-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
88 lines (69 loc) · 2.39 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { Task } from './Task.js';
import { TaskStorage } from './TaskStorage.js';
import { TaskUI } from './TaskUI.js';
const showCompleted = document.querySelector('#show-completed');
const newTask = document.querySelector('#new-task');
const taskCont = document.querySelector('.task-container');
// Add stored lists
document.addEventListener('DOMContentLoaded', TaskUI.displayTasks);
// Show completed
showCompleted.addEventListener('change', (e) => TaskUI.showCompletedTasks());
// New task
newTask.addEventListener('keydown', (e) => {
if (e.key !== 'Enter') return;
const taskId = new Date().getTime();
const title = newTask.value;
const task = new Task(taskId, title);
TaskStorage.storeTask(task);
TaskUI.addTaskToList(task);
TaskUI.clearFields();
});
// Show task details
taskCont.addEventListener('click', (e) => TaskUI.showTaskDetails(e.target));
// Remove task
taskCont.addEventListener('click', (e) => {
if (!e.target.classList.contains('remove-task')) return;
const task = e.target.parentElement.parentElement;
task.remove();
TaskStorage.removeTask(task.dataset.taskId);
});
// Task title
taskCont.addEventListener('keyup', (e) => {
if (!e.target.classList.contains('task-title')) return;
const taskId = e.target.parentElement.parentElement.dataset.taskId;
TaskStorage.taskTitle(taskId, e.target.value);
});
// Task notes
taskCont.addEventListener('keyup', (e) => {
if (!e.target.classList.contains('task-notes')) return;
const taskId =
e.target.parentElement.parentElement.parentElement.dataset.taskId;
TaskStorage.addNote(taskId, e.target.value);
});
// Priority
taskCont.addEventListener('click', (e) => {
if (!e.target.classList.contains('priority')) return;
const task = e.target.parentElement.parentElement.parentElement.parentElement;
TaskStorage.addPriority(
task.dataset.taskId,
e.target.textContent.toLowerCase()
);
TaskUI.addPriority(e.target);
});
// task completed
taskCont.addEventListener('change', (e) => {
if (e.target.id !== 'task-completed') return;
const task = e.target.parentElement.parentElement;
TaskStorage.taskCompleted(task.dataset.taskId, e.target.checked);
TaskUI.taskCompleted(e.target);
});
// Display date
TaskUI.displayDate();
let minute = new Date().getMinutes();
setInterval(() => {
let minuteNow = new Date().getMinutes();
if (minute !== minuteNow) {
TaskUI.displayDate();
minute = minuteNow;
}
}, 1000);