{{ weatherStore.cityState }}
Alerts
diff --git a/src/views/HourlyView.vue b/src/views/HourlyView.vue index 4c1105e..88c95d5 100644 --- a/src/views/HourlyView.vue +++ b/src/views/HourlyView.vue @@ -6,14 +6,17 @@ import { useWeatherStore } from '../stores/weather' const weatherStore = useWeatherStore() const coordinates = ref(null) -const hourly = ref(null) const chunks = ref([]) +const refreshing = ref(false) + onActivated(() => { if (coordinates.value != weatherStore.coordinates) { - hourly.value = null + refreshing.value = true chunks.value = [] - fetchHourly() + fetchHourly().then(() => { + refreshing.value = false + }) } }) @@ -24,11 +27,11 @@ async function fetchHourly() { const url = weather.properties.forecastHourly const response = await fetch(url) - hourly.value = await response.json() + const hourly = await response.json() chunks.value = [] let chunk = null - for (let period of hourly.value.properties.periods.slice(0, 12)) { + for (let period of hourly.properties.periods.slice(0, 12)) { const date = new Date(period.startTime).toLocaleDateString('en-US', { dateStyle: 'full', }) @@ -43,6 +46,16 @@ async function fetchHourly() { } } + +async function refreshHourly() { + refreshing.value = true + weatherStore.clearWeather(true) + chunks.value = [] + await fetchHourly() + refreshing.value = false +} + + function renderTime(period) { const date = new Date(period.startTime) return date.toLocaleTimeString('en-US', {timeStyle: 'short'}) @@ -53,12 +66,20 @@ function renderTime(period) {{{ weatherStore.cityState }}
diff --git a/src/views/WeatherView.vue b/src/views/WeatherView.vue index b62ea61..37a609b 100644 --- a/src/views/WeatherView.vue +++ b/src/views/WeatherView.vue @@ -10,7 +10,7 @@ const locationStore = useLocationStore() const weatherStore = useWeatherStore() const coordinates = ref(null) -const alerts = ref(null) +const refreshing = ref(false) const panelHeadingTitle = computed(() => { @@ -25,27 +25,39 @@ const panelHeadingTitle = computed(() => { onActivated(() => { - fetchWeather() -}) - - -function coordinatesUpdated(coords) { - weatherStore.clearWeather() - weatherStore.setCoordinates(coords) - fetchWeather() -} - - -async function fetchWeather() { if (!weatherStore.coordinates) { router.push('/') return } - const forecast = await weatherStore.getForecast() + refreshing.value = true + fetchWeather().then(() => { + refreshing.value = false + }) +}) + + +async function coordinatesUpdated(coords) { + refreshing.value = true + weatherStore.clearWeather() + weatherStore.setCoordinates(coords) + await fetchWeather() + refreshing.value = false +} + + +async function fetchWeather() { + await weatherStore.getForecast() coordinates.value = weatherStore.coordinates - alerts.value = weatherStore.alerts +} + + +async function refreshWeather() { + refreshing.value = true + weatherStore.clearWeather(true) + await fetchWeather() + refreshing.value = false } @@ -64,7 +76,8 @@ function showHourly(period) {
Watches In Effect
-Updated {{ new Date(alerts.updated).toLocaleTimeString('en-US', {timeStyle: 'short'}) }}
+Updated {{ new Date(weatherStore.alerts.updated).toLocaleTimeString('en-US', {timeStyle: 'short'}) }}
{{ period.name }}