-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskManager.js
More file actions
58 lines (50 loc) · 1.16 KB
/
TaskManager.js
File metadata and controls
58 lines (50 loc) · 1.16 KB
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
import TaskList from "./TaskList.js";
import TaskItem from "./TaskItem.js";
class TaskManager {
constructor() {
const savedData = localStorage.getItem("taskManager");
this.lists = savedData ? JSON.parse(savedData).lists : [];
}
initialize() {
if (!(localStorage.getItem("taskManager"))) {
this.lists = [
{
name: "Pending",
items: [{text: "Task 1"}, {text: "Task 2"}],
},
{
name: "On Hold",
items: [],
},
{
name: "Doing",
items: [],
},
];
this.saveToLocalStorage();
}
}
addList(listName) {
const list = new TaskList(listName);
this.lists.push(list);
this.saveToLocalStorage();
}
removeList(index) {
this.lists.splice(index, 1);
this.saveToLocalStorage();
}
addItem(listIndex, itemText) {
const item = new TaskItem(itemText);
this.lists[listIndex].items.push(item);
this.saveToLocalStorage();
}
removeItem(listIndex, itemIndex) {
this.lists[listIndex].items.splice(itemIndex, 1);
this.saveToLocalStorage();
}
saveToLocalStorage() {
const data = { lists: this.lists };
localStorage.setItem("taskManager", JSON.stringify(data));
}
}
export default TaskManager;