Skip to content

Commit

Permalink
grouped Todos
Browse files Browse the repository at this point in the history
  • Loading branch information
velvet-jedi committed Dec 9, 2024
1 parent 1adaf19 commit 456c639
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@
Always retrieve the most recent data directly from the primary source (like localStorage) before making updates, ensuring you're working with the latest information.

- using a function as a state variable to load initially the localstorage instead of a straight useEffect

- grouping together of done and pending
15 changes: 13 additions & 2 deletions src/TODO/ToDo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ export default function ToDo() {
persistTodos(newTodos);
}

const pendingTodos = [],
doneTodos = [];
todos.forEach((t) => {
if (t.isDone) {
doneTodos.push(t);
} else {
pendingTodos.push(t);
}
});
const groupedTodos = [...pendingTodos, ...doneTodos];

return (
<>
<InputText
Expand All @@ -96,8 +107,8 @@ export default function ToDo() {
/>
{/* {todoToAdd} */}
<ToDos
todos={todos}
handleDone={handleDone}
todos={groupedTodos} // replace with grouped todos
onDone={handleDone}
onDelete={handleDeleteTodo}
onEdit={handleEditTodo}
onEditCancel={handleEditCancel}
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ button:hover {
margin-right: 10px;
}

div[data-done-todo="true"] {
background-color: green;
}

/* Responsive Adjustments */
@media (max-width: 600px) {
#root {
Expand Down

0 comments on commit 456c639

Please sign in to comment.