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..59f3f876 100644 --- a/src/App/TodoList/Item/index.tsx +++ b/src/App/TodoList/Item/index.tsx @@ -62,7 +62,7 @@ const Item: React.FC = ({ todo }) => { // search clicked item by id... if (t.id === id) { // change complated status only clicked item - return { ...t, completed: !t.completed } + return { ...t, completed: !t.completed, inProgress: false } // return other item without any changes } else { return t @@ -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)} + > + Backlog + + )} + {todo.completed && !todo.inProgress && ( + Completed + )} {/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */}