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

              
                <noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  /* width: inherit; */
  /* height: inherit; */
}

body {
  background-color: rgb(16, 32, 54);
}

html,
body {
  /* padding: 2vw; */
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8vw;
  font-family: monospace;
  /* flex-wrap: wrap; */
  /* flex-direction: column; */
}

#clock {
  /* flex-grow: 1; */
  width: 40vw;
  height: 60vh;
  font-size: 100%;
  background-color: black;
  display: flex;
  /* padding-top: 5%; */
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  color: antiquewhite;
  border-radius: 1%;
  /* flex-direction: column; */
  /* align-items: center; */
}

#break-length,
#session-length {
  display: flex;
  justify-content: center;
  align-items: center;
}

#session-label,
#break-label {
  width: 30%;
  text-align: center;
  /* display: flex; */
  /* flex-direction: column; */
  /* justify-content: center; */
  /* align-items: center; */
}

#display {
  margin: 1%;
  width: 100%;
  height: 20%;
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande",
    "Lucida Sans", Arial, sans-serif;
  background-color: aquamarine;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 3vw;
  padding: 1%;
}

#controls {
  width: inherit;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;

}

.buttons {

  width: 45%;
  height: 30%;
  margin: 2%;
  padding: 2%;
}

#timer-div {
  height: 30%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  flex-direction: column;
  flex-grow: 1;
}

#sessionButtons {
  display: flex;
  justify-content: center;
  align-items: center;
  /* flex-wrap: wrap; */
  width: 30%;
  height: 30%;
  /* height: inherit;  */
}

#start_stop,
#reset {
  /* padding: 2%; */
  width: 45%;
  height: 100%;
}
              
            
!

JS

              
                // import React, { Component } from "react";
// import ReactDOM from "react-dom";
// import { createStore } from "redux";
// import { Provider } from "react-redux";
// import { connect } from "react-redux";
// import "./pomodoroClock.css";
// import App from "./ReactFCCtest";

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

const dataReducer = (state = {
    breakLength: 5, sessionLength: 25
    // , seconds: 1500, timerActive: false, isSession: true
}, action) => {

    if ((action.breakLength > 60 || action.breakLength < 0) || (action.sessionLength > 60 || action.sessionLength < 0)) {
        return
        // { ...state, sessionLength: 1, breakLength: 1 }
    }
    switch (action.type) {
        case "adjust":
            return Object.assign({}, state,
                action
            )
        case "reset":
            return Object.assign({}, state, {
                sessionLength: 25,
                breakLength: 5,
            })
        case "update":
            return Object.assign({}, state,
                action.element
            )
        default:
            return state
    }
};

const store = createStore(dataReducer);

/// Every connected Class automatically receive the entire state on update
const mapStateToProps = state => {
    return state;
};

const reset = () => {
    return { type: "reset" }
};
const adjust = (what, time) => {
    return { type: "adjust", [what + "Length"]: time }
}
const update = (element) => {
    return { type: "update", element }
}

class Controls extends Component {
    render() {
        console.log(this.props.value)
        return (
            <div id={this.props.text + "-label"}>
                {this.props.text}
                <p id={this.props.text + "-length"}>{this.props.value}</p>
                <button
                    id={this.props.text + "-decrement"}
                    className="buttons"
                    onClick={() => { if (this.props.value < 60) { store.dispatch(adjust(this.props.text, this.props.value + 1)) } }}
                >
                    Up
                </button>
                <button
                    id={this.props.text + "-increment"}
                    onClick={() => { if (this.props.value > 0) { store.dispatch(adjust(this.props.text, this.props.value - 1)) } }}
                    className="buttons">
                    Down
                </button>
            </div>

        );
    }
}

const ControlsCon = connect(mapStateToProps)(Controls);

class Timer extends Component {
    state = {
        seconds: store.getState().sessionLength * 60,
        timerActive: false,
        isSession: true
    }
    countDown = () => {
        if (!this.timer) { this.setState({ seconds: store.getState().sessionLength * 60 }) };
        if (!this.state.timerActive) {
            this.timer = setInterval(this.tick, 1000);
            this.setState({ timerActive: true });
        } else {
            clearInterval(this.timer);
            this.setState({ timerActive: false })
        }
    }

    tick = () => {
        if (this.state.seconds > 0) {
            return this.setState({ "seconds": this.state.seconds - 1 })
        } else {
            this.setState({ "seconds": this.state.isSession ? this.props.breakLength * 60 : this.props.sessionLength * 60, "isSession": !this.state.isSession })
            // Audio
            document.getElementById("beep").pause();
            document.getElementById("beep").currentTime = 0;
            document.getElementById("beep").play();

        }
    }


    stopCountDown = () => {
        clearInterval(this.timer);
        delete this.timer;
        store.dispatch(reset());
        this.setState({ seconds: store.getState().sessionLength * 60, timerActive: false });
        // Audio
        document.getElementById("beep").pause();
        document.getElementById("beep").currentTime = 0;

    }

    display = () => {
        let displayMinutes = (Math.floor(this.state.seconds / 60) < 10 ? "0" + Math.floor(this.state.seconds / 60) : Math.floor(this.state.seconds / 60));
        let displaySeconds = (this.state.seconds % 60) < 10 ? "0" + this.state.seconds % 60 : this.state.seconds % 60;
        if (!this.timer) {
            return this.props.sessionLength < 10 ? "0" + this.props.sessionLength + ":00" : this.props.sessionLength + ":00";
        }

        return displayMinutes + ":" + displaySeconds;
    }

    render() {
        return (
            <div id="timer-div">
                <p id="timer-label">{this.state.isSession ? "Session" : "Break"}</p>
                <audio id="beep" className="clip" src="https://s3.amazonaws.com/freecodecamp/drums/Chord_1.mp3" />
                <div id="time-left">
                    {this.display()}
                </div>
                <div id="sessionButtons">
                    <button id="start_stop" onClick={this.countDown}>Start</button>
                    <button id="reset" onClick={this.stopCountDown}>Reset</button>

                </div>
            </div>


        );
    }
}

const TimerCon = connect(mapStateToProps)(Timer);

class PomodoroClock extends Component {
    componentDidMount() {
        store.dispatch(reset())
    }
  // <App />
    render() {
        return (
            <div id="clock">
                Pomodoro clock
                
                <div id="controls">
                    <Controls text="session" value={this.props.sessionLength} />
                    <Controls text="break" value={this.props.breakLength} />
                </div>
                <TimerCon />
            </div>

        );
    }
}

const Clock = connect(mapStateToProps)(PomodoroClock);

ReactDOM.render(
    <Provider store={store}>
        <Clock />
    </Provider>
    , document.getElementById("root"));



              
            
!
999px

Console