├── public ├── favicon.ico ├── manifest.json └── index.html ├── src ├── index.css ├── index.js ├── App.test.js ├── format.js ├── SetTimer.js ├── App.css ├── buttons.css ├── App.js ├── Timer.js └── registerServiceWorker.js ├── .travis.yml ├── README.md ├── .gitignore └── package.json /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mihajlija/pomodoro/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: sans-serif; 5 | } 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "7" 4 | install: 5 | - npm install 6 | after_success: 7 | - npm run lh -- --perf=80 http://localhost:3000/ -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import registerServiceWorker from './registerServiceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById('root')); 8 | registerServiceWorker(); 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pomodoro 2 | 3 | Pomodoro timer built with React. Cool sound effects by [Bill Wurtz](https://www.youtube.com/watch?v=xuCn8ux2gbs) 4 | 5 | https://mihajlija.github.io/pomodoro/ 6 | 7 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). 8 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": "./index.html", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /src/format.js: -------------------------------------------------------------------------------- 1 | export const formatTime = ms => { 2 | let t = ms 3 | let seconds = Math.floor(t / 1000 % 60) 4 | let minutes = Math.floor(t / 1000 / 60 % 60) 5 | let hours = Math.floor(t / (1000 * 60 * 60) % 24) 6 | 7 | return { 8 | h: hours, 9 | m: minutes, 10 | s: seconds 11 | } 12 | } 13 | 14 | export const minutesToMs = min => { 15 | return min * 60 * 1000 16 | } 17 | 18 | export default formatTime 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pomodoro", 3 | "version": "0.1.0", 4 | "private": true, 5 | "homepage": "http://mihajlija.github.io/pomodoro", 6 | "dependencies": { 7 | "react": "^16.4.1", 8 | "react-dom": "^16.4.1", 9 | "react-scripts": "1.1.4" 10 | }, 11 | "scripts": { 12 | "start": "react-scripts start", 13 | "build": "react-scripts build", 14 | "test": "react-scripts test --env=jsdom", 15 | "eject": "react-scripts eject", 16 | "predeploy": "npm run build", 17 | "deploy": "gh-pages -d build", 18 | "lh": "lighthouse-ci" 19 | }, 20 | "devDependencies": { 21 | "gh-pages": "^1.2.0", 22 | "lighthouse-ci": "git+https://github.com/ebidel/lighthouse-ci.git" 23 | } 24 | } -------------------------------------------------------------------------------- /src/SetTimer.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | 3 | class SetTimer extends Component { 4 | increment = () => { 5 | let t = this.props.time 6 | if (this.props.time >= 1 && this.props.time < 60) { 7 | t = t + 1 8 | } 9 | this.props.setTime(t) 10 | } 11 | 12 | decrement = () => { 13 | let t = this.props.time 14 | if (this.props.time > 1 && this.props.time <= 60) { 15 | t = t - 1 16 | } 17 | this.props.setTime(t) 18 | } 19 | 20 | render () { 21 | return ( 22 |
23 |

{this.props.label}

24 | 25 | 26 |

{this.props.time}

27 |
28 | ) 29 | } 30 | } 31 | 32 | export default SetTimer 33 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | 2 | * { 3 | box-sizing: border-box; 4 | margin: 0; 5 | padding: 0; 6 | } 7 | :root { 8 | --bg-color: #39364A; 9 | --focus: #FF4E4D; 10 | --break: #05EC8C; 11 | } 12 | 13 | body { 14 | background: var(--bg-color); 15 | } 16 | 17 | .App { 18 | padding-top: 10vh; 19 | height: 80vh; 20 | text-align: center; 21 | color: white; 22 | font-family: 'Roboto Mono', monospace; 23 | font-weight: 400; 24 | } 25 | 26 | .timer { 27 | padding-bottom: 50px; 28 | display: flex; 29 | flex-direction: column; 30 | align-items: center; 31 | justify-content: center; 32 | } 33 | 34 | .countdown { 35 | display: flex; 36 | flex-direction: column; 37 | justify-content: center; 38 | align-items: center; 39 | border-radius: 50%; 40 | border: 3px solid white; 41 | width: 250px; 42 | height: 250px; 43 | margin-bottom: 1em; 44 | } 45 | 46 | h1 { 47 | font-size: 4em; 48 | font-weight: 300; 49 | } 50 | 51 | .prompt { 52 | height: 1rem; 53 | position: relative; 54 | top: -1rem; 55 | } 56 | 57 | .focus { 58 | color: var(--focus); 59 | border-color: var(--focus); 60 | } 61 | 62 | .chill { 63 | color: var(--break); 64 | border-color: var(--break); 65 | } 66 | 67 | .settings { 68 | display: flex; 69 | width: 100%; 70 | justify-content: center; 71 | } 72 | 73 | .labels { 74 | padding: 5px; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/buttons.css: -------------------------------------------------------------------------------- 1 | .play { 2 | position: relative; 3 | top: 1rem; 4 | border: 0; 5 | background: transparent; 6 | box-sizing: border-box; 7 | width: 0; 8 | height: 2em; 9 | 10 | border-color: transparent transparent transparent white; 11 | transition: 100ms all ease; 12 | cursor: pointer; 13 | 14 | border-style: solid; 15 | border-width: 1em 0 1em 1.5em; 16 | } 17 | 18 | .paused { 19 | border-style: double; 20 | border-width: 0px 0 0px 1.5em; 21 | } 22 | 23 | .play-focus { 24 | color: var(--focus); 25 | border-color: transparent transparent transparent var(--focus); 26 | } 27 | 28 | .play-chill { 29 | color: var(--break); 30 | border-color: transparent transparent transparent var(--break); 31 | } 32 | 33 | 34 | button { 35 | font-family: 'Roboto Mono', monospace; 36 | font-weight: 400; 37 | display:inline-block; 38 | border-radius: 50%; 39 | border: 2px solid white; 40 | height: 3em; 41 | width: 3em; 42 | background: none; 43 | color: white; 44 | margin: 0.5em; 45 | cursor: pointer; 46 | 47 | } 48 | 49 | button:focus { 50 | outline: none; 51 | } 52 | 53 | /* button:hover { 54 | color: #201d2d; 55 | border-color: #201d2d; 56 | } */ 57 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 24 | Pomodoro clock 25 | 26 | 27 | 28 | 31 |
32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import './buttons.css' 3 | import './App.css' 4 | import Timer from './Timer.js' 5 | import SetTimer from './SetTimer.js' 6 | import { minutesToMs } from './format.js' 7 | 8 | class App extends Component { 9 | constructor (props) { 10 | super(props) 11 | this.state = { 12 | session: 25, 13 | break: 5, 14 | running: false, 15 | paused: false, 16 | time: minutesToMs(25) 17 | } 18 | } 19 | 20 | setSession = t => { 21 | if (!this.state.running) { 22 | this.setState({ 23 | session: t, 24 | time: minutesToMs(t) 25 | }) 26 | } 27 | } 28 | 29 | setBreak = t => { 30 | this.setState({ 31 | break: t 32 | }) 33 | } 34 | 35 | updateTime = t => { 36 | this.setState({ 37 | time: t 38 | }) 39 | } 40 | 41 | setRunning = b => { 42 | this.setState({ 43 | running: b, 44 | paused: !b 45 | }) 46 | } 47 | 48 | reset = () => { 49 | this.setState({ 50 | session: 25, 51 | break: 5, 52 | running: false, 53 | paused: false, 54 | time: minutesToMs(25) 55 | }) 56 | } 57 | 58 | render () { 59 | return ( 60 |
61 | 69 |
70 | 75 | 80 |
81 |
82 | ) 83 | } 84 | } 85 | 86 | export default App 87 | -------------------------------------------------------------------------------- /src/Timer.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import { formatTime, minutesToMs } from './format.js' 3 | 4 | class Timer extends Component { 5 | constructor () { 6 | super() 7 | this.state = { 8 | sessionFlag: true 9 | } 10 | this.timer = 0 11 | } 12 | 13 | tickTock = () => { 14 | let time = this.props.app.time 15 | 16 | if (time === 0) { 17 | if (this.state.sessionFlag) { 18 | this.alarm(this.chill) 19 | this.props.updateTime(minutesToMs(this.props.app.break) + 1000) 20 | } else { 21 | this.alarm(this.focus) 22 | this.props.updateTime(minutesToMs(this.props.app.session) + 1000) 23 | } 24 | this.setState({ 25 | sessionFlag: !this.state.sessionFlag 26 | }) 27 | } 28 | 29 | time = this.props.app.time - 1000 30 | this.props.updateTime(time) 31 | } 32 | 33 | alarm = beep => { 34 | beep.play() 35 | } 36 | 37 | pauseAlarm = beep => { 38 | beep.pause() 39 | beep.currentTime = 0 40 | } 41 | 42 | startTimer = () => { 43 | if (!this.props.app.running) { 44 | this.props.setRunning(true) 45 | this.timer = setInterval(this.tickTock, 1000) 46 | } 47 | } 48 | 49 | stopTimer = () => { 50 | if (!this.props.app.paused && this.props.app.running) { 51 | this.props.setRunning(false) 52 | clearInterval(this.timer) 53 | } 54 | } 55 | 56 | startStop = () => { 57 | !this.props.app.running ? this.startTimer() : this.stopTimer() 58 | } 59 | 60 | resetTimer = () => { 61 | clearInterval(this.timer) 62 | this.setState({ sessionFlag: true }) 63 | this.pauseAlarm(this.chill) 64 | this.pauseAlarm(this.focus) 65 | this.props.reset() 66 | } 67 | 68 | render () { 69 | const timeFormat = formatTime(this.props.app.time) 70 | const minutes = ('0' + timeFormat.m).slice(-2) 71 | const seconds = ('0' + timeFormat.s).slice(-2) 72 | const focus = this.props.app.running && this.state.sessionFlag 73 | const chill = this.props.app.running && !this.state.sessionFlag 74 | const paused = !this.props.app.running && this.props.app.paused 75 | 76 | return ( 77 |
78 |
83 |

84 | {focus ? 'focus' : chill ? 'chill' : paused ? 'paused' : ''} 85 |

86 |

87 | {minutes}:{seconds} 88 |

89 |
99 |
100 |
101 | 102 |
103 |
120 | ) 121 | } 122 | } 123 | 124 | export default Timer 125 | -------------------------------------------------------------------------------- /src/registerServiceWorker.js: -------------------------------------------------------------------------------- 1 | // In production, we register a service worker to serve assets from local cache. 2 | 3 | // This lets the app load faster on subsequent visits in production, and gives 4 | // it offline capabilities. However, it also means that developers (and users) 5 | // will only see deployed updates on the "N+1" visit to a page, since previously 6 | // cached resources are updated in the background. 7 | 8 | // To learn more about the benefits of this model, read https://goo.gl/KwvDNy. 9 | // This link also includes instructions on opting out of this behavior. 10 | 11 | const isLocalhost = Boolean( 12 | window.location.hostname === 'localhost' || 13 | // [::1] is the IPv6 localhost address. 14 | window.location.hostname === '[::1]' || 15 | // 127.0.0.1/8 is considered localhost for IPv4. 16 | window.location.hostname.match( 17 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 18 | ) 19 | ); 20 | 21 | export default function register() { 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 23 | // The URL constructor is available in all browsers that support SW. 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location); 25 | if (publicUrl.origin !== window.location.origin) { 26 | // Our service worker won't work if PUBLIC_URL is on a different origin 27 | // from what our page is served on. This might happen if a CDN is used to 28 | // serve assets; see https://github.com/facebookincubator/create-react-app/issues/2374 29 | return; 30 | } 31 | 32 | window.addEventListener('load', () => { 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 34 | 35 | if (isLocalhost) { 36 | // This is running on localhost. Lets check if a service worker still exists or not. 37 | checkValidServiceWorker(swUrl); 38 | 39 | // Add some additional logging to localhost, pointing developers to the 40 | // service worker/PWA documentation. 41 | navigator.serviceWorker.ready.then(() => { 42 | console.log( 43 | 'This web app is being served cache-first by a service ' + 44 | 'worker. To learn more, visit https://goo.gl/SC7cgQ' 45 | ); 46 | }); 47 | } else { 48 | // Is not local host. Just register service worker 49 | registerValidSW(swUrl); 50 | } 51 | }); 52 | } 53 | } 54 | 55 | function registerValidSW(swUrl) { 56 | navigator.serviceWorker 57 | .register(swUrl) 58 | .then(registration => { 59 | registration.onupdatefound = () => { 60 | const installingWorker = registration.installing; 61 | installingWorker.onstatechange = () => { 62 | if (installingWorker.state === 'installed') { 63 | if (navigator.serviceWorker.controller) { 64 | // At this point, the old content will have been purged and 65 | // the fresh content will have been added to the cache. 66 | // It's the perfect time to display a "New content is 67 | // available; please refresh." message in your web app. 68 | console.log('New content is available; please refresh.'); 69 | } else { 70 | // At this point, everything has been precached. 71 | // It's the perfect time to display a 72 | // "Content is cached for offline use." message. 73 | console.log('Content is cached for offline use.'); 74 | } 75 | } 76 | }; 77 | }; 78 | }) 79 | .catch(error => { 80 | console.error('Error during service worker registration:', error); 81 | }); 82 | } 83 | 84 | function checkValidServiceWorker(swUrl) { 85 | // Check if the service worker can be found. If it can't reload the page. 86 | fetch(swUrl) 87 | .then(response => { 88 | // Ensure service worker exists, and that we really are getting a JS file. 89 | if ( 90 | response.status === 404 || 91 | response.headers.get('content-type').indexOf('javascript') === -1 92 | ) { 93 | // No service worker found. Probably a different app. Reload the page. 94 | navigator.serviceWorker.ready.then(registration => { 95 | registration.unregister().then(() => { 96 | window.location.reload(); 97 | }); 98 | }); 99 | } else { 100 | // Service worker found. Proceed as normal. 101 | registerValidSW(swUrl); 102 | } 103 | }) 104 | .catch(() => { 105 | console.log( 106 | 'No internet connection found. App is running in offline mode.' 107 | ); 108 | }); 109 | } 110 | 111 | export function unregister() { 112 | if ('serviceWorker' in navigator) { 113 | navigator.serviceWorker.ready.then(registration => { 114 | registration.unregister(); 115 | }); 116 | } 117 | } 118 | --------------------------------------------------------------------------------