/
UpdateUI.js
48 lines (43 loc) · 2 KB
/
UpdateUI.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
import addDragEvent from './Dragdrop.js';
import storageManager from './Storage.js';
export default class UpdateUI {
constructor(listElement, listObj) {
this.showToDoElement = listElement;
this.todoList = listObj;
}
static createListDisplay = (todo, empty = false) => {
const li = document.createElement('li');
li.classList.add('item');
li.draggable = true;
li.setAttribute('data-index', todo.index);
li.id = `list-${todo.index}`;
if (!empty) {
if (!todo.completed) {
li.innerHTML = `<input type="checkbox" id="${todo.index}" class="task-box">
<span id="task-${todo.index}" contenteditable='false' class= "task-description" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false"> ${todo.description} </span>
<button class="remove"> <i class="fa fa-grip-lines" aria-hidden="true"></i><i id ="trash-${todo.index}" class="trash fa fa-trash" aria-hidden="true"></i> </button>`;
} else {
li.innerHTML = `<input type="checkbox" id="${todo.index}" class="task-box" checked>
<span id="task-${todo.index}" contenteditable='false' class= "task-description completed" data-gramm="false" data-gramm_editor="false" data-enable-grammarly="false"> ${todo.description} </span>
<button class="remove"> <i class="fa fa-grip-lines" aria-hidden="true"></i><i id ="trash-${todo.index}" class="trash fa fa-trash" aria-hidden="true"></i> </button>`;
}
addDragEvent(li);
} else {
li.innerHTML = '<span class= "item">Nothing on the list!</span>';
}
return li;
};
refreshUI = () => {
this.todoList = storageManager.getData();
while (this.showToDoElement.firstChild) {
this.showToDoElement.removeChild(this.showToDoElement.firstChild);
}
if (this.todoList.length > 0) {
this.todoList.forEach((todo) => {
this.showToDoElement.appendChild(UpdateUI.createListDisplay(todo));
});
} else {
this.showToDoElement.appendChild(UpdateUI.createListDisplay({}, true));
}
};
}