Skip to content

Commit

Permalink
clean up and add Uncheck All todos
Browse files Browse the repository at this point in the history
  • Loading branch information
justthinguyen committed Oct 18, 2023
1 parent 1b68e1e commit 1bbbe34
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ body {
border: 1px solid rgba(255, 255, 255, 0);
}

.todo-list-stats {
.todo-list-stats,
.uncheck-all {
display: flex;
justify-content: center;
padding-bottom: 10px;
Expand Down Expand Up @@ -182,4 +183,11 @@ body {
top: 0;
right: 1px;
border-radius: 50%;
}

.uncheck-all button {
border: none;
cursor: pointer;
background: none;
font-size: 1rem;
}
12 changes: 10 additions & 2 deletions src/TodoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ interface TodoListStatsProps {
const TodoListStats = (ps: TodoListStatsProps) => (
<div className='todo-list-stats'>
Completed {ps.completed} / {ps.total}
{ps.completed ? (<span className='completedCheck'>&#x2714;</span>) : (<></>)}
{(ps.completed === ps.total && ps.total > 0) ? <span className='allDone'> well done!! 👏 🤩</span> : (<></>)}
{ps.completed && (<span className='completedCheck'>&#x2714;</span>)}
{(ps.completed === ps.total && ps.total > 0) && <span className='allDone'> well done!! 👏 🤩</span>}
</div>
)
const getTodoListStats = (todos: Todo[]): TodoListStatsProps => {
Expand Down Expand Up @@ -93,6 +93,12 @@ export const TodoList = (ps: TodoListProps) => {
return result;
};

const uncheckAllTodo = () => {
const newTodos = [...todos];
newTodos.forEach(todo => todo.isCompleted = false);
setTodos(newTodos);
}

const onDragEnd = (result: DropResult) => {
if (!result.destination) return;
const items = reorder(todos, result.source.index, result.destination.index);
Expand All @@ -103,6 +109,8 @@ export const TodoList = (ps: TodoListProps) => {
<>
<TodoListName name={todoName} onNameChange={ps.onNameChange} />
<TodoListStats completed={todoListStats.completed} total={todoListStats.total} />
{todoListStats.total && todoListStats.completed === todoListStats.total &&
(<div className='uncheck-all'><button onClick={() => uncheckAllTodo()}>Uncheck All ♻️</button></div>)}
<DragDropContext onDragEnd={onDragEnd}>

<StrictModeDroppable droppableId='droppable'>
Expand Down

0 comments on commit 1bbbe34

Please sign in to comment.