mirror of
https://github.com/TrentSPalmer/fcc-challenges.git
synced 2024-11-23 11:51:30 -08:00
add pomodoro-clock-react
This commit is contained in:
parent
01bbb2d626
commit
f3b0a0721a
@ -47,5 +47,8 @@
|
||||
<div>
|
||||
<a class="link" href="calculator-react/build" target="_blank" rel="noopener noreferrer">Calculator React</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="link" href="pomodoro-clock-react/build" target="_blank" rel="noopener noreferrer">Pomodoro Clock React</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
23
pomodoro-clock-react/.gitignore
vendored
Normal file
23
pomodoro-clock-react/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
# /build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
80
pomodoro-clock-react/README.md
Normal file
80
pomodoro-clock-react/README.md
Normal file
@ -0,0 +1,80 @@
|
||||
### Drum-Machine-React Project Links
|
||||
|
||||
* [GitHub Page View of this Repo](https://trentspalmer.github.io/fcc-challenges)
|
||||
* [GitHub Page View of this Project (pomodoro-clock-react)](https://trentspalmer.github.io/fcc-challenges/pomodoro-clock-react/build)
|
||||
|
||||
### FreeCodeCamp Links
|
||||
|
||||
* [FreeCodeCamp Instruction for This Project](https://www.freecodecamp.org/learn/front-end-libraries/front-end-libraries-projects/build-a-pomodoro-clock)
|
||||
* [FreeCodeCamp Section](https://www.freecodecamp.org/learn/front-end-libraries/front-end-libraries-projects)
|
||||
|
||||
---
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.<br />
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.<br />
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.<br />
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.<br />
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.<br />
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
|
23
pomodoro-clock-react/build/asset-manifest.json
Normal file
23
pomodoro-clock-react/build/asset-manifest.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"files": {
|
||||
"main.css": "/fcc-challenges/pomodoro-clock-react/build/static/css/main.1b8ac635.chunk.css",
|
||||
"main.js": "/fcc-challenges/pomodoro-clock-react/build/static/js/main.157adc9f.chunk.js",
|
||||
"main.js.map": "/fcc-challenges/pomodoro-clock-react/build/static/js/main.157adc9f.chunk.js.map",
|
||||
"runtime-main.js": "/fcc-challenges/pomodoro-clock-react/build/static/js/runtime-main.601eb45a.js",
|
||||
"runtime-main.js.map": "/fcc-challenges/pomodoro-clock-react/build/static/js/runtime-main.601eb45a.js.map",
|
||||
"static/js/2.9a920135.chunk.js": "/fcc-challenges/pomodoro-clock-react/build/static/js/2.9a920135.chunk.js",
|
||||
"static/js/2.9a920135.chunk.js.map": "/fcc-challenges/pomodoro-clock-react/build/static/js/2.9a920135.chunk.js.map",
|
||||
"index.html": "/fcc-challenges/pomodoro-clock-react/build/index.html",
|
||||
"precache-manifest.54ac6025f5b442b201d5113579ebf9b3.js": "/fcc-challenges/pomodoro-clock-react/build/precache-manifest.54ac6025f5b442b201d5113579ebf9b3.js",
|
||||
"service-worker.js": "/fcc-challenges/pomodoro-clock-react/build/service-worker.js",
|
||||
"static/css/main.1b8ac635.chunk.css.map": "/fcc-challenges/pomodoro-clock-react/build/static/css/main.1b8ac635.chunk.css.map",
|
||||
"static/js/2.9a920135.chunk.js.LICENSE.txt": "/fcc-challenges/pomodoro-clock-react/build/static/js/2.9a920135.chunk.js.LICENSE.txt",
|
||||
"static/media/BeepSound.ogg": "/fcc-challenges/pomodoro-clock-react/build/static/media/BeepSound.049fe0d0.ogg"
|
||||
},
|
||||
"entrypoints": [
|
||||
"static/js/runtime-main.601eb45a.js",
|
||||
"static/js/2.9a920135.chunk.js",
|
||||
"static/css/main.1b8ac635.chunk.css",
|
||||
"static/js/main.157adc9f.chunk.js"
|
||||
]
|
||||
}
|
1
pomodoro-clock-react/build/index.html
Normal file
1
pomodoro-clock-react/build/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="#"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/fcc-challenges/pomodoro-clock-react/build/logo192.png"/><link rel="manifest" href="/fcc-challenges/pomodoro-clock-react/build/manifest.json"/><link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@500&display=swap" rel="stylesheet"><title>Pomodoro Clock React - Build a Pomodoro Clock - Front End Libraries Projects</title><link href="/fcc-challenges/pomodoro-clock-react/build/static/css/main.1b8ac635.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"><div><script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script></div></div><script>!function(e){function r(r){for(var o,u,l=r[0],a=r[1],p=r[2],i=0,s=[];i<l.length;i++)u=l[i],Object.prototype.hasOwnProperty.call(n,u)&&n[u]&&s.push(n[u][0]),n[u]=0;for(o in a)Object.prototype.hasOwnProperty.call(a,o)&&(e[o]=a[o]);for(f&&f(r);s.length;)s.shift()();return c.push.apply(c,p||[]),t()}function t(){for(var e,r=0;r<c.length;r++){for(var t=c[r],o=!0,l=1;l<t.length;l++){var a=t[l];0!==n[a]&&(o=!1)}o&&(c.splice(r--,1),e=u(u.s=t[0]))}return e}var o={},n={1:0},c=[];function u(r){if(o[r])return o[r].exports;var t=o[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,u),t.l=!0,t.exports}u.m=e,u.c=o,u.d=function(e,r,t){u.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},u.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,r){if(1&r&&(e=u(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(u.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)u.d(t,o,function(r){return e[r]}.bind(null,o));return t},u.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(r,"a",r),r},u.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},u.p="/fcc-challenges/pomodoro-clock-react/build/";var l=this["webpackJsonppomodoro-clock-react"]=this["webpackJsonppomodoro-clock-react"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var p=0;p<l.length;p++)r(l[p]);var f=a;t()}([])</script><script src="/fcc-challenges/pomodoro-clock-react/build/static/js/2.9a920135.chunk.js"></script><script src="/fcc-challenges/pomodoro-clock-react/build/static/js/main.157adc9f.chunk.js"></script></body></html>
|
25
pomodoro-clock-react/build/manifest.json
Normal file
25
pomodoro-clock-react/build/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
self.__precacheManifest = (self.__precacheManifest || []).concat([
|
||||
{
|
||||
"revision": "d4480af81858bd79f0f992fbce881761",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/index.html"
|
||||
},
|
||||
{
|
||||
"revision": "52721a53958abb4c9a3a",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/static/css/main.1b8ac635.chunk.css"
|
||||
},
|
||||
{
|
||||
"revision": "a8ccb8073b63549a8872",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/static/js/2.9a920135.chunk.js"
|
||||
},
|
||||
{
|
||||
"revision": "c64c486544348f10a6d6c716950bc223",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/static/js/2.9a920135.chunk.js.LICENSE.txt"
|
||||
},
|
||||
{
|
||||
"revision": "52721a53958abb4c9a3a",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/static/js/main.157adc9f.chunk.js"
|
||||
},
|
||||
{
|
||||
"revision": "8cfbad2a32123298c100",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/static/js/runtime-main.601eb45a.js"
|
||||
},
|
||||
{
|
||||
"revision": "049fe0d053c2b8d3dcdf7c15abed110d",
|
||||
"url": "/fcc-challenges/pomodoro-clock-react/build/static/media/BeepSound.049fe0d0.ogg"
|
||||
}
|
||||
]);
|
3
pomodoro-clock-react/build/robots.txt
Normal file
3
pomodoro-clock-react/build/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
39
pomodoro-clock-react/build/service-worker.js
Normal file
39
pomodoro-clock-react/build/service-worker.js
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Welcome to your Workbox-powered service worker!
|
||||
*
|
||||
* You'll need to register this file in your web app and you should
|
||||
* disable HTTP caching for this file too.
|
||||
* See https://goo.gl/nhQhGp
|
||||
*
|
||||
* The rest of the code is auto-generated. Please don't update this file
|
||||
* directly; instead, make changes to your Workbox build configuration
|
||||
* and re-run your build process.
|
||||
* See https://goo.gl/2aRDsh
|
||||
*/
|
||||
|
||||
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
|
||||
|
||||
importScripts(
|
||||
"/fcc-challenges/pomodoro-clock-react/build/precache-manifest.54ac6025f5b442b201d5113579ebf9b3.js"
|
||||
);
|
||||
|
||||
self.addEventListener('message', (event) => {
|
||||
if (event.data && event.data.type === 'SKIP_WAITING') {
|
||||
self.skipWaiting();
|
||||
}
|
||||
});
|
||||
|
||||
workbox.core.clientsClaim();
|
||||
|
||||
/**
|
||||
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
|
||||
* requests for URLs in the manifest.
|
||||
* See https://goo.gl/S9QRab
|
||||
*/
|
||||
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
||||
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
|
||||
|
||||
workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/fcc-challenges/pomodoro-clock-react/build/index.html"), {
|
||||
|
||||
blacklist: [/^\/_/,/\/[^/?]+\.[^/]+$/],
|
||||
});
|
@ -0,0 +1,2 @@
|
||||
body{margin:0;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Roboto","Oxygen","Ubuntu","Cantarell","Fira Sans","Droid Sans","Helvetica Neue",sans-serif;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;overflow:hidden}code{font-family:source-code-pro,Menlo,Monaco,Consolas,"Courier New",monospace}
|
||||
/*# sourceMappingURL=main.1b8ac635.chunk.css.map */
|
@ -0,0 +1 @@
|
||||
{"version":3,"sources":["index.css"],"names":[],"mappings":"AAAA,KACE,QAAS,CACT,mJAEY,CACZ,kCAAmC,CACnC,iCAAkC,CAClC,eACF,CAEA,KACE,yEAEF","file":"main.1b8ac635.chunk.css","sourcesContent":["body {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',\n 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n overflow: hidden;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',\n monospace;\n}\n"]}
|
3
pomodoro-clock-react/build/static/js/2.9a920135.chunk.js
Normal file
3
pomodoro-clock-react/build/static/js/2.9a920135.chunk.js
Normal file
File diff suppressed because one or more lines are too long
@ -0,0 +1,41 @@
|
||||
/*
|
||||
object-assign
|
||||
(c) Sindre Sorhus
|
||||
@license MIT
|
||||
*/
|
||||
|
||||
/** @license React v0.19.1
|
||||
* scheduler.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
* react-dom.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
* react-is.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
/** @license React v16.13.1
|
||||
* react.production.min.js
|
||||
*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,2 @@
|
||||
!function(e){function r(r){for(var o,u,l=r[0],a=r[1],p=r[2],i=0,s=[];i<l.length;i++)u=l[i],Object.prototype.hasOwnProperty.call(n,u)&&n[u]&&s.push(n[u][0]),n[u]=0;for(o in a)Object.prototype.hasOwnProperty.call(a,o)&&(e[o]=a[o]);for(f&&f(r);s.length;)s.shift()();return c.push.apply(c,p||[]),t()}function t(){for(var e,r=0;r<c.length;r++){for(var t=c[r],o=!0,l=1;l<t.length;l++){var a=t[l];0!==n[a]&&(o=!1)}o&&(c.splice(r--,1),e=u(u.s=t[0]))}return e}var o={},n={1:0},c=[];function u(r){if(o[r])return o[r].exports;var t=o[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,u),t.l=!0,t.exports}u.m=e,u.c=o,u.d=function(e,r,t){u.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},u.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,r){if(1&r&&(e=u(e)),8&r)return e;if(4&r&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(u.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var o in e)u.d(t,o,function(r){return e[r]}.bind(null,o));return t},u.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(r,"a",r),r},u.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},u.p="/fcc-challenges/pomodoro-clock-react/build/";var l=this["webpackJsonppomodoro-clock-react"]=this["webpackJsonppomodoro-clock-react"]||[],a=l.push.bind(l);l.push=r,l=l.slice();for(var p=0;p<l.length;p++)r(l[p]);var f=a;t()}([]);
|
||||
//# sourceMappingURL=runtime-main.601eb45a.js.map
|
File diff suppressed because one or more lines are too long
BIN
pomodoro-clock-react/build/static/media/BeepSound.049fe0d0.ogg
Normal file
BIN
pomodoro-clock-react/build/static/media/BeepSound.049fe0d0.ogg
Normal file
Binary file not shown.
14064
pomodoro-clock-react/package-lock.json
generated
Normal file
14064
pomodoro-clock-react/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
pomodoro-clock-react/package.json
Normal file
40
pomodoro-clock-react/package.json
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "pomodoro-clock-react",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"homepage": "https://trentspalmer.github.io/fcc-challenges/pomodoro-clock-react/build",
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "^1.2.28",
|
||||
"@fortawesome/free-solid-svg-icons": "^5.13.0",
|
||||
"@fortawesome/react-fontawesome": "^0.1.10",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.5.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-redux": "^7.2.0",
|
||||
"react-scripts": "3.4.1",
|
||||
"redux": "^4.0.5"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
53
pomodoro-clock-react/public/index.html
Normal file
53
pomodoro-clock-react/public/index.html
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="#" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<link href="https://fonts.googleapis.com/css2?family=Ubuntu:wght@500&display=swap" rel="stylesheet">
|
||||
<!--
|
||||
font-family: 'Ubuntu', sans-serif;
|
||||
-->
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>
|
||||
Pomodoro Clock React - Build a Pomodoro Clock - Front End Libraries Projects
|
||||
</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root">
|
||||
<div>
|
||||
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
25
pomodoro-clock-react/public/manifest.json
Normal file
25
pomodoro-clock-react/public/manifest.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
pomodoro-clock-react/public/robots.txt
Normal file
3
pomodoro-clock-react/public/robots.txt
Normal file
@ -0,0 +1,3 @@
|
||||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
98
pomodoro-clock-react/src/App.js
Normal file
98
pomodoro-clock-react/src/App.js
Normal file
@ -0,0 +1,98 @@
|
||||
import React from 'react';
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import PomodoroClock from './PomodoroClock';
|
||||
|
||||
import { colors } from './globals'
|
||||
|
||||
import { innerWindowWidthAction } from "./actions/innerWindowWidthAction";
|
||||
import { innerWindowHeightAction } from "./actions/innerWindowHeightAction";
|
||||
|
||||
const mapStateToProps = (state) => ({ ...state });
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
innerWindowWidthAction: (windowInnerWidth) => dispatch(innerWindowWidthAction(windowInnerWidth)),
|
||||
innerWindowHeightAction: (windowInnerHeight) => dispatch(innerWindowHeightAction(windowInnerHeight)),
|
||||
});
|
||||
|
||||
class App extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleResize = this.handleResize.bind(this);
|
||||
};
|
||||
|
||||
handleResize() {
|
||||
this.props.innerWindowWidthAction(window.innerWidth);
|
||||
this.props.innerWindowHeightAction(window.innerHeight);
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
window.addEventListener('resize',this.handleResize);
|
||||
};
|
||||
|
||||
componentWillUnmount() {
|
||||
window.removeEventListener('resize',this.handleResize);
|
||||
};
|
||||
|
||||
render() {
|
||||
const height = this.props.innerWindowHeight;
|
||||
const width = this.props.innerWindowWidth;
|
||||
const gitHubLabelStyle = {
|
||||
backgroundColor: colors.prussianBlue,
|
||||
border: 'none',
|
||||
width: 149,
|
||||
height: 0,
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
};
|
||||
|
||||
const attachmentStyle = {
|
||||
position: 'absolute',
|
||||
right: 0,
|
||||
height: 149,
|
||||
width: 149,
|
||||
};
|
||||
|
||||
const style = {
|
||||
textAlign: 'center',
|
||||
backgroundColor: colors.prussianBlue,
|
||||
height: '100vh',
|
||||
width: '100vw',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
color: colors.ivoryBlack,
|
||||
overFlow: 'hidden',
|
||||
fontFamily: 'Ubuntu sans-serif',
|
||||
fontSize: 48,
|
||||
};
|
||||
|
||||
if (width > height && height < 400) {
|
||||
gitHubLabelStyle['width'] = 99;
|
||||
attachmentStyle['width'] = 99;
|
||||
attachmentStyle['height'] = 99;
|
||||
} else if (height > width) {
|
||||
gitHubLabelStyle['width'] = 99;
|
||||
attachmentStyle['width'] = 99;
|
||||
attachmentStyle['height'] = 99;
|
||||
}
|
||||
|
||||
return (
|
||||
<div style={style}>
|
||||
<a href="https://github.com/TrentSPalmer/fcc-challenges/tree/gh-pages/pomodoro-clock-react"
|
||||
style={gitHubLabelStyle}
|
||||
target="_blank" rel="noopener noreferrer">
|
||||
<img
|
||||
src="https://github.blog/wp-content/uploads/2008/12/forkme_right_white_ffffff.png?resize=149%2C149"
|
||||
className="size-full"
|
||||
style={attachmentStyle}
|
||||
alt="Fork me on GitHub"
|
||||
data-recalc-dims="1">
|
||||
</img>
|
||||
</a>
|
||||
<PomodoroClock />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(App);
|
9
pomodoro-clock-react/src/App.test.js
Normal file
9
pomodoro-clock-react/src/App.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
const { getByText } = render(<App />);
|
||||
const linkElement = getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
BIN
pomodoro-clock-react/src/BeepSound.ogg
Normal file
BIN
pomodoro-clock-react/src/BeepSound.ogg
Normal file
Binary file not shown.
31
pomodoro-clock-react/src/Break.js
Normal file
31
pomodoro-clock-react/src/Break.js
Normal file
@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
|
||||
import { colors } from './globals'
|
||||
import BreakControls from './BreakControls';
|
||||
|
||||
const Break = () => {
|
||||
const style = {
|
||||
height: '100%',
|
||||
width: '50%',
|
||||
};
|
||||
|
||||
const breakTextStyle = {
|
||||
height: '50%',
|
||||
width: '90%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
textAlign: 'right',
|
||||
marginRight: '10%',
|
||||
color: colors.goldLeaf,
|
||||
};
|
||||
|
||||
return(
|
||||
<div style={style}>
|
||||
<div id="break-label" style={breakTextStyle}>Break Length</div>
|
||||
<BreakControls />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Break;
|
124
pomodoro-clock-react/src/BreakControls.js
Normal file
124
pomodoro-clock-react/src/BreakControls.js
Normal file
@ -0,0 +1,124 @@
|
||||
import React from 'react';
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faArrowCircleDown } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faArrowCircleUp } from "@fortawesome/free-solid-svg-icons";
|
||||
import { colors,makeClock } from './globals'
|
||||
|
||||
import { breakLengthAction } from "./actions/breakLengthAction";
|
||||
import { clockAction } from "./actions/clockAction";
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
breakLengthAction: (breakLength) => dispatch(breakLengthAction(breakLength)),
|
||||
clockAction: (time) => dispatch(clockAction(time)),
|
||||
});
|
||||
|
||||
const mapStateToProps = (state) => ({ ...state });
|
||||
|
||||
class BreakControls extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleDownArrowMouseEvent = this.handleDownArrowMouseEvent.bind(this);
|
||||
this.handleUpArrowMouseEvent = this.handleUpArrowMouseEvent.bind(this);
|
||||
this.incrementBreak = this.incrementBreak.bind(this);
|
||||
this.decrementBreak = this.decrementBreak.bind(this);
|
||||
this.state = {
|
||||
downColor: colors.ivoryBlack,
|
||||
upColor: colors.ivoryBlack,
|
||||
};
|
||||
};
|
||||
|
||||
incrementBreak() {
|
||||
if (this.props.breakLength < 60) {
|
||||
const newBreakLength = this.props.breakLength + 1;
|
||||
if (!this.props.clockIsRunning) {
|
||||
this.props.breakLengthAction(newBreakLength);
|
||||
if (this.props.timer === 'Break') {
|
||||
this.props.clockAction(makeClock(newBreakLength * 60));
|
||||
}
|
||||
} else {
|
||||
if (this.props.timer === 'Session') {
|
||||
this.props.breakLengthAction(newBreakLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
decrementBreak() {
|
||||
if (this.props.breakLength > 1) {
|
||||
const newBreakLength = this.props.breakLength - 1;
|
||||
if (!this.props.clockIsRunning) {
|
||||
this.props.breakLengthAction(newBreakLength);
|
||||
if (this.props.timer === 'Break') {
|
||||
this.props.clockAction(makeClock(newBreakLength * 60));
|
||||
}
|
||||
} else {
|
||||
if (this.props.timer === 'Session') {
|
||||
this.props.breakLengthAction(newBreakLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
handleDownArrowMouseEvent(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({downColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({downColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
handleUpArrowMouseEvent(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({upColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({upColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const style = {
|
||||
height: '50%',
|
||||
width: '75%',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'flex-end',
|
||||
marginRight: '25%',
|
||||
fontSize: 32,
|
||||
};
|
||||
|
||||
const breakStyle = {
|
||||
width: 50,
|
||||
}
|
||||
|
||||
const downArrowStyle = {
|
||||
color: this.state.downColor,
|
||||
}
|
||||
|
||||
const upArrowStyle = {
|
||||
color: this.state.upColor,
|
||||
}
|
||||
|
||||
return(
|
||||
<div style={style}>
|
||||
<div id='break-decrement' style={downArrowStyle} onClick={this.decrementBreak}
|
||||
onTouchStart={this.handleDownArrowMouseEvent} onTouchEnd={this.handleDownArrowMouseEvent}
|
||||
onMouseDown={this.handleDownArrowMouseEvent} onMouseUp={this.handleDownArrowMouseEvent}>
|
||||
<FontAwesomeIcon icon={faArrowCircleDown}/>
|
||||
</div>
|
||||
|
||||
<p id='break-length' style={breakStyle}>{this.props.breakLength}</p>
|
||||
|
||||
<div id='break-increment' style={upArrowStyle} onClick={this.incrementBreak}
|
||||
onTouchStart={this.handleUpArrowMouseEvent} onTouchEnd={this.handleUpArrowMouseEvent}
|
||||
onMouseDown={this.handleUpArrowMouseEvent} onMouseUp={this.handleUpArrowMouseEvent}>
|
||||
<FontAwesomeIcon icon={faArrowCircleUp}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(BreakControls);
|
42
pomodoro-clock-react/src/Clock.js
Normal file
42
pomodoro-clock-react/src/Clock.js
Normal file
@ -0,0 +1,42 @@
|
||||
import React from 'react';
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import { colors } from './globals'
|
||||
|
||||
const mapStateToProps = (state) => ({ ...state });
|
||||
|
||||
class Clock extends React.Component {
|
||||
render() {
|
||||
const clockStyle = {
|
||||
height: '40%',
|
||||
width: '100%',
|
||||
}
|
||||
|
||||
const timerLabelStyle = {
|
||||
height: '30%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-end',
|
||||
color: colors.goldLeaf,
|
||||
}
|
||||
|
||||
const timerStyle = {
|
||||
height: '70%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
fontSize: 96,
|
||||
}
|
||||
|
||||
return(
|
||||
<div style={clockStyle}>
|
||||
<div id='timer-label' style={timerLabelStyle}>{this.props.timer}</div>
|
||||
<div id='time-left' style={timerStyle}>{this.props.clock}</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(Clock);
|
186
pomodoro-clock-react/src/Controls.js
Normal file
186
pomodoro-clock-react/src/Controls.js
Normal file
@ -0,0 +1,186 @@
|
||||
import React from 'react';
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faPlayCircle } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faPauseCircle } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faSyncAlt } from "@fortawesome/free-solid-svg-icons";
|
||||
import { colors,makeClock } from './globals'
|
||||
|
||||
import { clockIsRunningAction } from "./actions/clockIsRunningAction";
|
||||
import { zeroTimeAction } from "./actions/zeroTimeAction";
|
||||
import { clockAction } from "./actions/clockAction";
|
||||
import { timerAction } from "./actions/timerAction";
|
||||
import { sessionLengthAction } from "./actions/sessionLengthAction";
|
||||
import { breakLengthAction } from "./actions/breakLengthAction";
|
||||
import BeepSoundOgg from './BeepSound.ogg';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
clockIsRunningAction: (clockIsRunning) => dispatch(clockIsRunningAction(clockIsRunning)),
|
||||
zeroTimeAction: (zeroTime) => dispatch(zeroTimeAction(zeroTime)),
|
||||
clockAction: (time) => dispatch(clockAction(time)),
|
||||
timerAction: (timer) => dispatch(timerAction(timer)),
|
||||
sessionLengthAction: (sessionLength) => dispatch(sessionLengthAction(sessionLength)),
|
||||
breakLengthAction: (breakLength) => dispatch(breakLengthAction(breakLength)),
|
||||
});
|
||||
|
||||
const mapStateToProps = (state) => ({ ...state });
|
||||
|
||||
class Controls extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleMouseEventPlay = this.handleMouseEventPlay.bind(this);
|
||||
this.handleMouseEventPause = this.handleMouseEventPause.bind(this);
|
||||
this.handleMouseEventReset = this.handleMouseEventReset.bind(this);
|
||||
this.handlePlay = this.handlePlay.bind(this);
|
||||
this.handleReset = this.handleReset.bind(this);
|
||||
this.state = {
|
||||
playColor: colors.ivoryBlack,
|
||||
pauseColor: colors.ivoryBlack,
|
||||
resetColor: colors.ivoryBlack,
|
||||
sound: '',
|
||||
};
|
||||
};
|
||||
|
||||
handlePlay() {
|
||||
if (this.props.clockIsRunning) {
|
||||
this.props.clockIsRunningAction(false);
|
||||
} else {
|
||||
this.props.clockIsRunningAction(true);
|
||||
const now = new Date();
|
||||
const nowSeconds = Math.floor(now.getTime() / 1000);
|
||||
const remainingTime = this.props.clock.split(':');
|
||||
const remainingSeconds = (60 * parseInt(remainingTime[0])) + parseInt(remainingTime[1]);
|
||||
this.props.zeroTimeAction(nowSeconds + remainingSeconds);
|
||||
const self = this;
|
||||
let refreshClock = setInterval(function(){
|
||||
if (!self.props.clockIsRunning) {
|
||||
clearInterval(refreshClock);
|
||||
} else {
|
||||
const now = new Date();
|
||||
const nowSeconds = Math.floor(now.getTime() / 1000);
|
||||
if (nowSeconds <= self.props.zeroTime) {
|
||||
const remainingTime = self.props.zeroTime - nowSeconds;
|
||||
const newClock = makeClock(remainingTime);
|
||||
if (newClock !== self.props.clock) {
|
||||
self.props.clockAction(newClock);
|
||||
}
|
||||
} else {
|
||||
let remainingTime = self.props.breakLength * 60;
|
||||
if (self.props.timer === 'Session') {
|
||||
self.props.timerAction('Break');
|
||||
} else {
|
||||
self.props.timerAction('Session');
|
||||
remainingTime = self.props.sessionLength * 60;
|
||||
}
|
||||
self.props.zeroTimeAction(nowSeconds + remainingTime);
|
||||
self.props.clockAction(makeClock(remainingTime));
|
||||
}
|
||||
}
|
||||
},1000);
|
||||
}
|
||||
};
|
||||
|
||||
handleReset() {
|
||||
if (this.props.clockIsRunning) {
|
||||
this.props.clockIsRunningAction(false);
|
||||
}
|
||||
if (this.props.timer === 'Break') {
|
||||
this.props.timerAction('Session');
|
||||
}
|
||||
if (this.props.sessionLength !== 25) {
|
||||
this.props.sessionLengthAction(25);
|
||||
}
|
||||
if (this.props.breakLength !== 5) {
|
||||
this.props.breakLengthAction(5);
|
||||
}
|
||||
if (this.props.clock !== '25:00') {
|
||||
this.props.clockAction('25:00');
|
||||
}
|
||||
this.state.sound.pause();
|
||||
const oldSound = this.state.sound;
|
||||
oldSound.currentTime = 0;
|
||||
};
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.props.clock === '00:00') {
|
||||
this.state.sound.play();
|
||||
}
|
||||
};
|
||||
|
||||
handleMouseEventPlay(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({playColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({playColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
handleMouseEventPause(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({pauseColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({pauseColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
handleMouseEventReset(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({resetColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({resetColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
this.setState({sound: document.getElementById('beep')});
|
||||
};
|
||||
|
||||
render() {
|
||||
const controlsStyle = {
|
||||
height: '20%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
fontSize: 48,
|
||||
}
|
||||
|
||||
const playStyle = {
|
||||
color: this.state.playColor,
|
||||
};
|
||||
|
||||
const pauseStyle = {
|
||||
color: this.state.pauseColor,
|
||||
width: 150,
|
||||
};
|
||||
|
||||
const resetStyle = {
|
||||
color: this.state.resetColor,
|
||||
};
|
||||
|
||||
return(
|
||||
<div style={controlsStyle}>
|
||||
<div id='start_stop' style={playStyle} onClick={this.handlePlay}
|
||||
onMouseDown={this.handleMouseEventPlay} onMouseUp={this.handleMouseEventPlay}
|
||||
onTouchStart={this.handleMouseEventPlay} onTouchEnd={this.handleMouseEventPlay}>
|
||||
<FontAwesomeIcon icon={faPlayCircle}/>
|
||||
</div>
|
||||
|
||||
<FontAwesomeIcon style={pauseStyle} onMouseDown={this.handleMouseEventPause}
|
||||
onMouseUp={this.handleMouseEventPause} onTouchStart={this.handleMouseEventPause}
|
||||
onTouchEnd={this.handleMouseEventPause} onClick={() => {this.props.clockIsRunningAction(false)}} icon={faPauseCircle}/>
|
||||
|
||||
<div id='reset' style={resetStyle} onClick={this.handleReset}
|
||||
onMouseDown={this.handleMouseEventReset} onMouseUp={this.handleMouseEventReset}
|
||||
onTouchStart={this.handleMouseEventReset} onTouchEnd={this.handleMouseEventReset}>
|
||||
<FontAwesomeIcon icon={faSyncAlt}/>
|
||||
</div>
|
||||
|
||||
<audio id='beep' preload='auto' src={BeepSoundOgg} type='audio/ogg'></audio>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(Controls);
|
69
pomodoro-clock-react/src/PomodoroClock.js
Normal file
69
pomodoro-clock-react/src/PomodoroClock.js
Normal file
@ -0,0 +1,69 @@
|
||||
import React from 'react';
|
||||
import { connect } from "react-redux";
|
||||
import { colors } from './globals'
|
||||
|
||||
import Top from './Top';
|
||||
import Clock from './Clock';
|
||||
import Controls from './Controls';
|
||||
|
||||
const mapStateToProps = (state) => ({ ...state });
|
||||
|
||||
class PomodoroClock extends React.Component {
|
||||
render() {
|
||||
const width = this.props.innerWindowWidth;
|
||||
const height = this.props.innerWindowHeight;
|
||||
const eightyPercentWidth = Math.round(width * 0.8);
|
||||
const eightyPercentHeight = Math.round(height * 0.8);
|
||||
const maxHeight = 500;
|
||||
const maxWidth = 800;
|
||||
const style = {
|
||||
margin: 'auto',
|
||||
border: '3px solid',
|
||||
borderColor: colors.ivoryBlack,
|
||||
zIndex: '1',
|
||||
backgroundColor: colors.skyBlue,
|
||||
borderRadius: 10,
|
||||
height: eightyPercentHeight < maxHeight ? eightyPercentHeight : maxHeight,
|
||||
width: eightyPercentWidth < maxWidth ? eightyPercentWidth : maxWidth,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
fontSize: 32,
|
||||
userSelect: 'none',
|
||||
MozUserSelect: 'none',
|
||||
WebkitUserSelect: 'none',
|
||||
};
|
||||
|
||||
const clockContainerStyle = {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
};
|
||||
|
||||
if (width > height && height < 400) {
|
||||
style['height'] = '96vh';
|
||||
style['width'] = '75vw';
|
||||
style['margin'] = '1vh auto 3vh auto';
|
||||
style['fontSize'] = 24;
|
||||
} else if (height > width) {
|
||||
style['height'] = Math.round(height * 0.75);
|
||||
style['maxHeight'] = maxHeight;
|
||||
clockContainerStyle['height'] = width > style['height'] ? style['height'] : width;
|
||||
clockContainerStyle['maxHeight'] = maxHeight;
|
||||
style['width'] = width - 6;
|
||||
style['maxWidth'] = maxWidth;
|
||||
style['fontSize'] = 24;
|
||||
}
|
||||
|
||||
return(
|
||||
<div style={style}>
|
||||
<div style={clockContainerStyle}>
|
||||
<Top />
|
||||
<Clock />
|
||||
<Controls />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(PomodoroClock);
|
31
pomodoro-clock-react/src/Session.js
Normal file
31
pomodoro-clock-react/src/Session.js
Normal file
@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
|
||||
import { colors } from './globals'
|
||||
import SessionControls from './SessionControls';
|
||||
|
||||
const Session = () => {
|
||||
const style = {
|
||||
height: '100%',
|
||||
width: '50%',
|
||||
};
|
||||
|
||||
const sessionTextStyle = {
|
||||
height: '50%',
|
||||
width: '90%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
textAlign: 'left',
|
||||
marginLeft: '10%',
|
||||
color: colors.goldLeaf,
|
||||
};
|
||||
|
||||
return(
|
||||
<div style={style}>
|
||||
<div id="session-label" style={sessionTextStyle}>Session Length</div>
|
||||
<SessionControls />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Session;
|
124
pomodoro-clock-react/src/SessionControls.js
Normal file
124
pomodoro-clock-react/src/SessionControls.js
Normal file
@ -0,0 +1,124 @@
|
||||
import React from 'react';
|
||||
import { connect } from "react-redux";
|
||||
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faArrowCircleDown } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faArrowCircleUp } from "@fortawesome/free-solid-svg-icons";
|
||||
import { colors,makeClock } from './globals'
|
||||
|
||||
import { sessionLengthAction } from "./actions/sessionLengthAction";
|
||||
import { clockAction } from "./actions/clockAction";
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
sessionLengthAction: (sessionLength) => dispatch(sessionLengthAction(sessionLength)),
|
||||
clockAction: (time) => dispatch(clockAction(time)),
|
||||
});
|
||||
|
||||
const mapStateToProps = (state) => ({ ...state });
|
||||
|
||||
class SessionControls extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.handleDownArrowMouseEvent = this.handleDownArrowMouseEvent.bind(this);
|
||||
this.handleUpArrowMouseEvent = this.handleUpArrowMouseEvent.bind(this);
|
||||
this.incrementSession = this.incrementSession.bind(this);
|
||||
this.decrementSession = this.decrementSession.bind(this);
|
||||
this.state = {
|
||||
downColor: colors.ivoryBlack,
|
||||
upColor: colors.ivoryBlack,
|
||||
};
|
||||
};
|
||||
|
||||
incrementSession() {
|
||||
if (this.props.sessionLength < 60) {
|
||||
const newSessionLength = this.props.sessionLength + 1;
|
||||
if (!this.props.clockIsRunning) {
|
||||
this.props.sessionLengthAction(newSessionLength);
|
||||
if (this.props.timer === 'Session') {
|
||||
this.props.clockAction(makeClock(newSessionLength * 60));
|
||||
}
|
||||
} else {
|
||||
if (this.props.timer === 'Break') {
|
||||
this.props.sessionLengthAction(newSessionLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
decrementSession() {
|
||||
if (this.props.sessionLength > 1) {
|
||||
const newSessionLength = this.props.sessionLength - 1;
|
||||
if (!this.props.clockIsRunning) {
|
||||
this.props.sessionLengthAction(newSessionLength);
|
||||
if (this.props.timer === 'Session') {
|
||||
this.props.clockAction(makeClock(newSessionLength * 60));
|
||||
}
|
||||
} else {
|
||||
if (this.props.timer === 'Break') {
|
||||
this.props.sessionLengthAction(newSessionLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
handleDownArrowMouseEvent(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({downColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({downColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
handleUpArrowMouseEvent(e) {
|
||||
if (e.type === 'mousedown' || e.type === 'touchstart') {
|
||||
this.setState({upColor: colors.goldLeaf});
|
||||
} else if (e.type === 'mouseup' || e.type === 'touchend') {
|
||||
this.setState({upColor: colors.ivoryBlack});
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const style = {
|
||||
height: '50%',
|
||||
width: '75%',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'flex-start',
|
||||
marginLeft: '25%',
|
||||
fontSize: 32,
|
||||
};
|
||||
|
||||
const breakStyle = {
|
||||
width: 50,
|
||||
}
|
||||
|
||||
const downArrowStyle = {
|
||||
color: this.state.downColor,
|
||||
}
|
||||
|
||||
const upArrowStyle = {
|
||||
color: this.state.upColor,
|
||||
}
|
||||
|
||||
return(
|
||||
<div style={style}>
|
||||
<div id='session-decrement' style={downArrowStyle} onClick={this.decrementSession}
|
||||
onTouchStart={this.handleDownArrowMouseEvent} onTouchEnd={this.handleDownArrowMouseEvent}
|
||||
onMouseDown={this.handleDownArrowMouseEvent} onMouseUp={this.handleDownArrowMouseEvent}>
|
||||
<FontAwesomeIcon icon={faArrowCircleDown}/>
|
||||
</div>
|
||||
|
||||
<p id='session-length' style={breakStyle}>{this.props.sessionLength}</p>
|
||||
|
||||
<div id='session-increment' style={upArrowStyle} onClick={this.incrementSession}
|
||||
onTouchStart={this.handleUpArrowMouseEvent} onTouchEnd={this.handleUpArrowMouseEvent}
|
||||
onMouseDown={this.handleUpArrowMouseEvent} onMouseUp={this.handleUpArrowMouseEvent}>
|
||||
<FontAwesomeIcon icon={faArrowCircleUp}/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(SessionControls);
|
39
pomodoro-clock-react/src/Top.js
Normal file
39
pomodoro-clock-react/src/Top.js
Normal file
@ -0,0 +1,39 @@
|
||||
import React from 'react';
|
||||
|
||||
import Break from './Break';
|
||||
import Session from './Session';
|
||||
|
||||
const Top = () => {
|
||||
|
||||
const style = {
|
||||
height: '40%',
|
||||
width: '100%',
|
||||
}
|
||||
|
||||
const titleStyle = {
|
||||
height: '50%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'center',
|
||||
fontSize: 48,
|
||||
}
|
||||
|
||||
const breakAndSessionStyle = {
|
||||
height: '50%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
}
|
||||
|
||||
return(
|
||||
<div style={style}>
|
||||
<div style={titleStyle}>Pomodoro Clock</div>
|
||||
<div style={breakAndSessionStyle}>
|
||||
<Break />
|
||||
<Session />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Top;
|
8
pomodoro-clock-react/src/actions/breakLengthAction.js
Normal file
8
pomodoro-clock-react/src/actions/breakLengthAction.js
Normal file
@ -0,0 +1,8 @@
|
||||
export const SETBREAKLENGTH = "SETBREAKLENGTH";
|
||||
|
||||
export const breakLengthAction = (breakLength) => {
|
||||
return {
|
||||
type: SETBREAKLENGTH,
|
||||
breakLength: breakLength,
|
||||
};
|
||||
};
|
8
pomodoro-clock-react/src/actions/clockAction.js
Normal file
8
pomodoro-clock-react/src/actions/clockAction.js
Normal file
@ -0,0 +1,8 @@
|
||||
export const SETCLOCK = "SETCLOCK";
|
||||
|
||||
export const clockAction = (time) => {
|
||||
return {
|
||||
type: SETCLOCK,
|
||||
time: time,
|
||||
};
|
||||
};
|
8
pomodoro-clock-react/src/actions/clockIsRunningAction.js
Normal file
8
pomodoro-clock-react/src/actions/clockIsRunningAction.js
Normal file
@ -0,0 +1,8 @@
|
||||
export const SETCLOCKISRUNNING = "SETCLOCKISRUNNING";
|
||||
|
||||
export const clockIsRunningAction = (clockIsRunning) => {
|
||||
return {
|
||||
type: SETCLOCKISRUNNING,
|
||||
clockIsRunning: clockIsRunning,
|
||||
};
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
export const SETWINDOWINNERHEIGHT = "SETWINDOWINNERHEIGHT";
|
||||
|
||||
export const innerWindowHeightAction = (windowInnerHeight) => {
|
||||
return {
|
||||
type: SETWINDOWINNERHEIGHT,
|
||||
windowInnerHeight: windowInnerHeight,
|
||||
};
|
||||
};
|
@ -0,0 +1,8 @@
|
||||
export const SETWINDOWINNERWIDTH = "SETWINDOWINNERWIDTH";
|
||||
|
||||
export const innerWindowWidthAction = (windowInnerWidth) => {
|
||||
return {
|
||||
type: SETWINDOWINNERWIDTH,
|
||||
windowInnerWidth: windowInnerWidth,
|
||||
};
|
||||
};
|
8
pomodoro-clock-react/src/actions/sessionLengthAction.js
Normal file
8
pomodoro-clock-react/src/actions/sessionLengthAction.js
Normal file
@ -0,0 +1,8 @@
|
||||
export const SETSESSIONLENGTH = "SETSESSIONLENGTH";
|
||||
|
||||
export const sessionLengthAction = (sessionLength) => {
|
||||
return {
|
||||
type: SETSESSIONLENGTH,
|
||||
sessionLength: sessionLength,
|
||||
};
|
||||
};
|
8
pomodoro-clock-react/src/actions/timerAction.js
Normal file
8
pomodoro-clock-react/src/actions/timerAction.js
Normal file
@ -0,0 +1,8 @@
|
||||
export const SETTIMER = "SETTIMER";
|
||||
|
||||
export const timerAction = (timer) => {
|
||||
return {
|
||||
type: SETTIMER,
|
||||
timer: timer,
|
||||
};
|
||||
};
|
8
pomodoro-clock-react/src/actions/zeroTimeAction.js
Normal file
8
pomodoro-clock-react/src/actions/zeroTimeAction.js
Normal file
@ -0,0 +1,8 @@
|
||||
export const SETZEROTIME = "SETZEROTIME";
|
||||
|
||||
export const zeroTimeAction = (zeroTime) => {
|
||||
return {
|
||||
type: SETZEROTIME,
|
||||
zeroTime: zeroTime,
|
||||
};
|
||||
};
|
14
pomodoro-clock-react/src/globals.js
Normal file
14
pomodoro-clock-react/src/globals.js
Normal file
@ -0,0 +1,14 @@
|
||||
export const colors = {
|
||||
prussianBlue: '#0b3c5d',
|
||||
skyBlue: '#328cc1',
|
||||
goldLeaf: '#d9b310',
|
||||
ivoryBlack: '#1d2731',
|
||||
};
|
||||
|
||||
export const makeClock = (remainingTime) => {
|
||||
const remainingSeconds = remainingTime % 60;
|
||||
const remainingMinutes = Math.floor(remainingTime / 60);
|
||||
const minutes = remainingMinutes > 9 ? remainingMinutes.toString() : '0' + remainingMinutes.toString() ;
|
||||
const seconds = remainingSeconds > 9 ? remainingSeconds.toString() : '0' + remainingSeconds.toString() ;
|
||||
return minutes + ':' + seconds;
|
||||
};
|
14
pomodoro-clock-react/src/index.css
Normal file
14
pomodoro-clock-react/src/index.css
Normal file
@ -0,0 +1,14 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
13
pomodoro-clock-react/src/index.css.bak
Normal file
13
pomodoro-clock-react/src/index.css.bak
Normal file
@ -0,0 +1,13 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
20
pomodoro-clock-react/src/index.js
Normal file
20
pomodoro-clock-react/src/index.js
Normal file
@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { Provider } from "react-redux";
|
||||
import store from "./store";
|
||||
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<App />
|
||||
</Provider>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||
serviceWorker.unregister();
|
14
pomodoro-clock-react/src/reducers/breakLengthReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/breakLengthReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETBREAKLENGTH } from "../actions/breakLengthAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = 5;
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETBREAKLENGTH:
|
||||
return action.breakLength;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
14
pomodoro-clock-react/src/reducers/clockIsRunningReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/clockIsRunningReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETCLOCKISRUNNING } from "../actions/clockIsRunningAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = false;
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETCLOCKISRUNNING:
|
||||
return action.clockIsRunning;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
14
pomodoro-clock-react/src/reducers/clockReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/clockReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETCLOCK } from "../actions/clockAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = '25:00';
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETCLOCK:
|
||||
return action.time;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
import { SETWINDOWINNERHEIGHT } from "../actions/innerWindowHeightAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = window.innerHeight;
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETWINDOWINNERHEIGHT:
|
||||
return action.windowInnerHeight;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
14
pomodoro-clock-react/src/reducers/innerWindowWidthReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/innerWindowWidthReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETWINDOWINNERWIDTH } from "../actions/innerWindowWidthAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = window.innerWidth;
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETWINDOWINNERWIDTH:
|
||||
return action.windowInnerWidth;
|
||||
default:
|
||||
return state;
|
||||
};
|
||||
};
|
20
pomodoro-clock-react/src/reducers/rootReducer.js
Normal file
20
pomodoro-clock-react/src/reducers/rootReducer.js
Normal file
@ -0,0 +1,20 @@
|
||||
import { combineReducers } from "redux";
|
||||
import innerWindowWidthReducer from "./innerWindowWidthReducer";
|
||||
import innerWindowHeightReducer from "./innerWindowHeightReducer";
|
||||
import breakLengthReducer from "./breakLengthReducer";
|
||||
import sessionLengthReducer from "./sessionLengthReducer";
|
||||
import timerReducer from "./timerReducer";
|
||||
import clockReducer from "./clockReducer";
|
||||
import clockIsRunningReducer from "./clockIsRunningReducer";
|
||||
import zeroTimeReducer from "./zeroTimeReducer";
|
||||
|
||||
export default combineReducers({
|
||||
innerWindowWidth: innerWindowWidthReducer,
|
||||
innerWindowHeight: innerWindowHeightReducer,
|
||||
breakLength: breakLengthReducer,
|
||||
sessionLength: sessionLengthReducer,
|
||||
timer: timerReducer,
|
||||
clock: clockReducer,
|
||||
clockIsRunning: clockIsRunningReducer,
|
||||
zeroTime: zeroTimeReducer,
|
||||
});
|
14
pomodoro-clock-react/src/reducers/sessionLengthReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/sessionLengthReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETSESSIONLENGTH } from "../actions/sessionLengthAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = 25;
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETSESSIONLENGTH:
|
||||
return action.sessionLength;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
14
pomodoro-clock-react/src/reducers/timerReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/timerReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETTIMER } from "../actions/timerAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = 'Session';
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETTIMER:
|
||||
return action.timer;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
14
pomodoro-clock-react/src/reducers/zeroTimeReducer.js
Normal file
14
pomodoro-clock-react/src/reducers/zeroTimeReducer.js
Normal file
@ -0,0 +1,14 @@
|
||||
import { SETZEROTIME } from "../actions/zeroTimeAction";
|
||||
|
||||
export default (state, action) => {
|
||||
if (!state) {
|
||||
state = 0;
|
||||
}
|
||||
|
||||
switch (action.type) {
|
||||
case SETZEROTIME:
|
||||
return action.zeroTime;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
141
pomodoro-clock-react/src/serviceWorker.js
Normal file
141
pomodoro-clock-react/src/serviceWorker.js
Normal file
@ -0,0 +1,141 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' },
|
||||
})
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
5
pomodoro-clock-react/src/setupTests.js
Normal file
5
pomodoro-clock-react/src/setupTests.js
Normal file
@ -0,0 +1,5 @@
|
||||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom/extend-expect';
|
6
pomodoro-clock-react/src/store.js
Normal file
6
pomodoro-clock-react/src/store.js
Normal file
@ -0,0 +1,6 @@
|
||||
import { createStore } from "redux";
|
||||
import rootReducer from "./reducers/rootReducer";
|
||||
|
||||
const store = createStore(rootReducer);
|
||||
|
||||
export default store;
|
Loading…
Reference in New Issue
Block a user