Skip to content

Commit

Permalink
Update TodoList.jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
EuJinnLucaShow committed Jan 4, 2024
1 parent c6bffdc commit 654fd85
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/components/TodoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ const TodoList = () => {

const [removed] = items.splice(result.source.index, 1);
items.splice(result.destination.index, 0, removed);

setItems(items);

const reversed = [...items].reverse();
const updatedTodoIds = items.map(item => item._id);

const updatedTodos = [...todos].sort(
(a, b) => updatedTodoIds.indexOf(a._id) - updatedTodoIds.indexOf(b._id),
);

const reversed = [...updatedTodos].reverse();
dispatch(sendTodos(reversed));
};

Expand Down

0 comments on commit 654fd85

Please sign in to comment.