-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
39 lines (32 loc) · 973 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
// INIT STORAGE CLASS
const storage = new Storage();
// GET STORED DATA
const weatherLocation = storage.getLocationData();
// init weather object
const weather = new Weather(weatherLocation.city);
// INIT UI OBJECT
const ui = new UI();
// CHANGE LOCATION EVENT
document.getElementById('w-change-btn').addEventListener('click', (e) => {
const city = document.getElementById('city').value;
// change location
weather.changeLocation(city);
// set location
storage.setLocationData(city);
loadWeather();
// CLOSE MODAL
$('#locModal').modal('hide')
})
// CHANGE CITY
// Load weather on DOM loaded
document.addEventListener('DOMContentLoaded', loadWeather());
function loadWeather() {
// FETCH CITY ID THEN FEACH WEATHER FOR CITY
weather.getCity()
.then(results => {
return ui.paintLocation(results.full),
weather.getWeather(results.id)
.then(weatherData => ui.paintWeather(weatherData[0]))
})
.catch(err => console.log(err))
};