-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.js
71 lines (48 loc) · 2.12 KB
/
ui.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
class UI {
static addBeverageToUI(newBeverage) {
if (newBeverage.name === "tea") {
this.addTeaToUI(newBeverage);
} else if (newBeverage.name === "coffee") {
this.addCoffeeToUI(newBeverage);
}
}
static addTeaToUI(newBeverage) {
const teaList = document.getElementById("tea-list");
//add strikethrough style
$("#tea-list").children().css("text-decoration-line", "line-through");
teaList.innerHTML += `<a href="#" class="list-group-item list-group-item-action">${newBeverage.date.toLocaleTimeString()}</a>`;
}
static addCoffeeToUI(newBeverage) {
const coffeeList = document.getElementById("coffee-list");
$("#coffee-list ").children().css("text-decoration-line", "line-through");
coffeeList.innerHTML += `<a href="#" class="list-group-item list-group-item-action">${newBeverage.date.toLocaleTimeString()}</a>`;
}
static displayMessages(message, type, beverage) {
const div = document.querySelector(`#${beverage}-div`);
const messageDiv = document.createElement("div");
messageDiv.className = `alert alert-${type}`;
messageDiv.textContent = message;
div.appendChild(messageDiv);
// alert for 3 seconds
setTimeout(function () {
messageDiv.remove();
}, 3000);
}
static loadAllBeverages(beverages) {
const todayDate = new Date();
beverages.forEach(function (beverage) {
/*
* Date in local storage is ISO 8601 formatted.
* Convert it date object
* */
beverage.date = new Date(beverage.date);
// Control the day of beverage
if (beverage.date.toDateString() === todayDate.toDateString()) {
UI.addBeverageToUI(beverage);
} else {
// if it is not the same day don't show and delete from storage.
Storage.deleteBeverageFromStorage(beverage.name, beverage.date.toISOString());
}
});
}
}