-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
99 lines (92 loc) · 2.52 KB
/
App.jsx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import { useEffect, useState } from "react";
import AddTask from "./components/AddTask";
import Greeting from "./components/Greeting";
import ToDo from "./components/ToDo";
import { useDrop } from "react-dnd";
const App = () => {
const [taskList, setTaskList] = useState([]);
const [completed, setCompleted] = useState([]);
useEffect(() => {
let array = localStorage.getItem("taskList");
if (array) {
setTaskList(JSON.parse(array));
}
}, []);
const [{ isOver }, drop] = useDrop(() => ({
accept: "todo",
drop: (item) =>
addToCompleted(
item.id,
item.projectName,
item.taskDescription,
item.timestamp,
item.duration
),
collect: (monitor) => ({
isOver: !!monitor.isOver(),
}),
}));
const addToCompleted = (
id,
projectName,
taskDescription,
timestamp,
duration
) => {
const moveTask = taskList.filter((task) => id === task.id);
setCompleted((completed) => [
...completed,
{
moveTask,
projectName,
taskDescription,
timestamp,
duration,
},
]);
};
return (
<>
<h1 className="text-5xl font-bold py-5 pl-6">Task Tracker</h1>
<Greeting />
<div className="flex flex-row items-center">
<p className="text-xl pl-6">Click</p>
<AddTask taskList={taskList} setTaskList={setTaskList} />
<p className="text-xl my-2">to add a new task and drag to complete the task</p>
</div>
<div className="flex flex-row">
<div className="w-full">
<h2 className="ml-6 text-black my-4 rounded text-xl font-semibold w-3/4 max-w-lg py-1 px-2 bg-gray-300">
To Do:
</h2>
<div className="ml-6 flex flex-col-reverse">
{taskList.map((task, i) => (
<ToDo
key={i}
task={task}
index={i}
taskList={taskList}
setTaskList={setTaskList}
/>
))}
</div>
</div>
<div className="w-full flex flex-col" ref={drop}>
<h2 className="text-black my-4 rounded text-xl font-semibold w-3/4 max-w-lg py-1 px-2 bg-gray-300">
Completed:
</h2>
{completed.map((task, i) => (
<ToDo
key={i}
task={task}
index={i}
taskList={taskList}
setTaskList={setTaskList}
/>
))}
</div>
</div>
</>
);
};
export default App;