-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
67 lines (59 loc) · 1.42 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
require('colors');
const { saveToDB, readFromDB } = require('./db/dbHandler');
const {
promptUserOption,
waitForEnter,
readInput,
listTasksToDelete,
showChecklist,
confirmDelete,
} = require('./helpers/inquirer');
const Tasks = require('./models/Tasks');
const main = () => {
const tasks = new Tasks();
const tasksFromDB = readFromDB();
if (tasksFromDB) {
tasks.loadTasks(tasksFromDB);
}
start(tasks);
};
const start = async (tasks) => {
let option = 0;
do {
console.clear();
option = await promptUserOption();
switch (option) {
case 1:
const task = await readInput();
console.log(task);
tasks.createTask(task);
break;
case 2:
tasks.listAllTasks();
break;
case 3:
tasks.listCompletedTasks();
break;
case 4:
tasks.listCompletedTasks(false);
break;
case 5:
const ids = await showChecklist(tasks.tasksList);
tasks.changeSelectedTasksState(ids);
break;
case 6:
const id = await listTasksToDelete(tasks.tasksList);
if (id !== '0') {
const deleteConfirmation = await confirmDelete();
if (deleteConfirmation) {
tasks.deleteTask(id);
console.log(`Task with id: ${id} deleted.`);
}
}
break;
}
saveToDB(tasks.tasksList);
await waitForEnter();
} while (option !== 0);
};
main();