├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt └── src ├── App.js ├── Loader.js ├── Todo ├── AddTodo.js ├── Todo.css ├── TodoItem.js └── TodoList.js ├── context.js ├── index.css ├── index.js ├── reportWebVitals.js └── setupTests.js /.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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # reactjs-tutorial -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.9", 7 | "@testing-library/react": "^11.2.5", 8 | "@testing-library/user-event": "^12.8.3", 9 | "prop-types": "^15.7.2", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-scripts": "4.0.3", 13 | "web-vitals": "^1.1.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammibadriddinov/reactjs-tutorial/55cacbc1b808dd8be716e9a1134301e72a7db371/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | React Tutorial 19 | 20 | 21 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammibadriddinov/reactjs-tutorial/55cacbc1b808dd8be716e9a1134301e72a7db371/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sammibadriddinov/reactjs-tutorial/55cacbc1b808dd8be716e9a1134301e72a7db371/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.js: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from "react"; 2 | import TodoList from "./Todo/TodoList"; 3 | import Context from "./context"; 4 | import AddTodo from "./Todo/AddTodo"; 5 | import Loader from "./Loader"; 6 | 7 | function App() { 8 | const [todos, setTodos] = React.useState([]); 9 | const [loading, setLoading] = React.useState(true); 10 | 11 | useEffect(() => { 12 | fetch("https://jsonplaceholder.typicode.com/todos?_limit=5") 13 | .then((response) => response.json()) 14 | .then((todos) => { 15 | setTimeout(() => { 16 | setTodos(todos); 17 | setLoading(false); 18 | }, 2000); 19 | }); 20 | }, []); 21 | 22 | function toggleTodo(id) { 23 | setTodos( 24 | todos.map((todo) => { 25 | if (todo.id === id) { 26 | todo.completed = !todo.completed; 27 | } 28 | return todo; 29 | }) 30 | ); 31 | } 32 | function removeTodo(id) { 33 | setTodos(todos.filter((todo) => todo.id !== id)); 34 | } 35 | function addTodo(title) { 36 | setTodos( 37 | todos.concat({ 38 | title, 39 | id: Date.now(), 40 | completed: false, 41 | }) 42 | ); 43 | } 44 | return ( 45 | 46 |
47 |

React Tutorial

48 | 49 | {loading && } 50 | {todos.length ? ( 51 | 52 | ) : loading ? null : ( 53 |

Нету заметок

54 | )} 55 |
56 |
57 | ); 58 | } 59 | 60 | export default App; 61 | -------------------------------------------------------------------------------- /src/Loader.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | export default () => ( 4 |
5 |
6 |
7 | ); 8 | -------------------------------------------------------------------------------- /src/Todo/AddTodo.js: -------------------------------------------------------------------------------- 1 | import React, { useState } from "react"; 2 | import PropTypes from "prop-types"; 3 | 4 | function useInputValue(defaultValue = "") { 5 | const [value, setValue] = useState(defaultValue); 6 | 7 | return { 8 | bind: { 9 | value, 10 | onChange: (event) => setValue(event.target.value), 11 | }, 12 | clear: () => setValue(""), 13 | value: () => value, 14 | }; 15 | } 16 | 17 | function AddTodo({ onCreate }) { 18 | const input = useInputValue(""); 19 | function submitHandler(event) { 20 | event.preventDefault(); 21 | 22 | if (input.value().trim()) { 23 | onCreate(input.value()); 24 | input.clear(); 25 | } 26 | } 27 | return ( 28 |
29 | 30 | 31 |
32 | ); 33 | } 34 | 35 | AddTodo.propTypes = { 36 | onCreate: PropTypes.func.isRequired, 37 | }; 38 | 39 | export default AddTodo; 40 | -------------------------------------------------------------------------------- /src/Todo/Todo.css: -------------------------------------------------------------------------------- 1 | .li-item { 2 | display: flex; 3 | justify-content: space-between; 4 | align-items: center; 5 | padding: 8px 16px; 6 | border: 1px solid #eee; 7 | border-radius: 5px; 8 | margin-bottom: 10px; 9 | } 10 | .input { 11 | margin-right: 0.5rem; 12 | } 13 | .done { 14 | text-decoration: line-through; 15 | } 16 | .btn { 17 | padding: 3px 10px; 18 | background: crimson; 19 | outline: none; 20 | border-radius: 5px; 21 | border: none; 22 | cursor: pointer; 23 | transition: opacity 0.5s ease; 24 | } 25 | .btn:hover { 26 | opacity: 0.8; 27 | } 28 | -------------------------------------------------------------------------------- /src/Todo/TodoItem.js: -------------------------------------------------------------------------------- 1 | import React, { useContext } from "react"; 2 | import PropTypes from "prop-types"; 3 | import Context from "../context"; 4 | import "./Todo.css"; 5 | 6 | function TodoItem({ todo, index, onChange }) { 7 | const { removeTodo } = useContext(Context); 8 | const classes = []; 9 | 10 | if (todo.completed) { 11 | classes.push("done"); 12 | } 13 | 14 | return ( 15 |
  • 16 | 17 | onChange(todo.id)} 21 | className="input" 22 | />{" "} 23 |   24 | {index + 1}   25 | {todo.title} 26 | 27 | 30 |
  • 31 | ); 32 | } 33 | 34 | TodoItem.propTypes = { 35 | todo: PropTypes.object.isRequired, 36 | index: PropTypes.number, 37 | }; 38 | 39 | export default TodoItem; 40 | -------------------------------------------------------------------------------- /src/Todo/TodoList.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import TodoItem from "./TodoItem"; 3 | import PropTypes from "prop-types"; 4 | 5 | function TodoList(props) { 6 | const styles = { 7 | ul: { 8 | listStyle: "none", 9 | padding: 0, 10 | }, 11 | }; 12 | return ( 13 | 25 | ); 26 | } 27 | 28 | TodoList.propTypes = { 29 | todos: PropTypes.arrayOf(PropTypes.object).isRequired, 30 | onToggle: PropTypes.func.isRequired, 31 | }; 32 | 33 | export default TodoList; 34 | -------------------------------------------------------------------------------- /src/context.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | const Context = React.createContext(); 4 | 5 | export default Context; 6 | -------------------------------------------------------------------------------- /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 | 15 | .wrapper { 16 | width: 80%; 17 | margin: 0 auto; 18 | padding-top: 100px; 19 | } 20 | .lds-dual-ring { 21 | display: inline-block; 22 | width: 80px; 23 | height: 80px; 24 | } 25 | .lds-dual-ring:after { 26 | content: " "; 27 | display: block; 28 | width: 64px; 29 | height: 64px; 30 | margin: 8px; 31 | border-radius: 50%; 32 | border: 6px solid blue; 33 | border-color: blue transparent blue transparent; 34 | animation: lds-dual-ring 1.2s linear infinite; 35 | } 36 | @keyframes lds-dual-ring { 37 | 0% { 38 | transform: rotate(0deg); 39 | } 40 | 100% { 41 | transform: rotate(360deg); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /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(, document.getElementById("root")); 8 | 9 | reportWebVitals(); 10 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------