├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.css ├── App.js ├── App.test.js ├── components ├── Header │ ├── Header.js │ └── styles.css ├── Task │ ├── Task.js │ └── styles.css └── TaskList │ ├── TaskList.js │ └── styles.css ├── data.json ├── hooks ├── useConfigManager.js └── useDataManager.js ├── index.css ├── index.js ├── logo.svg ├── reportWebVitals.js └── setupTests.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | -------------------------------------------------------------------------------- /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 your browser. 13 | 14 | The page will reload when you make changes.\ 15 | You may 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 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.2", 7 | "@testing-library/react": "^12.1.3", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^17.0.2", 10 | "react-dom": "^17.0.2", 11 | "react-scripts": "5.0.0", 12 | "web-vitals": "^2.1.4" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "react-scripts test", 18 | "eject": "react-scripts eject" 19 | }, 20 | "eslintConfig": { 21 | "extends": [ 22 | "react-app", 23 | "react-app/jest" 24 | ] 25 | }, 26 | "browserslist": { 27 | "production": [ 28 | ">0.2%", 29 | "not dead", 30 | "not op_mini all" 31 | ], 32 | "development": [ 33 | "last 1 chrome version", 34 | "last 1 firefox version", 35 | "last 1 safari version" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiffinTech/react-todo-app/9fbcc782f98ada3070d8c8063fb5ee8b6519183c/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiffinTech/react-todo-app/9fbcc782f98ada3070d8c8063fb5ee8b6519183c/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiffinTech/react-todo-app/9fbcc782f98ada3070d8c8063fb5ee8b6519183c/public/logo512.png -------------------------------------------------------------------------------- /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 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | /* BASIC THEMING */ 2 | 3 | body { 4 | --accent-color: rgb(235, 28, 71); /* from one of your shirts :) */ 5 | --bg-color: white; 6 | --fg-color: #222; 7 | 8 | background-color: var(--bg-color); 9 | color: var(--fg-color); 10 | } 11 | 12 | body.dark { 13 | --bg-color: #222; 14 | --fg-color: #eee; 15 | } 16 | 17 | .App { 18 | text-align: center; 19 | max-width: 960px; 20 | margin: 0 auto; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from 'react'; 2 | import { useEffect } from "react"; 3 | 4 | import './App.css'; 5 | 6 | // components 7 | import Header from './components/Header/Header'; 8 | import TaskList from './components/TaskList/TaskList'; 9 | 10 | // hooks 11 | import useDataManager from './hooks/useDataManager'; 12 | 13 | function App() { 14 | const {taskList} = useDataManager(); // Instantiating our data manager custom hook 15 | const [dataAPI, setData] = useState(null); 16 | 17 | const fetchData = () => { 18 | return fetch('https://www.boredapi.com/api/activity') 19 | .then((response) => response.json()) 20 | .then((dataAPI) => { 21 | setData([dataAPI]) 22 | }) 23 | } 24 | 25 | useEffect(() => { 26 | fetchData() 27 | }, []) 28 | 29 | 30 | return ( 31 |
32 |
33 | 34 |

THIS API IS CONTROLLING MY LIFE

35 | 36 | {dataAPI && 37 | dataAPI.map(({ activity }) => ( 38 |
39 |

{activity}

40 |
41 | ))} 42 | 43 |
44 | ); 45 | } 46 | 47 | export default App; 48 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/components/Header/Header.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react'; 2 | import useConfigManager from '../../hooks/useConfigManager'; 3 | import './styles.css'; 4 | 5 | const Header = () => { 6 | const { currentConfig, isDarkMode, toggleMode } = useConfigManager(); // Custom hook to manage app config 7 | 8 | /** 9 | * Event handler for the theme button 10 | * calls the toggleMode mthod from our 11 | * custom hook 'useConfigManger' 12 | */ 13 | const onBtnModeClicked = () => { 14 | toggleMode(); // Toggles the mode and stores the new config 15 | } 16 | 17 | // Debug only 18 | useEffect(() => { 19 | if (!currentConfig) return; 20 | 21 | console.log(':: current mode is', isDarkMode(), currentConfig); 22 | }, [isDarkMode, currentConfig]); 23 | 24 | return ( 25 |
26 |

Productivity To Do List

27 |
28 | 29 | 30 | 31 |
32 |
33 | ); 34 | }; 35 | 36 | export default Header; 37 | -------------------------------------------------------------------------------- /src/components/Header/styles.css: -------------------------------------------------------------------------------- 1 | .header { 2 | color: var(--accent-color); 3 | 4 | display: flex; 5 | justify-content: space-between; 6 | align-items: center; 7 | } 8 | 9 | .header .btn-theme { 10 | display: flex; 11 | padding: .2rem; 12 | border: 1px solid var(--accent-color); 13 | border-radius: .2rem; 14 | cursor: pointer; 15 | } 16 | 17 | .header .btn-theme:hover { 18 | transform: scale(0.96); 19 | } -------------------------------------------------------------------------------- /src/components/Task/Task.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './styles.css'; 3 | 4 | const Task = ({ task }) => { 5 | return
{task.event}
; 6 | }; 7 | 8 | export default Task; 9 | -------------------------------------------------------------------------------- /src/components/Task/styles.css: -------------------------------------------------------------------------------- 1 | .task { 2 | /* start here styling :) */ 3 | } 4 | -------------------------------------------------------------------------------- /src/components/TaskList/TaskList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './styles.css'; 3 | 4 | import Task from '../Task/Task'; 5 | 6 | const TaskList = ({ taskList }) => { 7 | return ( 8 |
9 | {taskList.map((task, idx) => { 10 | return ; 11 | })} 12 |
13 | ); 14 | }; 15 | 16 | export default TaskList; 17 | -------------------------------------------------------------------------------- /src/components/TaskList/styles.css: -------------------------------------------------------------------------------- 1 | .task-list { 2 | /* start here styling :) */ 3 | } 4 | -------------------------------------------------------------------------------- /src/data.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id":1, 4 | "event": "Finish coding feature at work", 5 | "finished": true 6 | }, 7 | { 8 | "id":2, 9 | "event": "Film content for partner at Tiffintech", 10 | "finished": false 11 | }, 12 | { 13 | "id":3, 14 | "event": "Edit short form Tiktok video", 15 | "finished": true 16 | }, 17 | { 18 | "id":4, 19 | "event": "Take dogs to groomer", 20 | "finished": false 21 | }, 22 | { 23 | "id":5, 24 | "event": "Meet with mentor", 25 | "finished": false 26 | }, 27 | { 28 | "id":6, 29 | "event": "Read book tonight", 30 | "finished": false 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /src/hooks/useConfigManager.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react" 2 | 3 | const LOCAL_STORAGE_KEY = "tt-todo"; 4 | 5 | /* 6 | type Config = { 7 | theme: "default" | "dark" 8 | } 9 | */ 10 | 11 | /** 12 | * Custom hook to manage the application configuration 13 | */ 14 | const useConfigManager = () => { 15 | const [currentConfig, setCurrentConfig] = useState(null) // type: Config | null 16 | 17 | /** 18 | * Sets the UI mode to default (light) or dark 19 | * @param {string} newMode "default" | "dark" 20 | */ 21 | const setMode = (newMode) => { // type: "default" | "dark" 22 | if (!(newMode in ["default", "dark"])) return; // param makes no sense... 23 | setCurrentConfig({ ...currentConfig, theme: newMode }); 24 | } 25 | 26 | /** 27 | * Toggles the UI mode between dark mode and default (light) mode 28 | */ 29 | const toggleMode = () => { 30 | const newMode = currentConfig.theme === "dark" ? "default" : "dark"; 31 | setCurrentConfig({ ...currentConfig, theme: newMode }); 32 | } 33 | 34 | // Tries to load a former saved config from the browser's localStorage 35 | // and uses it or stores a new default config and uses this one 36 | useEffect(() => { 37 | let savedConfig; 38 | const savedConfigTxt = localStorage.getItem(LOCAL_STORAGE_KEY); 39 | 40 | // Try getting former stored config 41 | if (!savedConfigTxt) { 42 | // nope, not found, so we save a default config 43 | savedConfig = { theme: "dark" } 44 | localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(savedConfig)); 45 | } 46 | else { 47 | savedConfig = JSON.parse(savedConfigTxt); 48 | } 49 | 50 | // This setting triggers the text useEffect below 51 | setCurrentConfig(savedConfig); 52 | }, []); 53 | 54 | // Called every time the config changes 55 | useEffect(() => { 56 | if (!currentConfig) return; // Nothing to do 57 | 58 | if (currentConfig.theme === "dark") { 59 | // Add the css-class to the body tag, if we are in dark mode 60 | document.body.classList.add("dark"); 61 | } 62 | else { 63 | // Remove the dark mode css-class 64 | document.body.classList.remove("dark"); 65 | } 66 | 67 | // Store the new config 68 | localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(currentConfig)); 69 | }, [currentConfig]) 70 | 71 | return { 72 | currentConfig, 73 | setMode, 74 | toggleMode, 75 | isDarkMode: () => currentConfig.theme === "dark" 76 | } 77 | } 78 | 79 | export default useConfigManager; -------------------------------------------------------------------------------- /src/hooks/useDataManager.js: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import fakeData from "../data.json"; // Just temporary dummy data 3 | 4 | /** 5 | * Custom hook to manage our app data 6 | */ 7 | const useDataManager = () => { 8 | const [taskList, setTaskList] = useState([]); // The array of all fetched tasks - type: array of Task 9 | const [isLoading, setIsLoading] = useState(false); // Indicator, if data is currently loading 10 | const [loadingError, setLoadingError] = useState(null); // contains the error from data loading - type Error | null 11 | 12 | // Initial loading the data 13 | useEffect(() => { 14 | setIsLoading(true); 15 | 16 | try { 17 | // useEffect doesn't allow async so we wrap the async tasks 18 | // into a function and call the fuction later 19 | const loadDataFromApi = async () => { 20 | // Here will the data fetch magic happen 21 | setTaskList(fakeData); 22 | } 23 | 24 | loadDataFromApi(); // Execute the async function 25 | } catch (err) { 26 | // Handle the error case 27 | setTaskList([]); 28 | setLoadingError(err); 29 | } finally { 30 | // Either successfull or with error, now we are done loading data :) 31 | setIsLoading(false); 32 | } 33 | 34 | }, []); 35 | 36 | return { 37 | taskList, 38 | isLoading, 39 | loadingError 40 | } 41 | } 42 | 43 | export default useDataManager; -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /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 reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 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 | --------------------------------------------------------------------------------