From cae92748ebf923fc12ecb6e8cf43ef598d929344 Mon Sep 17 00:00:00 2001 From: Mohammad Date: Mon, 7 Nov 2022 21:42:00 +0330 Subject: [PATCH 1/5] add in-progress button to UnderBar --- src/App/TodoList/index.tsx | 17 +++++++++++++---- src/App/UnderBar/FilterLink/index.tsx | 15 ++++++++++++--- src/App/index.tsx | 3 ++- src/dataStructure.ts | 1 + 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/App/TodoList/index.tsx b/src/App/TodoList/index.tsx index 0f74c92f..0516773e 100644 --- a/src/App/TodoList/index.tsx +++ b/src/App/TodoList/index.tsx @@ -1,4 +1,4 @@ -import type { ReactElement } from 'react' +import { ReactElement, useEffect } from 'react' import React from 'react' import { useLocation } from 'react-router-dom' import { useRecoilState } from 'recoil' @@ -13,11 +13,20 @@ const TodoList: React.FC = () => { const { pathname } = useLocation() const [appState, setAppState] = useRecoilState(recoilState) - function toggleAllCheckbox(e: React.ChangeEvent): void { /* eslint-disable-line prettier/prettier */ + function toggleAllCheckbox(e: React.ChangeEvent): void { + /* eslint-disable-line prettier/prettier */ // reverse all todo.completed: boolean flag - setAppState({ todoList: appState.todoList.map((t: Todo): Todo => ({ ...t, completed: e.target.checked })) }) /* eslint-disable-line prettier/prettier */ + setAppState({ + todoList: appState.todoList.map( + (t: Todo): Todo => ({ ...t, completed: e.target.checked }) + ), + }) /* eslint-disable-line prettier/prettier */ } + useEffect(() => { + console.log('appState', appState) + }, [appState]) + return (
@@ -36,7 +45,7 @@ const TodoList: React.FC = () => { switch (pathname) { case '/': return true - case '/active': + case '/backlog': return t.completed === false case '/completed': return t.completed === true diff --git a/src/App/UnderBar/FilterLink/index.tsx b/src/App/UnderBar/FilterLink/index.tsx index 710c1e91..157222e0 100644 --- a/src/App/UnderBar/FilterLink/index.tsx +++ b/src/App/UnderBar/FilterLink/index.tsx @@ -17,10 +17,19 @@ const FilterLink: React.FC = () => {
  • - Active + Backlog + +
  • +
  • + + In progress
  • diff --git a/src/App/index.tsx b/src/App/index.tsx index 41e062ba..8dc59b6f 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -12,8 +12,9 @@ const App: React.FC = () => ( } /> - } /> + } /> } /> + } /> } /> diff --git a/src/dataStructure.ts b/src/dataStructure.ts index ae610c59..101997e3 100644 --- a/src/dataStructure.ts +++ b/src/dataStructure.ts @@ -7,6 +7,7 @@ export interface Todo { id: string bodyText: string completed: boolean + inProgress: boolean } export type TodoListType = Todo[] From f66dfc3cf53d6023a5194062add9fbb3b5e04182 Mon Sep 17 00:00:00 2001 From: Mohammad Date: Mon, 7 Nov 2022 22:44:18 +0330 Subject: [PATCH 2/5] add in-progress button in each item --- src/App/NewTodoInput/index.tsx | 5 ++++- src/App/TodoList/Item/index.tsx | 34 ++++++++++++++++++++++++++++++--- src/App/TodoList/Item/style.ts | 28 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/App/NewTodoInput/index.tsx b/src/App/NewTodoInput/index.tsx index ba877033..9e3e194a 100644 --- a/src/App/NewTodoInput/index.tsx +++ b/src/App/NewTodoInput/index.tsx @@ -19,11 +19,14 @@ const NewTodoTextInput: React.FC = () => { const todo: Todo = { bodyText: textInput.current.value, completed: false, + inProgress: false, id: UUID(), } // add new TODO to entire TodoList - setAppState({ todoList: [todo, ...appState.todoList] }) + setAppState({ + todoList: [todo, ...appState.todoList], + }) // reset text input UI value textInput.current.value = '' diff --git a/src/App/TodoList/Item/index.tsx b/src/App/TodoList/Item/index.tsx index 4ff6d6e7..0d94a8de 100644 --- a/src/App/TodoList/Item/index.tsx +++ b/src/App/TodoList/Item/index.tsx @@ -80,7 +80,19 @@ const Item: React.FC = ({ todo }) => { setAppState({ todoList: removed }) } - const handleTodoTextEdit = (e: React.ChangeEvent, onEdit: Todo['id']): void => { /* eslint-disable-line prettier/prettier */ + const setInprogress = (id: Todo['id']) => { + let temp: TodoListType = appState.todoList.map((t) => + t.inProgress ? { ...t, inProgress: false } : t + ) + temp = temp.map((t) => (t.id === id ? { ...t, inProgress: true } : t)) + setAppState({ todoList: temp }) + } + + const handleTodoTextEdit = ( + e: React.ChangeEvent, + onEdit: Todo['id'] + ): void => { + /* eslint-disable-line prettier/prettier */ const edited = appState.todoList.map((t: Todo): Todo => { if (t.id === onEdit) { return { ...t, bodyText: e.target.value } @@ -112,6 +124,7 @@ const Item: React.FC = ({ todo }) => { /> {/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */} + + {!todo.completed && todo.inProgress && ( + In Progress + )} + {!todo.completed && !todo.inProgress && ( + setInprogress(todo.id)} + > + In Progress + + )} {/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */}