-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
104 lines (82 loc) · 2.92 KB
/
Copy pathscript.js
File metadata and controls
104 lines (82 loc) · 2.92 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
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
100
101
102
103
function enterApp() {
const name = document.getElementById("username").value.trim();
if (!name) return alert("Enter your name");
localStorage.setItem("currentUser", name);
if (!localStorage.getItem(name)) {
localStorage.setItem(name, JSON.stringify([]));
}
window.location.href = "dashboard.html";
}
if (window.location.pathname.includes("dashboard.html")) {
const user = localStorage.getItem("currentUser");
document.getElementById("welcomeText").innerText = "Welcome, " + user;
loadLists();
function loadLists() {
const lists = JSON.parse(localStorage.getItem(user));
const container = document.getElementById("listsContainer");
container.innerHTML = "";
lists.forEach((list, index) => {
const div = document.createElement("div");
div.className = "card";
div.innerText = list.name;
div.onclick = () => {
localStorage.setItem("currentListIndex", index);
window.location.href = "todo.html";
};
container.appendChild(div);
});
}
window.createList = function () {
const listName = document.getElementById("newListName").value;
if (!listName) return;
const lists = JSON.parse(localStorage.getItem(user));
lists.push({ name: listName, tasks: [] });
localStorage.setItem(user, JSON.stringify(lists));
loadLists();
}
window.logout = function () {
window.location.href = "index.html";
}
}
// Todo Page
if (window.location.pathname.includes("todo.html")) {
const user = localStorage.getItem("currentUser");
const index = localStorage.getItem("currentListIndex");
let lists = JSON.parse(localStorage.getItem(user));
let currentList = lists[index];
document.getElementById("listTitle").innerText = currentList.name;
loadTasks();
function loadTasks() {
const container = document.getElementById("taskList");
container.innerHTML = "";
currentList.tasks.forEach((task, i) => {
const div = document.createElement("div");
div.className = "task";
div.innerHTML = `
${task}
<span onclick="deleteTask(${i})" style="cursor:pointer;">❌</span>
`;
container.appendChild(div);
});
}
window.addTask = function () {
const input = document.getElementById("taskInput");
if (!input.value) return;
currentList.tasks.push(input.value);
input.value = "";
save();
loadTasks();
}
window.deleteTask = function (i) {
currentList.tasks.splice(i, 1);
save();
loadTasks();
}
function save() {
lists[index] = currentList;
localStorage.setItem(user, JSON.stringify(lists));
}
window.goBack = function () {
window.location.href = "dashboard.html";
}
}