-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
72 lines (58 loc) · 1.82 KB
/
app.js
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
function app() {
return {
taskTitle: '',
tasks: JSON.parse(localStorage.getItem('tasks') || '[]'),
dragIndex: null,
taskData(index) {
return {
index,
startDrag() {
this.dragIndex = index;
},
};
},
dragStart(event) {
event.dataTransfer.setData('text/plain', ''); // Required for drag to work
this.dragIndex = this.index;
},
dragOver(event) {
event.preventDefault();
},
drop(targetIndex) {
if (this.dragIndex === null || this.dragIndex === targetIndex) return;
const [draggedTask] = this.tasks.splice(this.dragIndex, 1);
this.tasks.splice(targetIndex, 0, draggedTask);
this.dragIndex = null;
this.saveTasksToLocalStorage();
},
addTask() {
const title = this.taskTitle.trim();
if (title !== '') {
const newTask = {
type: 'to-do',
attributes: { title }
};
this.tasks.push(newTask);
this.taskTitle = '';
this.saveTasksToLocalStorage();
}
},
deleteTask(index) {
this.tasks.splice(index, 1);
this.saveTasksToLocalStorage();
},
saveTasksToLocalStorage() {
localStorage.setItem('tasks', JSON.stringify(this.tasks));
},
copyTasks() {
const encodedTasks = encodeURIComponent(JSON.stringify(this.tasks));
const url = `open 'things:///json?data=${encodedTasks}'`;
navigator.clipboard.writeText(url);
alert('Tasks copied to clipboard!');
},
deleteAllTasks() {
this.tasks = [];
this.saveTasksToLocalStorage();
},
};
}