diff --git a/README.md b/README.md index 02aac3f..a264358 100644 --- a/README.md +++ b/README.md @@ -1,70 +1,3 @@ -# Getting Started with Create React App +# Todo list -This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). - -## Available Scripts - -In the project directory, you can run: - -### `yarn start` - -Runs the app in the development mode.\ -Open [http://localhost:3000](http://localhost:3000) to view it in the browser. - -The page will reload if you make edits.\ -You will also see any lint errors in the console. - -### `yarn test` - -Launches the test runner in the interactive watch mode.\ -See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. - -### `yarn build` - -Builds the app for production to the `build` folder.\ -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.\ -Your app is ready to be deployed! - -See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. - -### `yarn 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](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](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](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](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](https://facebook.github.io/create-react-app/docs/deployment) - -### `yarn build` fails to minify - -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) +React intro diff --git a/public/index.html b/public/index.html index aa069f2..6ef8277 100644 --- a/public/index.html +++ b/public/index.html @@ -5,6 +5,7 @@ + - React App + Checklist diff --git a/src/App.css b/src/App.css deleted file mode 100644 index 74b5e05..0000000 --- a/src/App.css +++ /dev/null @@ -1,38 +0,0 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; -} - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} diff --git a/src/App.js b/src/App.js deleted file mode 100644 index 3784575..0000000 --- a/src/App.js +++ /dev/null @@ -1,25 +0,0 @@ -import logo from './logo.svg'; -import './App.css'; - -function App() { - return ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); -} - -export default App; diff --git a/src/App.test.js b/src/App.test.js deleted file mode 100644 index 1f03afe..0000000 --- a/src/App.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import { render, screen } from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - render(); - const linkElement = screen.getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -}); diff --git a/src/RESET_ACTION.js b/src/RESET_ACTION.js new file mode 100644 index 0000000..3b9afa7 --- /dev/null +++ b/src/RESET_ACTION.js @@ -0,0 +1,5 @@ +const RESET_ACTION = { + type: "RESET", +}; + +export default RESET_ACTION; diff --git a/src/addtask.js b/src/addtask.js new file mode 100644 index 0000000..9b074a8 --- /dev/null +++ b/src/addtask.js @@ -0,0 +1,105 @@ +import React, { useReducer, useState } from "react"; +import RESET_ACTION from "./RESET_ACTION"; + +export function AddTask(props) { + const [showForm, setShowForm] = useState(false); + const toggleForm = () => setShowForm(!showForm); + + return ( + <> +
+ +
+ + + ); +} + +function AddTaskForm(props) { + const { addTask, show, toggleForm } = props; + + const INITIAL_STATE = { name: "", description: "", date: "" }; + const reducer = (state, event) => { + if (event.type === RESET_ACTION.type) { + return INITIAL_STATE; + } else { + return { ...state, [event.target.name]: event.target.value }; + } + }; + const [task, setTask] = useReducer(reducer, INITIAL_STATE); + + if (!show) { + return <>; + } + + const handleSubmit = (event) => { + console.log(task); + addTask(task); + setTask(RESET_ACTION); + event.preventDefault(); + }; + + const cancelForm = () => { + setTask(RESET_ACTION); + toggleForm(); + }; + + return ( + <> +
+
+ + + + + + + + +
+
+ + +
+
+ + ); +} + +export default AddTask; diff --git a/src/index.css b/src/index.css index ec2585e..e69de29 100644 --- a/src/index.css +++ b/src/index.css @@ -1,13 +0,0 @@ -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; -} diff --git a/src/index.html b/src/index.html new file mode 100644 index 0000000..4ae99d3 --- /dev/null +++ b/src/index.html @@ -0,0 +1,12 @@ + + + + + + + + + +
+ + \ No newline at end of file diff --git a/src/index.js b/src/index.js index ef2edf8..e912600 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,44 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import './index.css'; -import App from './App'; -import reportWebVitals from './reportWebVitals'; +import React, { useState } from "react"; +import ReactDom from "react-dom"; +import AddTask from "./addtask"; +import { Task, TaskList } from "./tasklist"; -ReactDOM.render( - - - , - document.getElementById('root') -); +// Example task +// { name: "example task", description: "Amogus sus" }; -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); +function Root() { + const [taskNumber, setTaskNumber] = useState(0); + const [tasks, setTasks] = useState([]); + + const addNewTask = (props) => { + setTasks((tasks) => [ + ...tasks, + , + ]); + setTaskNumber((taskNumber) => taskNumber + 1); + }; + + const deleteTask = (id) => { + setTasks((tasks) => tasks.filter((task) => task.props.taskId !== id)); + }; + + return ( +
+
+

Task list

+
+
+ +

Tasks

+ +
+
+ ); +} + +ReactDom.render(, document.getElementById("root")); diff --git a/src/logo.svg b/src/logo.svg deleted file mode 100644 index 9dfc1c0..0000000 --- a/src/logo.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/src/reportWebVitals.js b/src/reportWebVitals.js deleted file mode 100644 index 5253d3a..0000000 --- a/src/reportWebVitals.js +++ /dev/null @@ -1,13 +0,0 @@ -const reportWebVitals = onPerfEntry => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 8f2609b..0000000 --- a/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// 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'; diff --git a/src/tasklist.js b/src/tasklist.js new file mode 100644 index 0000000..c0df388 --- /dev/null +++ b/src/tasklist.js @@ -0,0 +1,68 @@ +import { useState } from "react"; + +export function TaskList(props) { + const { tasks } = props; + return ( + + + + + + + + + + + {tasks} +
+ Done + NameDescription + Due date +
+ ); +} + +export function Task(props) { + const { taskId, name, description, date, deleteTask } = props; + const [done, setDone] = useState(false); + + const deleteBtn = (done) => { + if (done) { + return ( + + deleteTask(taskId)} + /> + + ); + } + return <>; + }; + + return ( + + + setDone(!done)} + > + + +

{name}

+ + +

{description}

+ + + {date === "" + ? "" + : new Date(Date.parse(date)).toLocaleDateString()} + + {deleteBtn(done)} + + ); +}