-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
35 lines (28 loc) · 798 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
// Init Local Storage
const storage = new Storage();
// Get City from LS
const weatherLocation = storage.getLocation();
// Init Weather
const weather = new Weather(weatherLocation);
// Init UI
const ui = new UI();
// Event Listener to Get Weather
document.addEventListener('DOMContentLoaded', getWeather);
// Change Location Event
document.getElementById('w-change-btn').addEventListener('click', (e) => {
const city = document.getElementById('city').value;
// Run Change Location
weather.changeLocation(city);
// Save City on LS
storage.setLocation(city);
// Get new Weather
getWeather();
// Close popup
$('#locModal').modal('hide');
})
// Get Weather
function getWeather() {
weather.getWeather()
.then(results => ui.paint(results))
.catch(err => console.log(err));
}