├── .gitignore ├── .prettierrc ├── README.md ├── package-lock.json ├── package.json ├── public ├── index.html └── robots.txt ├── src ├── App.test.tsx ├── assets │ └── audio │ │ └── bell.mp3 ├── components │ └── dialog │ │ └── index.tsx ├── context │ └── index.ts ├── index.css ├── index.tsx ├── layout │ ├── hero │ │ └── index.tsx │ └── setting │ │ └── index.tsx ├── lib │ └── time │ │ └── index.ts ├── pages │ └── index │ │ └── index.tsx ├── react-app-env.d.ts ├── reportWebVitals.ts ├── routes │ ├── route-generator.ts │ └── routes.ts ├── setupTests.ts └── shared │ └── nav-scroll │ └── index.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | 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. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "timer2", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.7.1", 7 | "@emotion/styled": "^11.6.0", 8 | "@mui/icons-material": "^5.2.5", 9 | "@mui/material": "^5.2.6", 10 | "@testing-library/jest-dom": "^5.16.1", 11 | "@testing-library/react": "^12.1.2", 12 | "@testing-library/user-event": "^13.5.0", 13 | "@types/jest": "^27.4.0", 14 | "@types/node": "^16.11.17", 15 | "@types/react": "^17.0.38", 16 | "@types/react-dom": "^17.0.11", 17 | "howler": "^2.2.3", 18 | "nprogress": "^0.2.0", 19 | "react": "^17.0.2", 20 | "react-dom": "^17.0.2", 21 | "react-hot-toast": "^2.1.1", 22 | "react-lazy-with-preload": "^2.0.1", 23 | "react-router-dom": "^6.2.1", 24 | "react-scripts": "5.0.0", 25 | "typescript": "^4.5.4", 26 | "web-vitals": "^2.1.2" 27 | }, 28 | "scripts": { 29 | "start": "react-scripts start", 30 | "build": "react-scripts build", 31 | "test": "react-scripts test", 32 | "eject": "react-scripts eject" 33 | }, 34 | "eslintConfig": { 35 | "extends": [ 36 | "react-app", 37 | "react-app/jest" 38 | ] 39 | }, 40 | "browserslist": { 41 | "production": [ 42 | ">0.2%", 43 | "not dead", 44 | "not op_mini all" 45 | ], 46 | "development": [ 47 | "last 1 chrome version", 48 | "last 1 firefox version", 49 | "last 1 safari version" 50 | ] 51 | }, 52 | "devDependencies": { 53 | "@types/howler": "^2.2.4", 54 | "@types/nprogress": "^0.2.0" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Timer Application 7 | 8 | 9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { render, screen } from '@testing-library/react' 3 | 4 | test('renders learn react link', () => { 5 | const linkElement = screen.getByText(/learn react/i) 6 | expect(linkElement).toBeInTheDocument() 7 | }) 8 | -------------------------------------------------------------------------------- /src/assets/audio/bell.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asyncfinkd/timer/5bc9066785ea9e32e1e9ae649db2156b17f62390/src/assets/audio/bell.mp3 -------------------------------------------------------------------------------- /src/components/dialog/index.tsx: -------------------------------------------------------------------------------- 1 | import Dialog from '@mui/material/Dialog' 2 | import DialogActions from '@mui/material/DialogActions' 3 | import DialogContent from '@mui/material/DialogContent' 4 | import DialogContentText from '@mui/material/DialogContentText' 5 | import DialogTitle from '@mui/material/DialogTitle' 6 | import { TransitionProps } from '@mui/material/transitions' 7 | import Slide from '@mui/material/Slide' 8 | import Button from '@mui/material/Button' 9 | import React from 'react' 10 | 11 | const Transition = React.forwardRef(function Transition( 12 | props: TransitionProps & { 13 | children: React.ReactElement 14 | }, 15 | ref: React.Ref 16 | ) { 17 | return 18 | }) 19 | 20 | export const Dialogs = ({ 21 | text, 22 | handleClose, 23 | open, 24 | }: { 25 | text: string 26 | handleClose: () => void 27 | open: boolean 28 | }) => { 29 | return ( 30 | <> 31 | 38 | {'Timer Reminder'} 39 | 40 | 41 | {text} 42 | 43 | 44 | 45 | 53 | 54 | 55 | 56 | ) 57 | } 58 | -------------------------------------------------------------------------------- /src/context/index.ts: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | 3 | export interface TContext { 4 | minutes: string 5 | minutesToSecond: number 6 | notification: string 7 | timer: number 8 | } 9 | 10 | export interface TAppContext { 11 | setting: TContext 12 | setSetting: React.Dispatch> 13 | } 14 | 15 | export const ApplicationContext = React.createContext(null) 16 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | box-sizing: border-box; 5 | } 6 | 7 | body { 8 | margin: 0; 9 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 10 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 11 | sans-serif; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | } 15 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { Suspense } from 'react' 2 | import ReactDOM from 'react-dom' 3 | import './index.css' 4 | import reportWebVitals from './reportWebVitals' 5 | import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom' 6 | import { ApplicationContext, TContext } from 'context' 7 | import { RoutesData } from 'routes/route-generator' 8 | import { Toaster } from 'react-hot-toast' 9 | import { NavigationScroll } from 'shared/nav-scroll' 10 | import NProgress from 'nprogress' 11 | import 'nprogress/nprogress.css' 12 | 13 | const LazyLoad = () => { 14 | React.useEffect(() => { 15 | NProgress.configure({ showSpinner: false }) 16 | NProgress.start() 17 | 18 | return () => { 19 | NProgress.done() 20 | } 21 | }) 22 | 23 | return <> 24 | } 25 | 26 | const Pages = () => { 27 | const [setting, setSetting] = React.useState({ 28 | minutes: '10', 29 | minutesToSecond: 600, 30 | notification: 'sound', 31 | timer: 10 * 60, 32 | }) 33 | 34 | return ( 35 | 36 | 37 | {RoutesData.map((el) => { 38 | return ( 39 | } /> 40 | ) 41 | })} 42 | } /> 43 | 44 | 45 | ) 46 | } 47 | 48 | ReactDOM.render( 49 | 50 | 51 | 52 | 53 | }> 54 | 55 | 56 | 57 | 58 | , 59 | document.getElementById('root') 60 | ) 61 | 62 | // If you want to start measuring performance in your app, pass a function 63 | // to log results (for example: reportWebVitals(console.log)) 64 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 65 | reportWebVitals() 66 | -------------------------------------------------------------------------------- /src/layout/hero/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react-hooks/exhaustive-deps */ 2 | import React from 'react' 3 | import Box from '@mui/material/Box' 4 | import IconButton from '@mui/material/IconButton' 5 | import PauseRounded from '@mui/icons-material/PauseRounded' 6 | import PlayArrowRounded from '@mui/icons-material/PlayArrowRounded' 7 | import FastRewindRounded from '@mui/icons-material/FastRewindRounded' 8 | import FastForwardRounded from '@mui/icons-material/FastForwardRounded' 9 | import Tooltip from '@mui/material/Tooltip' 10 | import { formatTime } from '../../lib/time' 11 | import { ApplicationContext } from 'context' 12 | import toast from 'react-hot-toast' 13 | import { Dialogs } from 'components/dialog' 14 | // @ts-ignore 15 | import Bell from 'assets/audio/bell.mp3' 16 | import { Howl, Howler } from 'howler' 17 | 18 | export default function Hero() { 19 | const { setting }: any = React.useContext(ApplicationContext) 20 | const [timer, setTimer] = React.useState(setting.timer) 21 | const [paused, setPaused] = React.useState(true) 22 | const [breakLength] = React.useState(['00:00']) 23 | const [open, setOpen] = React.useState(false) 24 | 25 | const handleClose = () => { 26 | setOpen(false) 27 | } 28 | 29 | React.useEffect(() => { 30 | setTimer(setting.timer) 31 | }, [setting]) 32 | 33 | const SoundPlay = (src: string) => { 34 | const sound = new Howl({ 35 | src, 36 | }) 37 | 38 | sound.play() 39 | } 40 | 41 | React.useEffect(() => { 42 | if (!paused) { 43 | if (formatTime(timer) === breakLength[0]) { 44 | document.title = 'Reminder!' 45 | setPaused(true) 46 | 47 | if (setting.notification === 'text') { 48 | setOpen(true) 49 | } else { 50 | SoundPlay(Bell) 51 | } 52 | } else { 53 | document.title = `${formatTime(timer)} | Timer` 54 | 55 | setTimeout(() => { 56 | setTimer(timer - 1) 57 | }, 1000) 58 | } 59 | } 60 | }, [paused, timer]) 61 | 62 | Howler.volume(1.0) 63 | return ( 64 | <> 65 | 72 | 78 | 91 | {formatTime(timer)} 92 | 93 | 94 | { 97 | if (paused) { 98 | if (formatTime(timer) !== breakLength[0]) { 99 | setTimer(timer - setting.minutesToSecond) 100 | } 101 | } else { 102 | toast.error( 103 | 'If you want to change time first of all stop timer' 104 | ) 105 | } 106 | }} 107 | > 108 | 109 | 110 | 111 | { 114 | if (formatTime(timer) === breakLength[0]) { 115 | toast.error('Please choose time.') 116 | } else { 117 | toast.dismiss() 118 | setPaused(!paused) 119 | } 120 | }} 121 | > 122 | {paused ? ( 123 | 124 | 125 | 126 | ) : ( 127 | 128 | 129 | 130 | )} 131 | 132 | { 135 | if (paused) { 136 | setTimer(timer + setting.minutesToSecond) 137 | } else { 138 | toast.error( 139 | 'If you want to change time first of all stop timer' 140 | ) 141 | } 142 | }} 143 | > 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | ) 153 | } 154 | -------------------------------------------------------------------------------- /src/layout/setting/index.tsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react-hooks/exhaustive-deps */ 2 | import React from 'react' 3 | import Box from '@mui/material/Box' 4 | import SettingsIcon from '@mui/icons-material/Settings' 5 | import CloseIcon from '@mui/icons-material/Close' 6 | import Tooltip from '@mui/material/Tooltip' 7 | import InputLabel from '@mui/material/InputLabel' 8 | import MenuItem from '@mui/material/MenuItem' 9 | import FormControl from '@mui/material/FormControl' 10 | import Select from '@mui/material/Select' 11 | import TextField from '@mui/material/TextField' 12 | import { ApplicationContext } from 'context' 13 | import { Button } from '@mui/material' 14 | 15 | export default function Setting() { 16 | const { setting, setSetting }: any = React.useContext(ApplicationContext) 17 | const [show, setShow] = React.useState(false) 18 | const [notification, setNotification] = React.useState( 19 | setting.notification 20 | ) 21 | const [incrementDecrementTime, setIncrementDecrementTime] = 22 | React.useState(setting.minutes) 23 | 24 | React.useEffect(() => { 25 | setSetting({ 26 | minutes: incrementDecrementTime, 27 | minutesToSecond: parseInt(incrementDecrementTime) * 60, 28 | timer: 10 * 60, 29 | }) 30 | }, [incrementDecrementTime]) 31 | 32 | React.useEffect(() => { 33 | setting.notification = notification 34 | }, [notification]) 35 | return ( 36 | <> 37 | {show && ( 38 | <> 39 | setShow(!show)} 47 | zIndex="9" 48 | sx={{ 49 | transition: 'background 0.3s ease 0s', 50 | }} 51 | > 52 | 61 | 69 | 70 | Timer Setting 71 | 72 | 73 | 74 | setShow(!show)} 81 | /> 82 | 83 | 84 | 85 | 86 | 87 | 88 | Notification 89 | 90 | 100 | 101 | 102 | { 109 | setIncrementDecrementTime(e.target.value) 110 | }} 111 | /> 112 | 113 | 124 | 125 | 126 | 127 | )} 128 | setShow(!show)} 146 | > 147 | 148 | 149 | 150 | ) 151 | } 152 | -------------------------------------------------------------------------------- /src/lib/time/index.ts: -------------------------------------------------------------------------------- 1 | export const formatTime = (time: number) => { 2 | let minutes = Math.floor(time / 60) 3 | let seconds = time % 60 4 | return ( 5 | (minutes < 10 ? '0' + minutes : minutes) + 6 | ':' + 7 | (seconds < 10 ? '0' + seconds : seconds) 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /src/pages/index/index.tsx: -------------------------------------------------------------------------------- 1 | import Hero from 'layout/hero' 2 | import Setting from 'layout/setting' 3 | 4 | export default function IndexPage() { 5 | return ( 6 | <> 7 | 8 | 9 | 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/routes/route-generator.ts: -------------------------------------------------------------------------------- 1 | import lazy from 'react-lazy-with-preload' 2 | import { routes } from './routes' 3 | 4 | export const RoutesData = [ 5 | { 6 | title: 'Index', 7 | path: routes.index, 8 | component: lazy(() => import('pages/index')), 9 | }, 10 | ] 11 | -------------------------------------------------------------------------------- /src/routes/routes.ts: -------------------------------------------------------------------------------- 1 | export const Routes = { 2 | index: '/', 3 | } 4 | 5 | export const routes = { ...Routes } 6 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/shared/nav-scroll/index.ts: -------------------------------------------------------------------------------- 1 | import { useEffect } from 'react' 2 | import { useLocation } from 'react-router-dom' 3 | 4 | export const NavigationScroll = ({ children }: any) => { 5 | const location = useLocation() 6 | const { pathname } = location 7 | 8 | useEffect(() => { 9 | window.scrollTo({ 10 | top: 0, 11 | left: 0, 12 | behavior: 'smooth', 13 | }) 14 | }, [pathname]) 15 | 16 | return children || null 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx", 22 | "baseUrl": "./src" 23 | }, 24 | "include": [ 25 | "src" 26 | ] 27 | } 28 | --------------------------------------------------------------------------------