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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<div id="root"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Montserrat:500|Orbitron|Pacifico');

body {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #CECECE;
  font-family: Montserrat, sans-serif;
  color: white;
}

button:focus {
  outline: 0;
}

#app {
  width: 500px;
  height: 500px;
  background-color: #FF4444;
  border-radius: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 20px;
  box-shadow: 0 0 10px #6a6a6a;
}

h1 {
  font-size: 280%;
  font-weight: 200;
  font-family: Pacifico, Montserrat, sans-serif;
  margin: 0;
  text-shadow: 2px 2px 6px #6a6a6a;
}

hr {
  width: 420px;
}

.length-container {
  width: 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  margin-top: 15px;
}

#session-container,
#break-container {
  width: 180px;
}

#break-label,
#session-label {
  margin: 0;
  display: flex;
  justify-content: center;
}

.length-set {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.length-display {
  margin: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 200%;
  background-color: #6a6a6a;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.842);
  border-radius: 3px;
  width: 70px;
  box-shadow: inset 0 0 5px #000000b9;
  font-family: Orbitron, sans-serif;
}

.control-btn {
  height: 40px;
  width: 40px;
  font-size: 200%;
  color: white;
  background: none;
  border: none;
  cursor: pointer;
  text-shadow: 2px 2px 5px #6a6a6a;
  transition: 250ms;
}

i {
  pointer-events: none;
}

.control-btn:hover {
  color: #21E521;
}

.control-btn:active {
  color: #107c10;
}

#timer-container {
  height: 55%;
  width: 55%;
  border-radius: 100%;
  border: 10px solid white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-shadow: 2px 2px 20px #6a6a6a;
}

#time-left {
  background-color: #6a6a6a;
  border-radius: 3px;
  height: 20%;
  width: 70%;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.842);
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: inset 0 0 5px #000000b9;
  font-family: Orbitron, sans-serif;
  font-size: 230%;
}

#timer-container-buttons {
  width: 60%;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  margin-top: 20px;
}

#timer-label {
  background-color: #6a6a6a;
  border-radius: 3px;
  text-shadow: 0 0 5px rgba(255, 255, 255, 0.842);
  box-shadow: inset 0 0 5px #000000b9;
  width: 145px;
  height: 40px;
  display: flex;
  justify-content: center;
  align-items: center;
  letter-spacing: 3px;
  font-family: Orbitron, sans-serif;
  margin-top: 0;
}
              
            
!

JS

              
                const { Provider, connect } = ReactRedux;
const { createStore, combineReducers, bindActionCreators, applyMiddleware } = Redux;

// ----------------------------------->>> ACTION CREATORS <<<-----------------------------------//

const activeAction = () => {
    return {
        type: 'COUNT'
    }
}

const breakLengthAction = (event, action) => {
    const direction = event.target.id === 'break-increment' ? 'INCREMENT_BREAK' : 'DECREMENT_BREAK';
    return {
        type: direction
    }
}

const resetAction = () => {
    return {
        type: 'RESET'
    }
}

const sessionLengthAction = (event, action) => {
    const direction = event.target.id === 'session-increment' ? 'INCREMENT_SESSION' : 'DECREMENT_SESSION';
    const actionType = action === 'count' || action === 'pause' ? 'FALSE' : 'TRUE';
    return {
        type: direction + '_' + actionType
    }
}

const stopAction = (sessionLength, breakLength) => {
    return {
        type: 'STOP',
        sessionLength,
        breakLength
    }
}

const timer = (status) => {
    status = status === 'count' ? 'pause' : status === 'pause' ? 'count' : 'stop';
    if (timerOn === false && status === 'count') {
        clearInterval(timing);
        return (dispatch) => {
            timing = setInterval(() => dispatch(tick()), 1000);
            dispatch({ type: 'TIMER_START' });
        }
    }
    else {
        clearInterval(timing);
        timerOn = false;
        return {
            type: 'TIMER_STOP'
        }
    }
}

const tick = () => {
    return {
        type: 'TICK'
    }
}

// ----------------------------------->>> REDUCERS <<<-----------------------------------//

const activeReducer = (state = 'stop', action) => {
    switch(action.type) {
        case 'COUNT':
            return state === 'count' ? 'pause' : 'count';

        case 'STOP':
        case 'RESET':
            return 'stop';
            
        default:
            return state;
    }
}

const sessionLengthReducer = (state = 25, action) => {
    
    switch(action.type) {
        case 'INCREMENT_SESSION_FALSE':
        case 'INCREMENT_SESSION_TRUE':
            return state + 1 > 60 ? 60 : ++state;

        case 'DECREMENT_SESSION_FALSE':
        case 'DECREMENT_SESSION_TRUE':
            return state - 1 === 0 ? 1 : --state;

        case 'RESET':
            return 25;

        default:
            return state;
    }
}

const breakLengthReducer = (state = 5, action) => {

    switch(action.type) {
        case 'INCREMENT_BREAK':
            return state + 1 > 60 ? 60 : ++state;

        case 'DECREMENT_BREAK':
            return state - 1 === 0 ? 1 : --state;

        case 'RESET':
            return 5;
            
        default:
            return state;
    }
}

const displayReducer = (state = {
    display: {
        min: 25,
        sec: 0
    },
    sessionSet: 25,
    breakSet: 5,
    type: 'session'
}, action) => {

    const audioElem = document.getElementById('beep');

    switch(action.type) {
        case 'TICK':
            console.log('tick');
            let tick = Object.assign({}, state);

            if (tick.display.min === 0 && tick.display.sec === 0) {
                tick.type = tick.type === 'session' ? 'break' : 'session';
                tick.display.min = tick.type === 'session' ? tick.sessionSet : tick.breakSet;
                tick.display.sec = 0;
            }
            else {
                tick.display.min = tick.display.sec === 0 ? --tick.display.min : tick.display.min;

                tick.display.sec = tick.display.sec === 0 ? 59 : --tick.display.sec;
            }
            if (tick.display.min === 0 && tick.display.sec === 0) {
                
                let playPromise = audioElem.play();
                if (playPromise !== undefined) {
                    playPromise.then(function() {
                      console.log('play')
                    }).catch(function(error) {
                      console.log('error with audio element')
                    });
                }
            }
            return tick;

        case 'INCREMENT_SESSION_TRUE':
            let incrTrue = Object.assign({}, state);
            incrTrue.sessionSet = incrTrue.sessionSet + 1 > 60 ? incrTrue.sessionSet : ++incrTrue.sessionSet;
            incrTrue.display.min = incrTrue.sessionSet;
            return incrTrue;

        case 'DECREMENT_SESSION_TRUE':
            let decrTrue = Object.assign({}, state);
            decrTrue.sessionSet = decrTrue.sessionSet - 1 === 0 ? decrTrue.sessionSet : --decrTrue.sessionSet;
            decrTrue.display.min = decrTrue.sessionSet;
            return decrTrue;

        case 'INCREMENT_SESSION_FALSE':
            let incrFalse = Object.assign({}, state);
            incrFalse.sessionSet = incrFalse.sessionSet + 1 > 60 ? incrFalse.sessionSet : ++incrFalse.sessionSet;
            return incrFalse;

        case 'DECREMENT_SESSION_FALSE':
            let decrFalse = Object.assign({}, state);
            decrFalse.sessionSet = decrFalse.sessionSet - 1 === 0 ? decrFalse.sessionSet : --decrFalse.sessionSet;
            return decrFalse;

        case 'INCREMENT_BREAK':
            let incrBrFalse = Object.assign({}, state);
            incrBrFalse.breakSet = incrBrFalse.breakSet + 1 > 60 ? incrBrFalse.breakSet : ++incrBrFalse.breakSet;
            return incrBrFalse;

        case 'DECREMENT_BREAK':
            let decrBrFalse = Object.assign({}, state);
            decrBrFalse.breakSet = decrBrFalse.breakSet - 1 === 0 ? decrBrFalse.breakSet : --decrBrFalse.breakSet;
            return decrBrFalse;

        case 'STOP':
            let stop = Object.assign({}, state);
            stop.display.min = stop.sessionSet;
            stop.display.sec = 0;
            stop.type = 'session';
            return stop;

        case 'RESET':
            audioElem.pause();
            audioElem.currentTime = 0;
            let reset = Object.assign({}, state);
            reset.display.min = 25;
            reset.display.sec = 0;
            reset.sessionSet = 25;
            reset.breakSet = 5;
            reset.type = 'session';
            return reset;

        default:
            return state;
    }
}

// ----------------------------------->>> ROOT REDUCER <<<-----------------------------------//

const rootReducer = combineReducers({
    sessionLength: sessionLengthReducer,
    breakLength: breakLengthReducer,
    active: activeReducer,
    display: displayReducer
})

// ----------------------------------->>> GLOBAL VARIABLES <<<-----------------------------------//

const store = createStore(rootReducer, applyMiddleware(ReduxThunk.default));
let timing = null;
let timerOn = false;

// ----------------------------------->>> COMPONENT <<<-----------------------------------//

class App extends React.Component {
  render() {
    
    const { breakLengthAction, breakLength, sessionLengthAction, sessionLength, active, resetAction, activeAction, stopAction, display, timer  } = this.props;
    
    const min = display.display.min;
    const sec = display.display.sec;
    
    return (
      <div id='app'>
        <h1 className='title'>Pomodoro Clock</h1>
        <hr />
        <div className='length-container'>
          <section id='session-container'>
            <h2 id='session-label'>session length</h2>
            <div id='session-set'  className='length-set'>
              <button
                id='session-decrement'
                className='control-btn'
                onClick={(event) => {
                  sessionLengthAction(event, active);
                } }>
                <i className="fas fa-angle-down"></i>
              </button>
              <div id='session-length' className='length-display'>{sessionLength}</div>
              <button
                id='session-increment'
                className='control-btn'
                onClick={(event) => {
                  sessionLengthAction(event, active);
                } }>
                <i className="fas fa-angle-up"></i>
              </button>
            </div>
          </section>
          <section id='break-container'>
            <h2 id='break-label'>break length</h2>
            <div id='break-set' className='length-set'>
              <button
                id='break-decrement'
                className='control-btn'
                onClick={(event) => {
                  breakLengthAction(event, active);
                } }>
                <i className="fas fa-angle-down"></i>
              </button>
              <div id='break-length' className='length-display'>{breakLength}</div>
              <button
                id='break-increment'
                className='control-btn'
                onClick={(event) => {
                  breakLengthAction(event, active);
                } }>
                <i className="fas fa-angle-up"></i>
              </button>
            </div>
          </section>
        </div>
        <div id='timer-container'>
          <h2 id='timer-label'>{display.type}</h2>
          <div id='time-left'>{(min < 10 ? '0' + min : min) + ':' + (sec < 10 ? '0' + sec : sec)}</div>
          <div id='timer-container-buttons'>
            <button
              id='start_stop'
              className='control-btn'
              onClick={() => {
                activeAction();
                const status = active === 'count' ? 'count' : 'pause';
                timer(status);
              } }>
            { active === 'count' ? <i className="fas fa-pause"></i> : <i className="fas fa-play"></i> }
            </button>
            <button
              id='stop'
              className='control-btn'
              onClick={() => {
                stopAction(sessionLength, breakLength);
                timer('stop');
              } }>
              <i className="fas fa-stop"></i>
            </button>
            <button
              id='reset'
              className='control-btn'
              onClick={() => {
                resetAction();
                timer('stop');
              } }>
              <i className="fas fa-redo"></i>
            </button>
          </div>
          <audio className='clip' id='beep' src='https://res.cloudinary.com/jutzee/video/upload/v1537693352/FCC-pomodoro%20clock/alarm_beep.mp3' preload="auto"></audio>
        </div>
      </div>
    );
  }
}

// ----------------------------------->>> mapStateToProps, mapDispatchToProps <<<-----------------------------------//

let mapStateToProps = (state) => {
    return {
      active: state.active,
      sessionLength: state.sessionLength,
      breakLength: state.breakLength,
      display: state.display      
    };
}

let mapDispatchToProps = (dispatch) => {
  return bindActionCreators({
    sessionLengthAction,
    breakLengthAction,
    resetAction,
    activeAction,
    stopAction,
    timer
  }, dispatch)
}

const AppContainer = connect(mapStateToProps, mapDispatchToProps)(App);

ReactDOM.render(<Provider store={store}><AppContainer/></Provider>, document.getElementById('root'));
              
            
!
999px

Console