├── src ├── index.css ├── style.css ├── index.js ├── components │ ├── Footer.js │ ├── Header.js │ ├── TaskList.js │ ├── AddTask.js │ └── TaskItem.js └── App.js ├── postcss.config.js ├── tailwind.config.js ├── public └── index.html ├── .gitignore ├── package.json └── README.md /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./src/**/*.{js,jsx,ts,tsx}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | }; 9 | -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | .task-list::-webkit-scrollbar { 2 | width: 4px; 3 | } 4 | 5 | .task-list::-webkit-scrollbar-track { 6 | box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); 7 | } 8 | 9 | .task-list::-webkit-scrollbar-thumb { 10 | background-color: teal; 11 | border-radius: 5px; 12 | } 13 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | import App from "./App"; 4 | import "./index.css"; 5 | import "./style.css"; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById("root")); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | react todo app 9 | 10 | 11 | 12 |
13 | 14 | 15 | -------------------------------------------------------------------------------- /.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 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /src/components/Footer.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | const Footer = () => { 4 | return ( 5 | 10 | ); 11 | }; 12 | 13 | export default Footer; 14 | -------------------------------------------------------------------------------- /src/components/Header.js: -------------------------------------------------------------------------------- 1 | import { FaReact } from "react-icons/fa"; 2 | import React from "react"; 3 | 4 | const Header = () => { 5 | return ( 6 |
7 |

8 | 9 | 10 | 11 | react todo app 12 |

13 |
14 | ); 15 | }; 16 | 17 | export default Header; 18 | -------------------------------------------------------------------------------- /src/components/TaskList.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import TaskItem from "./TaskItem"; 3 | 4 | const TaskList = ({ 5 | tasks, 6 | error, 7 | loading, 8 | handleEditeSubmit, 9 | editedText, 10 | setEditedText, 11 | }) => { 12 | return ( 13 |
14 | {loading ? ( 15 |

{error ? error : "loading..."}

16 | ) : tasks.length > 0 ? ( 17 | tasks.map((task) => ( 18 | 25 | )) 26 | ) : ( 27 |

28 | data not found 29 |

30 | )} 31 |
32 | ); 33 | }; 34 | 35 | export default TaskList; 36 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "todo-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.16.5", 7 | "@testing-library/react": "^13.4.0", 8 | "@testing-library/user-event": "^13.5.0", 9 | "react": "^18.2.0", 10 | "react-dom": "^18.2.0", 11 | "react-icon": "^1.0.0", 12 | "react-icons": "^4.7.1", 13 | "react-scripts": "5.0.1", 14 | "web-vitals": "^2.1.4" 15 | }, 16 | "scripts": { 17 | "start": "react-scripts start", 18 | "build": "react-scripts build", 19 | "test": "react-scripts test", 20 | "eject": "react-scripts eject" 21 | }, 22 | "eslintConfig": { 23 | "extends": [ 24 | "react-app", 25 | "react-app/jest" 26 | ] 27 | }, 28 | "browserslist": { 29 | "production": [ 30 | ">0.2%", 31 | "not dead", 32 | "not op_mini all" 33 | ], 34 | "development": [ 35 | "last 1 chrome version", 36 | "last 1 firefox version", 37 | "last 1 safari version" 38 | ] 39 | }, 40 | "devDependencies": { 41 | "autoprefixer": "^10.4.13", 42 | "postcss": "^8.4.19", 43 | "tailwindcss": "^3.2.4" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/components/AddTask.js: -------------------------------------------------------------------------------- 1 | import React, { useRef, useState } from "react"; 2 | 3 | const AddTask = ({ tasks, setTasks }) => { 4 | const [task, setTast] = useState(""); 5 | const inputRef = useRef(null); 6 | 7 | //add task handler event 8 | const addTaskHandler = (e) => { 9 | e.preventDefault(); 10 | 11 | //post task into server 12 | taskPosting(task); 13 | 14 | //input focus blur 15 | inputRef.current.blur(); 16 | //input clear 17 | setTast(""); 18 | }; 19 | 20 | //task posting 21 | const taskPosting = async (text) => { 22 | const res = await fetch( 23 | "https://dramatic-quintessential-deerstalker.glitch.me/tasks", 24 | { 25 | method: "POST", 26 | headers: { 27 | "Content-type": "application/json", 28 | }, 29 | body: JSON.stringify({ text }), 30 | } 31 | ); 32 | 33 | //real time data show 34 | const data = await res.json(); 35 | setTasks([...tasks, data]); 36 | }; 37 | 38 | return ( 39 |
addTaskHandler(e)} 42 | > 43 | setTast(e.target.value)} 46 | ref={inputRef} 47 | type="text" 48 | required 49 | name="" 50 | id="" 51 | className="bg-transparent outline-none text-xl border-b-2 border-teal-500 text-center" 52 | placeholder="what things to do" 53 | /> 54 | 60 |
61 | ); 62 | }; 63 | 64 | export default AddTask; 65 | -------------------------------------------------------------------------------- /src/components/TaskItem.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useState } from "react"; 3 | import { useContext } from "react"; 4 | import { BiEdit, BiTrashAlt } from "react-icons/bi"; 5 | import { DeleteContext, EditContext } from "../App"; 6 | 7 | const TaskItem = ({ task, handleEditeSubmit, editedText, setEditedText }) => { 8 | const handleDelete = useContext(DeleteContext); 9 | const handleEdit = useContext(EditContext); 10 | const [checked, setChecked] = useState(false); 11 | 12 | const handleCheckBox = () => { 13 | setChecked(!checked); 14 | }; 15 | 16 | return ( 17 |
18 |
19 | 20 | 28 | 29 | 30 | {task.isEditable && ( 31 |
handleEditeSubmit(e, task.id)}> 32 | setEditedText(e.target.value)} 39 | className="bg-transparent outline-none border-b-2 border-gray-400" 40 | /> 41 |
42 | )} 43 | 44 | {!task.isEditable && ( 45 |

50 | {task.text} 51 |

52 | )} 53 |
54 |
55 | 61 | 67 |
68 |
69 | ); 70 | }; 71 | 72 | export default TaskItem; 73 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import Header from "./components/Header"; 2 | import Footer from "./components/Footer"; 3 | import AddTask from "./components/AddTask"; 4 | import TaskList from "./components/TaskList"; 5 | import { useEffect, useState } from "react"; 6 | import { data } from "autoprefixer"; 7 | import { createContext } from "react"; 8 | 9 | export const DeleteContext = createContext(); 10 | export const EditContext = createContext(); 11 | 12 | const App = () => { 13 | const [tasks, setTasks] = useState([]); 14 | const [loading, setLoading] = useState(true); 15 | const [error, setError] = useState(""); 16 | 17 | const [editedText, setEditedText] = useState(""); 18 | const [toggleEditeMode, setToggleEditeMode] = useState(true); 19 | 20 | //getting data from the server 21 | useEffect(() => { 22 | fetchingData(); 23 | }, []); 24 | 25 | //fetching data from server 26 | const fetchingData = async () => { 27 | try { 28 | const res = await fetch( 29 | "https://dramatic-quintessential-deerstalker.glitch.me/tasks" 30 | ); 31 | if (!res.ok) throw new Error("somethign went wrong"); 32 | const data = await res.json(); 33 | setTasks(data); 34 | setLoading(false); 35 | } catch (error) { 36 | setError(error); 37 | } 38 | }; 39 | 40 | //deleting data 41 | const handleDelete = (id) => { 42 | deleteData(id); 43 | //set updated tasks 44 | setTasks(tasks.filter((task) => id !== task.id)); 45 | }; 46 | 47 | //delete data 48 | const deleteData = async (id) => { 49 | await fetch( 50 | `https://dramatic-quintessential-deerstalker.glitch.me/tasks/${id}`, 51 | { 52 | method: "DELETE", 53 | headers: { 54 | "content-type": "aplication/json", 55 | }, 56 | } 57 | ); 58 | }; 59 | 60 | //data editing 61 | const handleEdit = (id) => { 62 | const [editableTarget] = tasks.filter((task) => id === task.id); 63 | 64 | editableTarget.isEditable = true; 65 | setEditedText(editableTarget.text); 66 | 67 | setTasks([...tasks]); 68 | setToggleEditeMode(false); 69 | 70 | //re-arrange 71 | tasks 72 | .filter((task) => task.id !== id) 73 | .map((editableEl) => (editableEl.isEditable = false)); 74 | }; 75 | 76 | //editing task form handler 77 | const handleEditeSubmit = (e, id) => { 78 | e.preventDefault(); 79 | setToggleEditeMode(!toggleEditeMode); 80 | 81 | //update data 82 | const updateData = { 83 | text: editedText, 84 | id: id, 85 | }; 86 | 87 | //put request 88 | puttingRequest(id, updateData); 89 | 90 | //real time update 91 | const [editableTarget] = tasks.filter((task) => id === task.id); 92 | editableTarget.isEditable = false; 93 | editableTarget.text = updateData.text; 94 | }; 95 | 96 | const puttingRequest = async (id, newData) => { 97 | await fetch( 98 | `https://dramatic-quintessential-deerstalker.glitch.me/tasks/${id}`, 99 | { 100 | method: "PUT", 101 | headers: { 102 | "content-type": "application/json", 103 | }, 104 | body: JSON.stringify(newData), 105 | } 106 | ); 107 | }; 108 | 109 | return ( 110 |
111 | 112 | 113 |
114 | 115 | 123 |
127 | ); 128 | }; 129 | 130 | export default App; 131 | --------------------------------------------------------------------------------