-
Notifications
You must be signed in to change notification settings - Fork 0
/
Done.tsx
55 lines (49 loc) · 1.82 KB
/
Done.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from "react";
import Header from "./Header";
import { useSelector } from "react-redux";
import {ToDoInterface} from "./Modules/d";
import DoneToDoElement from "./DoneToDoElement";
import { StateInterface } from "./Modules/d";
import { addToDo, setDoneList } from "./Redux/contentSlice";
import {useDispatch} from "react-redux";
// Component for the Done page
export default function Done() {
const dispatch = useDispatch();
const doneToDos = useSelector((state: StateInterface) => state.content.doneList)
// Function to delete a signle done ToDo
const deleteToDo = ( { iD }:ToDoInterface ) => {
if (confirm('Are you sure you want to delete that?\n(This is an irreversible operation)')) {
const doneToDosCopy = [...doneToDos].filter(x => x.iD !== iD);
dispatch(setDoneList(doneToDosCopy));
}
}
// Function for reverting a single ToDo to the done list
const revertDone = (toDo: ToDoInterface) => {
const doneToDosCopy = [...doneToDos].filter(x => x.iD !== toDo.iD);
dispatch(setDoneList(doneToDosCopy));
dispatch(addToDo(toDo));
}
if (doneToDos.length === 0) {
return (
<>
<Header active={"done"}/>
<div id={"donediv"}>
<div id="actiondiv">No ToDos marked as done.</div>
</div>
</>
);
} else {
return (
<>
<Header active={"done"}/>
<div id={"donediv"}>
{doneToDos.map((toDo) => {
return (
<DoneToDoElement key={toDo.iD} toDo={toDo} deleteToDo={deleteToDo} revertDone={revertDone}/>
)
})}
</div>
</>
);
}
}