-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherui.js
49 lines (37 loc) · 1.16 KB
/
weatherui.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
class UI {
constructor() {
this.uiContainer = document.getElementById("content");
this.city;
this.defaultCity = "London";
}
populateUI(data) {
//de-structure vars
//add them to inner HTML
this.uiContainer.innerHTML = `
<div class="card mx-auto mt-5" style="width: 18rem;">
<div class="card-body justify-content-center">
<h5 class="card-title">${data.name}</h5>
<h6 class="card-subtitle mb-2 text-muted">Highs of ${data.main.temp_max}. Lows of ${data.main.temp_min}</h6>
<p class="card-text ">Weather conditions are described as: ${data.weather[0].description}</p>
</div>
</div>
`;
}
clearUI() {
uiContainer.innerHTML = "";
}
saveToLS(data) {
localStorage.setItem("city", JSON.stringify(data));
}
getFromLS() {
if (localStorage.getItem("city" == null)) {
return this.defaultCity;
} else {
this.city = JSON.parse(localStorage.getItem("city"));
}
return this.city;
}
clearLS() {
localStorage.clear();
}
}