Add timestamp param to bust cache when refreshing radar images

This commit is contained in:
Lance Edgar 2024-06-09 19:26:42 -05:00
parent cd615cb020
commit fa1e702173
2 changed files with 15 additions and 3 deletions

View file

@ -131,7 +131,7 @@ export const useWeatherStore = defineStore('weather', {
if (!this.forecast) { if (!this.forecast) {
const weather = await this.getWeather(this.coordinates) const weather = await this.getWeather()
const url = weather.properties.forecast const url = weather.properties.forecast
const response = await fetch(url) const response = await fetch(url)

View file

@ -11,6 +11,7 @@ const weatherStore = useWeatherStore()
const coordinates = ref(null) const coordinates = ref(null)
const refreshing = ref(false) const refreshing = ref(false)
const timestamp = ref(new Date().getTime())
const panelHeadingTitle = computed(() => { const panelHeadingTitle = computed(() => {
@ -24,6 +25,16 @@ const panelHeadingTitle = computed(() => {
}) })
const radarLatestURL = computed(() => {
return `${weatherStore.radarLatestURL}?t=${timestamp.value}`
})
const radarLoopURL = computed(() => {
return `${weatherStore.radarLoopURL}?t=${timestamp.value}`
})
onActivated(() => { onActivated(() => {
if (!weatherStore.coordinates) { if (!weatherStore.coordinates) {
@ -56,6 +67,7 @@ async function fetchWeather() {
async function refreshWeather() { async function refreshWeather() {
refreshing.value = true refreshing.value = true
weatherStore.clearWeather(true) weatherStore.clearWeather(true)
timestamp.value = new Date().getTime()
await fetchWeather() await fetchWeather()
refreshing.value = false refreshing.value = false
} }
@ -163,10 +175,10 @@ function showHourly(period) {
<div class="panel-block"> <div class="panel-block">
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<img :src="weatherStore.radarLatestURL" /> <img :src="radarLatestURL" />
</div> </div>
<div class="column"> <div class="column">
<img :src="weatherStore.radarLoopURL" /> <img :src="radarLoopURL" />
</div> </div>
</div> </div>
</div> </div>