Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">

  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root" style="height: 100%"></div>

  </body>
</html>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Quicksand:500|Sarpanch:700|Kaushan+Script|Source+Code+Pro:600|Abril+Fatface|Audiowide|Comfortaa:700|Kelly+Slab&display=swap');
$bootstrap-sass-asset-helper: false !default;

body,
html {
  height: 100%;
  margin: 0px;
  font-family: "Raleway", sans-serif;
  @extends .themeThree;
}
.themeOne {
    --shade1: #f4f1af;
    --shade2: #e7e283;
    --shade3: #dbd55b;
    --shade4: #dedede;
}

.themeTwo {
    --shade1: #aadff6;
    --shade2: #7ec9e9;
    --shade3: #57b5dd;
    --shade4: #32a1d0;
    --grey1: #dedede;
}

.themeThree {
  --shade1: #c3cacf;
  --shade2: #9ab1c2;
  --shade3: #e88f00;
  --shade3-font: #120b00;
  --shade4: #5385a9;
   --grey1: #dedede;
  --background: #121212;
  --foreground: #d4bfa6;
}

.themeFour {
  --shade1: #e6e6e6;
  --shade2: #dedede;
  --shade3: #d1d1d1;
  --shade4: #c7c7c7;
   --grey1: #dedede;
}

.themeFive {
  --shade1: #466b8c;
  --shade2: #8c5f46;
  --shade3: #8c8346;
  --shade4: #79468c;
   --grey1: #dedede;
 }
@mixin border-radius($a, $b, $c, $d) {
    -webkit-border-radius: $a $b $c $d;
    -moz-border-radius: $a $b $c $d;
    -ms-border-radius: $a $b $c $d;
    border-radius: $a $b $c $d;
}
@mixin height-calc($percentage, $value) {
    height: -moz-calc(#{$percentage} - #{$value});
    /* WebKit */
    height: -webkit-calc(#{$percentage} - #{$value});
    /* Opera */
    height: -o-calc(#{$percentage} - #{$value});
    /* Standard */
    height: calc(#{$percentage} - #{$value});
}
.outerDiv {
    height: 100%;
    width: 100%;
    background-color: var(--background);
    overflow: hidden;
    transition: all .3s ease-in-out;


}
.innerDiv {
    background: var(--background);
    height: 100%;
    margin-top: 0px;
}

.header {


  padding-top: 7px;
  background-color: var(--shade3);

  transition: all .3s ease-in-out;
}

.mytitle {
  padding-left: 3pt;
  font-size: 60px;
  font-family: 'Kaushan Script', cursive;
  color: var(--shade3-font);
}





.lengthButton {
  border: 0px;
  background: none;
  font-size: 10vw;
  color: var(--shade3);
}

.clockButton {
  border: 0px;
  border-radius: 50%;
  background: var(--shade3);
  font-size: 20vw;
  width: 32vw;
  height: 32vw;
  color: var(--background);
  display: flex;
  justify-content: center;
  align-content: center;
}

.fa-play {
  margin-left: 3vw;
}

.button {


  padding: 0;
  padding-top: auto;
}


.button:focus {
  outline: none;
}

.button:hover{
  cursor: default; 
  filter:brightness(1.25);
}

.lengthContainer {
  text-transform: capitalize;
}

.textField {


  text-align: right;

  font-size: 5em;

  font-family: 'Sarpanch', sans-serif;
  color: var(--shade3);
  filter: hue-rotate(280deg);

}

.lengthField {
  font-size: 20vw;
  line-height: 14vw;

}

.decrementButton {
  margin-right: -10px;
}

.label {
  color: var(--foreground);
}

.clockField {

}

@media (min-width: 576px){
  .mytitle{
    font-size: 30px;
  }

  .textField {
    font-size: 50px;
    text-align: center;
  }

  .clockButton {
    font-size: .8em;
    padding: .3em;
    width: auto;
    height: auto;
  }
  .clockField{
    font-size: 2em;
    line-height: .7em;
  }
  .fa-play {
    margin-left: 5px;
  }
  .fa-redo {
    margin-right: 5px;
    margin-top: 2px;
  }

  .label {
    font-size: .4em;
  }

  .lengthContainer {

  }
  .lengthButton {
    font-size: 1em;
  }

  .lengthField {
    line-height: .7em;
  }

}
              
            
!

JS

              
                

const {render} =  ReactDOM

const {Provider, connect} = ReactRedux; 
const {createStore} = Redux;



const INC_BREAK = 1;
const INC_SESSION = 2;
const DEC_BREAK = 3;
const DEC_SESSION = 4;
const RESET = 5;
const DEC_TIMER = 7;
const SWITCH_CLOCKS = 8;
const TIMER = 9;

const SESSION = 100;
const BREAK = 200;

const interval = 100;

// Section for setting up state
const defaultState = {
  message: "Hello world with my redux",
  sessionLength: 25, 
  breakLength: 5,
  time: 1500,
  clockState: SESSION,
  timing: false
}



const messageReducer = (state=defaultState, action) => {
  let holder = {...state};
//  console.log("in message reducer, state is " + JSON.stringify(state) + " action is " + JSON.stringify(action))
  switch(action.type){
    case INC_SESSION:
      if(holder.sessionLength < 60)
        holder.sessionLength ++;
      if(holder.clockState == SESSION)
        holder.time = holder.sessionLength *60
      break;
    case INC_BREAK:
      if(holder.breakLength <60)
        holder.breakLength ++;
      if(holder.clockState == BREAK)
        holder.time = holder.breakLength *60
      break;
    case DEC_SESSION:
      if(holder.sessionLength > 1)
        holder.sessionLength --;
      if(holder.clockState == SESSION)
        holder.time = holder.sessionLength *60
      break;
    case DEC_BREAK:
      if(holder.breakLength > 1)
        holder.breakLength--;
      if(holder.clockState == BREAK)
        holder.time = holder.breakLength *60
      break;
    case RESET: 
      holder.sessionLength = 25;
      holder.breakLength = 5;
      holder.time = holder.sessionLength * 60
      holder.clockState = SESSION;
      holder.timing = false;
      break;
    case DEC_TIMER:
      if(holder.time > 0)
        holder.time--;
   //   console.log("decrementing timer with interval " + action.interval + " time is " + holder.time);
      break;
    case SWITCH_CLOCKS:
      holder.clockState = holder.clockState == SESSION ? BREAK: SESSION;
      let time = holder.clockState == SESSION? holder.sessionLength: holder.breakLength
      holder.time = time * 60;
      break;
    case TIMER: 
      holder.timing = ! holder.timing;
      break;
    default:
      break;
  }
  return holder;
}

const store = createStore(messageReducer);

// end section for setting up redux

/// HEADER stateless component
/////// setup for Header 
const Header = (props) =>{
  return(
      <div className="col " style={{padding: "0px"}}>
          <div className="header " >
            <div className="mytitle" >{props.title}</div>
          </div>
      </div>
  )
}
/// end HEADER


  const TimingButton = (props)=>{
    let className = "fa-"+props.label+"-circle"
    return(<button className="button lengthButton " 
      id={props.name} 
      disabled={props.timing} 
      onClick={props.action}>
        <i className={"fas " + className}></i>
      </button>)}; 


    const SessionDecrementButton = connect(
      state =>({timing: state.timing, label: "minus"}),
      dispatch => ({action: () =>  { dispatch({type:DEC_SESSION})}})
    )(TimingButton)

    const SessionIncrementButton = connect(
      state =>({timing: state.timing, label: "plus"}),
      dispatch => ({action: () =>  { dispatch({type:INC_SESSION})}})
    )(TimingButton)

    const BreakDecrementButton = connect(
      state =>({timing: state.timing, label: "minus"}),
      dispatch => ({action: () =>  { dispatch({type:DEC_BREAK})}})
    )(TimingButton)

    const BreakIncrementButton = connect(
      state =>({timing: state.timing, label: "plus"}),
      dispatch => ({action: () =>  { dispatch({type:INC_BREAK})}})
    )(TimingButton)

    const LengthContainer = (props) => {

   //   console.log("in render for " + props.name);
      return(
        <div className="lengthContainer col-sm-5">

          <div className="row justify-content-center">

            <div className="col-auto decrementButton align-self-center" >
              {props.decrement}
            </div>
            <div className="col-4 col-sm-5 justify-content-center ">
              <div id={props.name +"-label"} className="col d-flex justify-content-center label">{props.name} Length</div>
              <div className="textField lengthField " id={props.name +'-length'}>
                {props.length}
                </div>
            </div>
            <div className="col-auto incrementButton align-self-center">
              {props.increment}
            </div>

          </div>
        </div>
      )
    }

    const BreakLengthContainer = connect (
      state => ({length: state.breakLength}), 
      null
    )(LengthContainer);

    const SessionLengthContainer = connect (
      state => ({length: state.sessionLength}),
      null
    )(LengthContainer);



class ClockComponent extends React.Component {
  constructor(props){
    super(props)
    this.state = {};
    this.timer = "";

    this.triggerTimer = this.triggerTimer.bind(this);
    this.clockTick = this.clockTick.bind(this);
    this.reset = this.reset.bind(this);
    this.playAudio = this.playAudio.bind(this);
  }


  triggerTimer(){

    if(this.timer){
    //  console.log('trigger timer stopping clock');
      clearInterval(this.timer);
      this.timer = "";
    }
    else{
  //    console.log('trigger timer starting clock ');
      this.timer = setInterval(this.clockTick, interval);
    }
    this.props.toggleTimer();
  }
  clockTick(){
    if(this.props.time == 0){

      clearInterval(this.timer);
      let sound = document.getElementById("beep");
      sound.play();
      this.timer = "";
      this.props.toggleTimer();
      this.props.switchClocks();

      setTimeout(this.triggerTimer(), interval*2);
    }
    else{
      this.props.decrementTimer(interval);
    }
    
  }

  reset(){
    clearInterval(this.timer);
    let sound = document.getElementById("beep");
    sound.pause();
    sound.currentTime = 0;
    this.timer = "";
    this.props.reset();
  }

  playAudio(){
    document.getElementById('beep').play();
  }

  render(){

      let minutes = Math.floor(this.props.time / 60);
      let seconds = this.props.time - minutes * 60;

      minutes = ("00" + minutes).slice (-2);
      seconds = ("00" + seconds).slice (-2);
    return(
      <div className="textField d-flex justify-content-center clockField" id='time-left'> {minutes + ":" + seconds} </div>
    )
  }
}

 ClockComponent = connect(
  function mapStateToProps(state, ownState){
    return { time: state.time}
  }, 
  function mapDispatchToProps(dispatch, ownProps){
    return {
      reset: ()=> {
        dispatch({type: RESET});
      },
      decrementTimer: (interval) =>{
        dispatch({type: DEC_TIMER, interval: interval});
      },
      switchClocks : () => {
        dispatch({type: SWITCH_CLOCKS});
      },
      toggleTimer: () => {
        dispatch({type: TIMER});
      }
    }
  },null, {forwardRef: true})(ClockComponent)


class App extends React.Component{
  constructor(props){
    super(props)
    this.state ={
      
    }
    this.reset = this.reset.bind(this);
    this.triggerTimer = this.triggerTimer.bind(this);
    this.clockRef = React.createRef();
  }

  reset(){
    this.refs.clockRef.reset();
  }

  triggerTimer(){
    this.refs.clockRef.triggerTimer();
  }
  render(){

   // console.log("in render for app ");

    let title = this.props.clockState == SESSION ? "Session": "Break";
    return (
        <div className="outerDiv themeThree container-fluid " style={{backgroundColor: "green"}}>         

          <div className="innerDiv row " >

            <Header title="Pomodoro Clock" />

            <div className="col-12 col-sm-12" >
              <div className="row justify-content-sm-center align-items-sm-end">
                <div className="col-12 col-sm-4 order-sm-2 align-items-end" >

                    <div id="timer-label" className="d-flex justify-content-center label">{title}</div>

                      <ClockComponent ref="clockRef"/>
                      <audio preload="auto" id="beep" src="https://goo.gl/65cBl1" style={{width: "100%"}}></audio>
                </div>   
                <div className="col-6 col-sm-auto order-sm-1 align-self-sm-end d-flex justify-content-end">
                  <button className="button clockButton" id="reset" onClick={this.reset}>
                    <i className="fas fa-redo " ></i>
                  </button>
                </div>


                <div className="col-6 col-sm-auto order-sm-3 align-self-sm-end d-flex justify-content-start">
                  <button className="button clockButton" id="start_stop" onClick={this.triggerTimer}>
                    <i className="fas fa-play " ></i>
                  </button>
                </div>
              </div>
            </div>

            <div className="col-12 col-sm-12 ">
              <div className="row justify-content-center">
                <SessionLengthContainer name="session" decrement={<SessionDecrementButton name="session-decrement"/>} increment={<SessionIncrementButton name="session-increment"/>}/>
                <BreakLengthContainer name="break" decrement={<BreakDecrementButton name="break-decrement"/>} increment={<BreakIncrementButton name="break-increment"/>}/>
              </div>
            </div>

          </div>

        </div>
    )
  }
}

App = connect(
  function mapStateToProps(state, ownProps){
    let myState = {
      clockState: state.clockState
    }
    return myState;
  }, 
  null
)(App);

// End App component

render(
  <Provider store={store}>
    <App />
  </Provider>
  , document.getElementById('root'));


              
            
!
999px

Console