-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
43 lines (31 loc) · 995 Bytes
/
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
const weather = new Weather();
const ui = new UI();
const storage = new Storage();
// GET Data from API And display on View
function getThenDisplay(city, country) {
weather.getWeatherData(city, country)
.then(res => ui.displayData(res))
.catch(err => ui.showError(err));
}
// EVENTS LISTENERS
document.addEventListener('DOMContentLoaded', (e) => {
// Get data from Local Storage
const city = storage.getItemFromLS('city');
const country = storage.getItemFromLS('country');
if (city !== null) {
getThenDisplay(city, country);
}
});
document.getElementById("location-form").addEventListener('submit', function (e) {
const city = e.target[0].value;
const country = e.target[1].value;
if (city !== "") {
storage.setItemToLS('city', city);
storage.setItemToLS('country', country);
getThenDisplay(city, country);
}
else {
alert("Please Enter City Name");
}
e.preventDefault();
});