├── .firebaserc ├── .gitignore ├── README.md ├── firebase.json ├── firestore.indexes.json ├── firestore.rules ├── jsconfig.json ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.jsx ├── App.scss ├── api.js ├── components │ ├── AppContent │ │ ├── index.jsx │ │ └── index.scss │ ├── AppDrawer │ │ └── index.jsx │ ├── TodoDetails │ │ ├── index.jsx │ │ └── index.scss │ ├── TodoForm │ │ ├── index.jsx │ │ └── index.scss │ ├── TodoList │ │ ├── index.jsx │ │ └── index.scss │ └── TodoListItem │ │ ├── index.jsx │ │ └── index.scss ├── contexts │ └── store.js ├── firebase.js ├── hooks │ └── store.js ├── index.js ├── index.scss ├── pages │ ├── Auth │ │ ├── index.jsx │ │ └── index.scss │ └── List │ │ ├── index.jsx │ │ └── index.scss └── store │ ├── Provider.jsx │ ├── actions.js │ ├── index.js │ ├── reducer.js │ ├── state.js │ └── utils.js └── storage.rules /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "react-todo-16181" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.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 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | 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. 35 | 36 | 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. 37 | 38 | 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. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "firestore": { 3 | "rules": "firestore.rules", 4 | "indexes": "firestore.indexes.json" 5 | }, 6 | "hosting": { 7 | "public": "public", 8 | "ignore": [ 9 | "firebase.json", 10 | "**/.*", 11 | "**/node_modules/**" 12 | ], 13 | "rewrites": [ 14 | { 15 | "source": "**", 16 | "destination": "/index.html" 17 | } 18 | ] 19 | }, 20 | "storage": { 21 | "rules": "storage.rules" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /firestore.indexes.json: -------------------------------------------------------------------------------- 1 | { 2 | "indexes": [], 3 | "fieldOverrides": [] 4 | } 5 | -------------------------------------------------------------------------------- /firestore.rules: -------------------------------------------------------------------------------- 1 | rules_version = '2'; 2 | service cloud.firestore { 3 | match /databases/{database}/documents { 4 | 5 | // This rule allows anyone on the internet to view, edit, and delete 6 | // all data in your Firestore database. It is useful for getting 7 | // started, but it is configured to expire after 30 days because it 8 | // leaves your app open to attackers. At that time, all client 9 | // requests to your Firestore database will be denied. 10 | // 11 | // Make sure to write security rules for your app before that time, or else 12 | // your app will lose access to your Firestore database 13 | match /{document=**} { 14 | allow read, write: if request.time < timestamp.date(2020, 5, 18); 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "src" 4 | }, 5 | "include": ["src"] 6 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-todo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "react-scripts start", 7 | "build": "react-scripts build", 8 | "test": "react-scripts test", 9 | "eject": "react-scripts eject", 10 | "deploy": "firebase deploy" 11 | }, 12 | "dependencies": { 13 | "@testing-library/jest-dom": "^4.2.4", 14 | "@testing-library/react": "^9.5.0", 15 | "@testing-library/user-event": "^7.2.1", 16 | "firebase": "^7.14.1", 17 | "mdc-react": "^0.14.6", 18 | "react": "^16.13.1", 19 | "react-dom": "^16.13.1", 20 | "react-router-dom": "^5.1.2", 21 | "react-scripts": "3.4.1" 22 | }, 23 | "devDependencies": { 24 | "sass": "^1.26.3" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codedojo/react-todo/1464eef0b60ac73d476bc2b25c373df85de91fa0/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | React App 18 | 19 | 20 | 21 |
22 | 23 | 24 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codedojo/react-todo/1464eef0b60ac73d476bc2b25c373df85de91fa0/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codedojo/react-todo/1464eef0b60ac73d476bc2b25c373df85de91fa0/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.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react'; 2 | import { Switch, Route } from 'react-router-dom'; 3 | 4 | import useStore from './hooks/store'; 5 | 6 | import AppDrawer from './components/AppDrawer'; 7 | import AppContent from './components/AppContent'; 8 | import ListPage from './pages/List'; 9 | import AuthPage from './pages/Auth'; 10 | 11 | import './App.scss'; 12 | 13 | export default function App() { 14 | const { state, actions } = useStore(); 15 | 16 | useEffect(() => { 17 | actions.initAuth(); 18 | actions.getLists(); 19 | }, []); 20 | 21 | if (!state.user) { 22 | return ( 23 | 24 | ); 25 | } else { 26 | return ( 27 |
28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
41 | ); 42 | } 43 | } -------------------------------------------------------------------------------- /src/App.scss: -------------------------------------------------------------------------------- 1 | .app { 2 | display: flex; 3 | flex-direction: row; 4 | width: 100%; 5 | 6 | #app-content { 7 | width: 100%; 8 | } 9 | } -------------------------------------------------------------------------------- /src/api.js: -------------------------------------------------------------------------------- 1 | import { db, auth } from './firebase'; 2 | 3 | /* Auth */ 4 | export function logInUser(email, password) { 5 | return auth.signInWithEmailAndPassword(email, password); 6 | } 7 | 8 | export function signOutUser() { 9 | return auth.signOut(); 10 | } 11 | 12 | export function registerUser(email, password) { 13 | return auth.createUserWithEmailAndPassword(email, password); 14 | } 15 | 16 | export function initAuth(onAuth) { 17 | auth.onAuthStateChanged(onAuth); 18 | } 19 | 20 | 21 | /* DB */ 22 | export function getLists() { 23 | return db.collection('lists') 24 | .get() 25 | .then(snapshot => { 26 | const items = snapshot.docs.map(doc => ({ 27 | id: doc.id, 28 | ...doc.data() 29 | })); 30 | 31 | return items; 32 | }); 33 | } 34 | 35 | export function getTodos() { 36 | return db.collection('todos') 37 | .where('listId', '==', '') 38 | .get() 39 | .then(snapshot => { 40 | const items = snapshot.docs.map(doc => ({ 41 | id: doc.id, 42 | ...doc.data() 43 | })); 44 | 45 | return items; 46 | }); 47 | } 48 | 49 | export function getListTodos(listId) { 50 | return db.collection('todos') 51 | .where('listId', '==', listId) 52 | .get() 53 | .then(snapshot => { 54 | const items = snapshot.docs.map(doc => ({ 55 | id: doc.id, 56 | ...doc.data() 57 | })); 58 | 59 | return items; 60 | }); 61 | } 62 | 63 | export function createTodo(data) { 64 | return db.collection('todos').add({ 65 | ...data, 66 | completed: false 67 | }) 68 | .then(docRef => docRef.get()) 69 | .then(doc => ({ 70 | id: doc.id, 71 | ...doc.data() 72 | })); 73 | } 74 | 75 | export function updateTodo(todoId, data) { 76 | return db.collection('todos').doc(todoId).update(data) 77 | .then(() => ({ 78 | id: todoId, 79 | ...data 80 | })); 81 | } 82 | 83 | export function deleteTodo(todoId) { 84 | return db.collection('todos').doc(todoId).delete() 85 | .then(() => todoId); 86 | } -------------------------------------------------------------------------------- /src/components/AppContent/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | 3 | import './index.scss'; 4 | 5 | export default function AppContent({ ...props }) { 6 | return ( 7 |
8 | ); 9 | } -------------------------------------------------------------------------------- /src/components/AppContent/index.scss: -------------------------------------------------------------------------------- 1 | #app-content { 2 | background-color: #f2f2f2; 3 | } -------------------------------------------------------------------------------- /src/components/AppDrawer/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { NavLink } from 'react-router-dom'; 3 | import { 4 | Drawer, DrawerHeader, DrawerContent, 5 | Icon, 6 | IconButton, 7 | Layout, 8 | List, ListItem, ListItemGraphic, ListItemText, ListItemMeta, 9 | ListDivider, 10 | ListGroup, 11 | Typography 12 | } from 'mdc-react'; 13 | 14 | import useStore from 'hooks/store'; 15 | 16 | export default function AppDrawer({ lists }) { 17 | const { state, actions } = useStore(); 18 | 19 | return ( 20 | 23 | 26 | 27 | {state.user.email} 28 | actions.signOutUser()} title="Выйти"> 29 | exit_to_app 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | {[ 38 | { title: 'Задачи', icon: 'home', to: '/', exact: true }, 39 | { title: 'Важно', icon: 'star', to: '/important' }, 40 | { title: 'Запланированные', icon: 'event', to: '/planned' }, 41 | ].map(item => 42 | 49 | 50 | {item.icon} 51 | 52 | 53 | 54 | {item.title} 55 | 56 | 57 | )} 58 | 59 | 60 | 61 | 62 | 63 | {lists.map(item => 64 | 70 | 71 | list 72 | 73 | 74 | 75 | {item.title} 76 | 77 | 78 | 79 | {item.todos.length} 80 | 81 | 82 | )} 83 | 84 | 85 | 86 | 87 | ); 88 | } -------------------------------------------------------------------------------- /src/components/TodoDetails/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Checkbox, 4 | Layout, 5 | List, ListItem, ListItemText, ListItemGraphic, 6 | TextField, 7 | Typography 8 | } from 'mdc-react'; 9 | 10 | import './index.scss'; 11 | 12 | export default function TodoDetails({ todo }) { 13 | return ( 14 | 43 | ); 44 | } -------------------------------------------------------------------------------- /src/components/TodoDetails/index.scss: -------------------------------------------------------------------------------- 1 | .todo-details { 2 | .todo-steps { 3 | margin: 1rem 0; 4 | 5 | .todo-step-list { 6 | .mdc-list-item { 7 | padding: 0; 8 | 9 | .mdc-checkbox { 10 | margin-right: .5rem; 11 | } 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/components/TodoForm/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { 3 | List, ListItem, 4 | TextField 5 | } from 'mdc-react'; 6 | 7 | import './index.scss'; 8 | 9 | export default function TodoForm({ onSubmit }) { 10 | const [title, setTitle] = useState(''); 11 | 12 | function handleSubmit(event) { 13 | event.preventDefault(); 14 | 15 | onSubmit(title); 16 | setTitle(''); 17 | } 18 | 19 | return ( 20 |
21 | 22 | 23 | 29 | 30 | 31 |
32 | ); 33 | } -------------------------------------------------------------------------------- /src/components/TodoForm/index.scss: -------------------------------------------------------------------------------- 1 | .todo-form { 2 | background-color: white; 3 | margin-top: 2px; 4 | 5 | .mdc-list { 6 | padding: 0; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/components/TodoList/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | List 4 | } from 'mdc-react'; 5 | 6 | import TodoListItem from '../TodoListItem'; 7 | 8 | import './index.scss'; 9 | 10 | export default function TodoList({ 11 | todos, 12 | onUpdate, 13 | onDelete, 14 | onSelect 15 | }) { 16 | return ( 17 | 18 | {todos.map(todo => 19 | 26 | )} 27 | 28 | ); 29 | } -------------------------------------------------------------------------------- /src/components/TodoList/index.scss: -------------------------------------------------------------------------------- 1 | .todo-list { 2 | .todo-list__title { 3 | margin-top: 1rem; 4 | margin-bottom: 1rem; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /src/components/TodoListItem/index.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | Checkbox, 4 | Icon, 5 | IconButton, 6 | ListItem, ListItemGraphic, ListItemText, ListItemMeta 7 | } from 'mdc-react'; 8 | 9 | import './index.scss'; 10 | 11 | export default function TodoListItem({ 12 | todo, 13 | onUpdate, 14 | onDelete, 15 | onSelect 16 | }) { 17 | function handleChange(completed) { 18 | onUpdate(todo.id, { completed }); 19 | } 20 | 21 | return ( 22 | 23 | 24 | 28 | 29 | 30 | onSelect(todo)}>{todo.title} 31 | 32 | 33 | onDelete(todo.id)}> 34 | delete 35 | 36 | 37 | 38 | ); 39 | } -------------------------------------------------------------------------------- /src/components/TodoListItem/index.scss: -------------------------------------------------------------------------------- 1 | .todo-list-item { 2 | background-color: white; 3 | margin-top: 2px; 4 | 5 | .mdc-list-item__graphic { 6 | width: 18px; 7 | height: 18px; 8 | margin-right: 1rem; 9 | } 10 | 11 | .mdc-list-item__text { 12 | flex: 1; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/contexts/store.js: -------------------------------------------------------------------------------- 1 | import { createContext } from 'react'; 2 | 3 | export default createContext(); -------------------------------------------------------------------------------- /src/firebase.js: -------------------------------------------------------------------------------- 1 | import firebase from 'firebase'; 2 | 3 | firebase.initializeApp({ 4 | apiKey: process.env.REACT_APP_FIREBASE_API_KEY, 5 | projectId: 'react-todo-16181', 6 | appId: '1:853702437056:web:356a2257476d5e5a7ea525', 7 | authDomain: 'react-todo-16181.firebaseapp.com', 8 | databaseURL: 'https://react-todo-16181.firebaseio.com', 9 | storageBucket: 'react-todo-16181.appspot.com', 10 | messagingSenderId: '853702437056' 11 | }); 12 | 13 | const db = firebase.firestore(); 14 | const auth = firebase.auth(); 15 | 16 | export { db, auth }; -------------------------------------------------------------------------------- /src/hooks/store.js: -------------------------------------------------------------------------------- 1 | import { useContext } from 'react'; 2 | 3 | import StoreContext from 'contexts/store'; 4 | 5 | export default function useStore() { 6 | const { state, actions } = useContext(StoreContext); 7 | 8 | return { 9 | state, 10 | actions 11 | }; 12 | } -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { BrowserRouter as Router } from 'react-router-dom'; 4 | 5 | import './index.scss'; 6 | 7 | import { Provider, initialState, reducer, actions } from './store'; 8 | import App from './App'; 9 | 10 | ReactDOM.render( 11 | 12 | 13 | 14 | 15 | , 16 | document.getElementById('root') 17 | ); -------------------------------------------------------------------------------- /src/index.scss: -------------------------------------------------------------------------------- 1 | @import '~mdc-react/dist/index.css'; 2 | 3 | * { 4 | box-sizing: content-box; 5 | } 6 | 7 | body { 8 | margin: 0; 9 | padding: 0; 10 | overflow: hidden; 11 | } 12 | 13 | #root { 14 | display: flex; 15 | min-height: 100vh; 16 | } -------------------------------------------------------------------------------- /src/pages/Auth/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { 3 | Button, 4 | Card, CardSection, CardActions, 5 | Layout, 6 | TextField, 7 | Typography 8 | } from 'mdc-react'; 9 | 10 | import useStore from 'hooks/store'; 11 | 12 | import './index.scss'; 13 | 14 | export default function AuthPage() { 15 | const { actions } = useStore(); 16 | const [email, setEmail] = useState(''); 17 | const [password, setPassword] = useState(''); 18 | const [error, setError] = useState(''); 19 | 20 | function handleLogInButtonClick() { 21 | if (email && password) { 22 | actions.logInUser(email, password) 23 | .catch(error => setError(error.message)); 24 | } 25 | } 26 | 27 | function handleRegisterButtonClick() { 28 | if (email && password) { 29 | actions.registerUser(email, password) 30 | .catch(error => setError(error.message)); 31 | } 32 | } 33 | 34 | return ( 35 | 36 | React Todo 37 | 38 | {error && 39 | {error} 40 | } 41 | 42 | 43 | 44 | 52 | 53 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | ); 70 | } -------------------------------------------------------------------------------- /src/pages/Auth/index.scss: -------------------------------------------------------------------------------- 1 | #login-page { 2 | margin: auto; 3 | } -------------------------------------------------------------------------------- /src/pages/List/index.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import { 3 | Icon, 4 | IconButton, 5 | Layout, 6 | SideSheet, 7 | Spinner, 8 | TopAppBar, 9 | Typography 10 | } from 'mdc-react'; 11 | 12 | import useStore from 'hooks/store'; 13 | 14 | import TodoList from 'components/TodoList'; 15 | import TodoForm from 'components/TodoForm'; 16 | import TodoDetails from 'components/TodoDetails'; 17 | 18 | import './index.scss'; 19 | 20 | export default function ListPage({ match }) { 21 | const { state, actions } = useStore(); 22 | const [selectedTodo, setSelectedTodo] = useState(null); 23 | 24 | useEffect(() => { 25 | setSelectedTodo(null); 26 | 27 | if (match.params.listId) { 28 | actions.getListTodos(match.params.listId); 29 | } else { 30 | actions.getTodos(); 31 | } 32 | }, [actions, match.params.listId]); 33 | 34 | function handleSubmit(title) { 35 | actions.createTodo({ 36 | title, 37 | listId: list.id 38 | }); 39 | } 40 | 41 | function handleDelete(todoId) { 42 | actions.deleteTodo(todoId); 43 | } 44 | 45 | function handleUpdate(todoId, data) { 46 | actions.updateTodo(todoId, data); 47 | } 48 | 49 | function handleSelect(todo) { 50 | setSelectedTodo(todo); 51 | } 52 | 53 | const list = state.lists.find(list => list.id === match.params.listId); 54 | 55 | if (!list || !state.todos) return ; 56 | 57 | return ( 58 | 59 | 62 | 63 | 64 | 69 | 70 | Детали задачи 71 | 72 | setSelectedTodo(null)}> 73 | close 74 | 75 | 76 | 77 | {selectedTodo && 78 | 81 | } 82 | 83 | 84 | 85 | 92 | 93 | 96 | 97 | 98 | 99 | ); 100 | } -------------------------------------------------------------------------------- /src/pages/List/index.scss: -------------------------------------------------------------------------------- 1 | #list-page { 2 | max-width: 100%; 3 | 4 | .mdc-layout { 5 | flex: 1; 6 | } 7 | 8 | .mdc-side-sheet { 9 | top: 64px; 10 | padding: 1rem; 11 | } 12 | 13 | .todo-list { 14 | margin: 1rem 1rem .25rem; 15 | } 16 | 17 | .todo-form { 18 | margin: .25rem 1rem 1rem; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/store/Provider.jsx: -------------------------------------------------------------------------------- 1 | import React, { useReducer, useMemo } from 'react'; 2 | 3 | import StoreContext from 'contexts/store'; 4 | import { bindActions } from './utils'; 5 | 6 | export default function Provider({ initialState, reducer, actions, children }) { 7 | const [state, dispatch] = useReducer(reducer, initialState); 8 | 9 | const memoizedActions = useMemo(() => bindActions(actions, dispatch), [dispatch, actions]); 10 | 11 | const memoizedStore = useMemo(() => ({ 12 | state, 13 | actions: memoizedActions 14 | }), [state, memoizedActions]); 15 | 16 | return ( 17 | 18 | {children} 19 | 20 | ); 21 | } -------------------------------------------------------------------------------- /src/store/actions.js: -------------------------------------------------------------------------------- 1 | import * as api from '../api'; 2 | 3 | /* Auth */ 4 | export function logInUser(email, password) { 5 | return api.logInUser(email, password).then(() => ({})); 6 | } 7 | 8 | export function signOutUser() { 9 | return api.signOutUser().then(() => ({})); 10 | } 11 | 12 | export function registerUser(email, password) { 13 | return api.registerUser(email, password).then(() => ({})); 14 | } 15 | 16 | export function initAuth() { 17 | return dispatch => api.initAuth(user => { 18 | return user ? dispatch({ 19 | type: 'LOGIN_USER', 20 | payload: { 21 | user 22 | } 23 | }) : dispatch({ 24 | type: 'LOGOUT_USER' 25 | }); 26 | }); 27 | } 28 | 29 | 30 | /* DB */ 31 | export function getLists() { 32 | return api.getLists() 33 | .then(lists => ({ 34 | type: 'GET_LISTS', 35 | payload: { 36 | lists 37 | } 38 | })); 39 | } 40 | 41 | export function getTodos() { 42 | return api.getTodos() 43 | .then(todos => ({ 44 | type: 'GET_TODOS', 45 | payload: { 46 | todos 47 | } 48 | })); 49 | } 50 | 51 | export function getListTodos(listId) { 52 | return api.getListTodos(listId) 53 | .then(todos => ({ 54 | type: 'GET_LIST_TODOS', 55 | payload: { 56 | todos 57 | } 58 | })); 59 | } 60 | 61 | export function createTodo(data) { 62 | return api.createTodo(data) 63 | .then(todo => ({ 64 | type: 'CREATE_TODO', 65 | payload: { 66 | todo 67 | } 68 | })); 69 | } 70 | 71 | export function updateTodo(todoId, data) { 72 | return api.updateTodo(todoId, data) 73 | .then(todo => ({ 74 | type: 'UPDATE_TODO', 75 | payload: { 76 | todo 77 | } 78 | })); 79 | } 80 | 81 | export function deleteTodo(todoId) { 82 | return api.deleteTodo(todoId) 83 | .then(todoId => ({ 84 | type: 'DELETE_TODO', 85 | payload: { 86 | todoId 87 | } 88 | })); 89 | } -------------------------------------------------------------------------------- /src/store/index.js: -------------------------------------------------------------------------------- 1 | import * as actions from './actions'; 2 | 3 | export { default as Provider } from './Provider'; 4 | export { default as reducer } from './reducer'; 5 | export { default as initialState } from './state'; 6 | export { actions }; -------------------------------------------------------------------------------- /src/store/reducer.js: -------------------------------------------------------------------------------- 1 | export default function reducer(state, action) { 2 | switch (action.type) { 3 | case 'LOGIN_USER': 4 | return { 5 | ...state, 6 | user: action.payload.user 7 | }; 8 | 9 | case 'LOGOUT_USER': 10 | return { 11 | ...state, 12 | user: null 13 | }; 14 | 15 | case 'GET_LISTS': 16 | return { 17 | ...state, 18 | lists: action.payload.lists 19 | }; 20 | 21 | case 'GET_TODOS': 22 | return { 23 | ...state, 24 | todos: action.payload.todos 25 | }; 26 | 27 | case 'GET_LIST_TODOS': 28 | return { 29 | ...state, 30 | todos: action.payload.todos 31 | } 32 | 33 | case 'CREATE_TODO': 34 | return { 35 | ...state, 36 | todos: state.todos.push(action.payload.todo) 37 | } 38 | 39 | case 'UPDATE_TODO': 40 | return { 41 | ...state, 42 | todos: state.todos.map(todo => { 43 | if (todo.id === action.payload.todo.id) { 44 | return { 45 | ...todo, 46 | ...action.payload.todo 47 | } 48 | } 49 | 50 | return todo 51 | }) 52 | } 53 | 54 | case 'DELETE_TODO': 55 | return { 56 | ...state, 57 | todos: state.todos.filter(todo => todo !== action.payload.todoId) 58 | } 59 | 60 | default: 61 | return state; 62 | } 63 | } -------------------------------------------------------------------------------- /src/store/state.js: -------------------------------------------------------------------------------- 1 | export default { 2 | user: null, 3 | lists: [], 4 | todos: [] 5 | }; -------------------------------------------------------------------------------- /src/store/utils.js: -------------------------------------------------------------------------------- 1 | export function bindActions(actions, dispatch) { 2 | return Object.entries(actions).reduce((result, [key, fn]) => { 3 | result[key] = (...args) => { 4 | const action = fn(...args); 5 | 6 | if (typeof action.then === 'function') { 7 | action.then(dispatch); 8 | } else if (typeof action === 'function') { 9 | action(dispatch); 10 | } else if (action.type) { 11 | dispatch(action); 12 | } 13 | 14 | return action; 15 | }; 16 | 17 | return result; 18 | }, {}); 19 | } 20 | 21 | export function combineReducers(reducers) { 22 | return function(state, action) { 23 | return Object.entries(reducers).reduce((newState, [key, reducer]) => { 24 | newState[key] = reducer(state[key], action); 25 | 26 | return newState; 27 | }, {}); 28 | }; 29 | } -------------------------------------------------------------------------------- /storage.rules: -------------------------------------------------------------------------------- 1 | service firebase.storage { 2 | match /b/{bucket}/o { 3 | match /{allPaths=**} { 4 | allow read, write: if request.auth!=null; 5 | } 6 | } 7 | } 8 | --------------------------------------------------------------------------------