├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.tsx ├── components │ ├── ColumnLayout.tsx │ └── columns │ │ ├── Done.tsx │ │ ├── InProgress.tsx │ │ └── ToDo.tsx ├── index.tsx ├── react-app-env.d.ts ├── redux │ ├── slice │ │ ├── customSlice.ts │ │ ├── done.ts │ │ ├── inProgress.ts │ │ └── todo.ts │ └── store │ │ └── index.ts └── types │ └── index.ts └── tsconfig.json /.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 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "editor.defaultFormatter": "esbenp.prettier-vscode", 4 | "typescript.tsdk": "node_modules\\typescript\\lib", 5 | "files.insertFinalNewline": true, 6 | "files.eol": "\n", 7 | "editor.tabSize": 2, 8 | "[typescriptreact]": { 9 | "editor.defaultFormatter": "esbenp.prettier-vscode" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Piotr Glejzer 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app), using the [Redux](https://redux.js.org/) and [Redux Toolkit](https://redux-toolkit.js.org/) template. 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-todo-list-redux", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.7.1", 7 | "@emotion/styled": "^11.6.0", 8 | "@mui/icons-material": "^5.3.1", 9 | "@mui/material": "^5.4.0", 10 | "@reduxjs/toolkit": "^1.7.1", 11 | "@testing-library/jest-dom": "^4.2.4", 12 | "@testing-library/react": "^9.5.0", 13 | "@testing-library/user-event": "^7.2.1", 14 | "@types/jest": "^24.9.1", 15 | "@types/node": "^12.20.43", 16 | "@types/react": "^16.14.22", 17 | "@types/react-dom": "^16.9.14", 18 | "@types/react-redux": "^7.1.22", 19 | "react": "^17.0.2", 20 | "react-beautiful-dnd": "^13.1.0", 21 | "react-dom": "^17.0.2", 22 | "react-redux": "^7.2.6", 23 | "react-scripts": "5.0.0", 24 | "typescript": "^4.1.6", 25 | "uuid": "^8.3.2" 26 | }, 27 | "scripts": { 28 | "start": "react-scripts start", 29 | "build": "react-scripts build", 30 | "test": "react-scripts test", 31 | "eject": "react-scripts eject" 32 | }, 33 | "eslintConfig": { 34 | "extends": "react-app" 35 | }, 36 | "browserslist": { 37 | "production": [ 38 | ">0.2%", 39 | "not dead", 40 | "not op_mini all" 41 | ], 42 | "development": [ 43 | "last 1 chrome version", 44 | "last 1 firefox version", 45 | "last 1 safari version" 46 | ] 47 | }, 48 | "devDependencies": { 49 | "@types/react-beautiful-dnd": "^13.1.2", 50 | "@types/uuid": "^8.3.4", 51 | "add": "^2.0.6" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enespolat25/react-todo-list-redux/fdb008dfdb9b2a92a5adbbb81dd4287726072547/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React Redux App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enespolat25/react-todo-list-redux/fdb008dfdb9b2a92a5adbbb81dd4287726072547/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/enespolat25/react-todo-list-redux/fdb008dfdb9b2a92a5adbbb81dd4287726072547/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.tsx: -------------------------------------------------------------------------------- 1 | import Container from '@mui/material/Container'; 2 | import Grid from '@mui/material/Grid'; 3 | import Typography from '@mui/material/Typography'; 4 | import { DragDropContext, DropResult } from 'react-beautiful-dnd'; 5 | import { useDispatch, useSelector } from 'react-redux'; 6 | import { ToDoColumn } from './components/columns/ToDo'; 7 | import { DoneColumn } from './components/columns/Done'; 8 | import { InProgressColumn } from './components/columns/InProgress'; 9 | import { todoSlice as todo } from './redux/slice/todo'; 10 | import { inProgressSlice as inProgress } from './redux/slice/inProgress'; 11 | import { doneSlice as done } from './redux/slice/done'; 12 | import { StoreState } from './redux/store'; 13 | import { IModel } from './types'; 14 | 15 | type TAllSilces = 'todo' | 'inProgress' | 'done'; 16 | 17 | function App() { 18 | const dispatch = useDispatch(); 19 | const appState = useSelector((state: StoreState) => state); 20 | 21 | const onDragEnd = (result: DropResult) => { 22 | if (!result.destination) { 23 | return; 24 | } 25 | 26 | const { destination, source, draggableId } = result; 27 | const allSlices = { todo, inProgress, done }; 28 | 29 | if (destination.droppableId === source.droppableId) { 30 | dispatch( 31 | allSlices[destination.droppableId as TAllSilces].actions.reorder(result) 32 | ); 33 | } else { 34 | const [filterState] = ( 35 | (appState as any)[source.droppableId] as IModel[] 36 | ).filter(({ id }) => id === draggableId); 37 | 38 | dispatch( 39 | allSlices[source.droppableId as TAllSilces].actions.remove(draggableId) 40 | ); 41 | dispatch( 42 | allSlices[destination.droppableId as TAllSilces].actions.update({ 43 | ...result, 44 | filterState, 45 | }) 46 | ); 47 | } 48 | }; 49 | 50 | return ( 51 | 52 | 53 | This is a ToDo APP with Redux 54 | {' '} 55 | 56 | onDragEnd(res)}> 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | ); 70 | } 71 | 72 | export default App; 73 | -------------------------------------------------------------------------------- /src/components/ColumnLayout.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import Button from '@mui/material/Button'; 3 | import TextField from '@mui/material/TextField'; 4 | import Box from '@mui/material/Box'; 5 | import List from '@mui/material/List'; 6 | import ListItem from '@mui/material/ListItem'; 7 | import ListItemText from '@mui/material/ListItemText'; 8 | import Checkbox from '@mui/material/Checkbox'; 9 | import IconButton from '@mui/material/IconButton'; 10 | import DeleteIcon from '@mui/icons-material/Delete'; 11 | import Alert from '@mui/material/Alert'; 12 | import Collapse from '@mui/material/Collapse'; 13 | import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward'; 14 | import { useDispatch } from 'react-redux'; 15 | import { Droppable, Draggable } from 'react-beautiful-dnd'; 16 | import { StoreDispatch } from '../redux/store'; 17 | import { IColumnLayoutProps } from '../types'; 18 | 19 | const ColumnLayout: React.FC = ({ 20 | labelText, 21 | addHandler, 22 | removeHandler, 23 | completedHandler, 24 | selectorState, 25 | droppableId, 26 | updateTextShowed, 27 | }) => { 28 | const [isError, setIsError] = useState({ 29 | isShow: false, 30 | text: '', 31 | }); 32 | 33 | const [textDescription, setTextDescription] = useState(''); 34 | const dispatch = useDispatch(); 35 | 36 | const handleOnChange = ({ 37 | target: { value }, 38 | }: React.ChangeEvent) => { 39 | setTextDescription(value); 40 | 41 | setIsError({ 42 | isShow: value.length > 200, 43 | text: 44 | value.length > 200 45 | ? 'The input value cannot be more than 200 characters' 46 | : '', 47 | }); 48 | }; 49 | 50 | const handleOnBlur = () => { 51 | setIsError({ ...isError, isShow: false }); 52 | }; 53 | 54 | const handleOnClick = () => { 55 | if (!isError.isShow) { 56 | dispatch(addHandler(textDescription)); 57 | setTextDescription(''); 58 | } 59 | }; 60 | 61 | const handleInputKeyDown = ({ 62 | target, 63 | key, 64 | }: React.KeyboardEvent) => { 65 | if (key === 'Enter') { 66 | if ( 67 | (target as HTMLInputElement).value.length > 0 && 68 | (target as HTMLInputElement).value.length <= 200 69 | ) { 70 | handleOnClick(); 71 | } else { 72 | setIsError({ 73 | isShow: true, 74 | text: 'The input value cannot be empty', 75 | }); 76 | } 77 | } 78 | }; 79 | 80 | return ( 81 | 82 | 92 | 93 | 94 | 95 | {isError.text} 96 | 97 | 98 | 99 | 100 | 114 | 115 | 116 | {(provided) => ( 117 | 130 | {selectorState.map( 131 | ( 132 | { id, text, isFinished, createdAt, updatedAt, isTextShowed }, 133 | index: number 134 | ) => ( 135 | 136 | {(provided, snapshot) => ( 137 | 155 | 161 | 164 | dispatch( 165 | updateTextShowed({ 166 | id, 167 | isTextShowed: !isTextShowed, 168 | }) 169 | ) 170 | } 171 | > 172 | 178 | 179 | 180 | 187 | {updatedAt ? 'Updated' : 'Created'} at:{' '} 188 | {updatedAt || createdAt} 189 | 190 | 191 | 192 | {text} 193 | 194 | 195 | 196 | dispatch(removeHandler(id))} 198 | > 199 | 204 | 205 | 211 | dispatch( 212 | completedHandler({ 213 | isFinished: !isFinished, 214 | id, 215 | updatedAt: new Date().toLocaleString(), 216 | }) 217 | ) 218 | } 219 | /> 220 | 221 | 222 | 223 | You can add here some content{' '} 224 | 225 | 😍 226 | 227 | 228 | 229 | )} 230 | 231 | ) 232 | )} 233 | {provided.placeholder} 234 | 235 | )} 236 | 237 | 238 | ); 239 | }; 240 | 241 | export default ColumnLayout; 242 | -------------------------------------------------------------------------------- /src/components/columns/Done.tsx: -------------------------------------------------------------------------------- 1 | import Typography from '@mui/material/Typography'; 2 | import { useSelector } from 'react-redux'; 3 | import { StoreState } from '../../redux/store'; 4 | import { doneSlice } from '../../redux/slice/done'; 5 | import ColumnLayout from '../ColumnLayout'; 6 | 7 | export function DoneColumn() { 8 | const { done } = useSelector((state: StoreState) => state); 9 | const { 10 | actions: { completeStatus, remove, add, updateTextShowed }, 11 | } = doneSlice; 12 | 13 | return ( 14 | <> 15 | All done tasks: {done.length} 16 | 25 | 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /src/components/columns/InProgress.tsx: -------------------------------------------------------------------------------- 1 | import Typography from '@mui/material/Typography'; 2 | import { useSelector } from 'react-redux'; 3 | import { StoreState } from '../../redux/store'; 4 | import { inProgressSlice } from '../../redux/slice/inProgress'; 5 | import ColumnLayout from '../ColumnLayout'; 6 | 7 | export function InProgressColumn() { 8 | const { inProgress } = useSelector((state: StoreState) => state); 9 | 10 | const { 11 | actions: { completeStatus, remove, add, updateTextShowed }, 12 | } = inProgressSlice; 13 | 14 | return ( 15 | <> 16 | All inProgress tasks: {inProgress.length} 17 | 26 | 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /src/components/columns/ToDo.tsx: -------------------------------------------------------------------------------- 1 | import Typography from '@mui/material/Typography'; 2 | import { useSelector } from 'react-redux'; 3 | import { StoreState } from '../../redux/store'; 4 | import { todoSlice } from '../../redux/slice/todo'; 5 | import ColumnLayout from '../ColumnLayout'; 6 | 7 | export function ToDoColumn() { 8 | const { todo } = useSelector((state: StoreState) => state); 9 | const { 10 | actions: { completeStatus, remove, add, updateTextShowed }, 11 | } = todoSlice; 12 | 13 | return ( 14 | <> 15 | All todo tasks: {todo.length} 16 | 25 | 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { Provider } from 'react-redux'; 4 | import CssBaseline from '@mui/material/CssBaseline'; 5 | import App from './App'; 6 | import { store } from './redux/store'; 7 | 8 | ReactDOM.render( 9 | 10 | 11 | 12 | 13 | 14 | , 15 | document.getElementById('root') 16 | ); 17 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /src/redux/slice/customSlice.ts: -------------------------------------------------------------------------------- 1 | import { createSlice, PayloadAction } from '@reduxjs/toolkit'; 2 | import { v4 as uuidv4 } from 'uuid'; 3 | import { TActionSlice, TUpdateTextShowed, IModel } from '../../types'; 4 | 5 | const initialState: IModel[] = []; 6 | 7 | export const createCustomSlice = (name: string) => { 8 | const { 9 | actions: { add, remove, completeStatus, reorder, update, updateTextShowed }, 10 | reducer, 11 | } = createSlice({ 12 | name, 13 | initialState, 14 | reducers: { 15 | add: { 16 | reducer: (state, action: PayloadAction) => { 17 | state.push(action.payload); 18 | }, 19 | prepare: (text: string) => ({ 20 | payload: { 21 | id: uuidv4(), 22 | text, 23 | isFinished: false, 24 | createdAt: new Date().toLocaleString(), 25 | isTextShowed: false, 26 | } as IModel, 27 | }), 28 | }, 29 | update(state, action) { 30 | state.splice( 31 | action.payload.destination.index, 32 | 0, 33 | action.payload.filterState 34 | ); 35 | }, 36 | remove(state, action: PayloadAction) { 37 | const index = state.findIndex(({ id }) => id === action.payload); 38 | state.splice(index, 1); 39 | }, 40 | completeStatus(state, action: PayloadAction) { 41 | const index = state.findIndex(({ id }) => id === action.payload.id); 42 | state[index].isFinished = action.payload.isFinished; 43 | state[index].updatedAt = action.payload.updatedAt; 44 | }, 45 | updateTextShowed(state, action: PayloadAction) { 46 | const index = state.findIndex(({ id }) => id === action.payload.id); 47 | state[index].isTextShowed = action.payload.isTextShowed; 48 | }, 49 | reorder(state, action) { 50 | const [removed] = state.splice(action.payload.source.index, 1); 51 | state.splice(action.payload.destination.index, 0, removed); 52 | }, 53 | }, 54 | }); 55 | 56 | return { 57 | actions: { add, remove, completeStatus, reorder, update, updateTextShowed }, 58 | reducer, 59 | }; 60 | }; 61 | -------------------------------------------------------------------------------- /src/redux/slice/done.ts: -------------------------------------------------------------------------------- 1 | import { createCustomSlice } from './customSlice'; 2 | 3 | export const doneSlice = createCustomSlice('done'); 4 | -------------------------------------------------------------------------------- /src/redux/slice/inProgress.ts: -------------------------------------------------------------------------------- 1 | import { createCustomSlice } from './customSlice'; 2 | 3 | export const inProgressSlice = createCustomSlice('progress'); 4 | -------------------------------------------------------------------------------- /src/redux/slice/todo.ts: -------------------------------------------------------------------------------- 1 | import { createCustomSlice } from './customSlice'; 2 | 3 | export const todoSlice = createCustomSlice('todo'); 4 | -------------------------------------------------------------------------------- /src/redux/store/index.ts: -------------------------------------------------------------------------------- 1 | import { configureStore, combineReducers } from '@reduxjs/toolkit'; 2 | import { doneSlice } from '../slice/done'; 3 | import { inProgressSlice } from '../slice/inProgress'; 4 | import { todoSlice } from '../slice/todo'; 5 | 6 | export const store = configureStore({ 7 | reducer: combineReducers({ 8 | done: doneSlice.reducer, 9 | inProgress: inProgressSlice.reducer, 10 | todo: todoSlice.reducer, 11 | }), 12 | }); 13 | 14 | export type StoreDispatch = typeof store.dispatch; 15 | export type StoreState = ReturnType; 16 | -------------------------------------------------------------------------------- /src/types/index.ts: -------------------------------------------------------------------------------- 1 | import { AnyAction } from '@reduxjs/toolkit'; 2 | 3 | export interface IModel { 4 | id: string; 5 | text: string; 6 | isFinished: boolean; 7 | createdAt?: string; 8 | updatedAt?: string; 9 | isTextShowed?: boolean; 10 | } 11 | 12 | export type TActionSlice = Omit; 13 | export type TUpdateTextShowed = Omit; 14 | 15 | export interface IColumnLayoutProps { 16 | labelText?: string; 17 | addHandler: (v: string) => AnyAction; 18 | removeHandler: (v: string) => AnyAction; 19 | completedHandler: (v: TActionSlice) => AnyAction; 20 | selectorState: IModel[]; 21 | droppableId: string; 22 | updateTextShowed: (v: TUpdateTextShowed) => AnyAction; 23 | } 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | --------------------------------------------------------------------------------