Commit 23105189 authored by Jonatan Zint's avatar Jonatan Zint
Browse files

improve handling of cached schedules

parent 261dbe92
Pipeline #11026 passed with stages
in 42 seconds
......@@ -73,7 +73,7 @@ module.exports = function(ctx) {
},
env: {
SCHEDULE_URL:
"https://pretalx.hedonist-international.org/worldcongress-2022/schedule/export/schedule.json"
"http://localhost:8000/democon/schedule/export/schedule.json",
}
},
......
<template lang="pug">
#q-app
router-view(v-if="ready")
q-spinner-orbit.loader(v-if="!ready" color="primary" size="6em")
</template>
......@@ -12,11 +12,7 @@ import { READY, SYNC_RESOURCES } from './store/types'
export default {
name: "App",
async created() {
try {
await this.$store.dispatch(SYNC_RESOURCES);
} catch (e) {
console.warn("Failed to refresh resources");
}
this.sync(() => null);
},
computed: {
ready() {
......@@ -34,8 +30,17 @@ export default {
}
},
notifyConnectionIssue() {
this.$q.notify("There has been an error refreshing the schedule data");
this.$q.notify({
message: "There has been an error refreshing the schedule data",
color: "warning"
});
}
}
};
</script>
<style scoped>
.loader {
display: block;
margin: 10% auto;
}
</style>
<template lang="pug">
q-tabs(class="bg-primary text-white")
q-btn(icon='refresh' @click="refresh" flat :loading="refreshing" :label="lastSync" size="sm" stack)
q-route-tab(icon='alarm', to='/timetable', exact='', replace='') Timetable
q-route-tab(icon='lens', :to='"/space/" + defaultRoom', exact='', replace='') Spaces
q-route-tab(icon='search', to='/search', exact='', replace='') Search
q-route-tab(icon='info', to='/info', exact='', replace='') Info
q-route-tab(icon='map', to='/map', exact='', replace='') Map
</template>
<script>
import { LAST_SYNC, SYNC_RESOURCES } from '../store/types'
export default {
props: ["defaultRoom"],
name: "Navigation"
};
props: ['defaultRoom'],
name: 'Navigation',
data () {
return {
refreshing: false
}
},
computed: {
lastSync() {
if (this.$store.getters[LAST_SYNC]) {
return new Date(this.$store.getters[LAST_SYNC]).toLocaleString()
} else {
return undefined
}
}
},
methods: {
async refresh () {
this.refreshing = true
try {
await this.$store.dispatch(SYNC_RESOURCES, true)
} catch (e) {
this.$q.notify({
message: 'There has been an error refreshing the schedule data',
color: 'warning'
})
console.error(`Failed to refresh schedule ${e}`)
} finally {
this.refreshing = false
}
}
}
}
</script>
......@@ -14,7 +14,7 @@ export default new Vuex.Store({
plugins: [
createPersistedState({
key: "kyrene",
paths: ["schedule.scheduleData", "schedule.speakerData"]
paths: ["schedule.scheduleData", "schedule.scheduleDate"]
})
]
});
......@@ -7,6 +7,7 @@ import {
INITIALIZE_SPEAKERS,
INITIALIZE_SCHEDULES,
GET_SPEAKER,
LAST_SYNC,
LIST_SPEAKERS,
GET_DAYS_FOR_ROOM,
TIMESLOT_DURATION,
......@@ -101,6 +102,9 @@ export default {
return findId => {
return state.speakers.getSpeakerById(findId);
};
},
[LAST_SYNC](state) {
return state.scheduleDate;
}
},
......@@ -127,10 +131,10 @@ export default {
},
actions: {
async [SYNC_RESOURCES]({ commit, dispatch, state }, force = false) {
if ((state.scheduleData != null && state.speakerData != null) || force) {
if (!force && state.scheduleData != null) {
// use cached version
commit(INITIALIZE_SCHEDULES, state.scheduleData);
commit(INITIALIZE_SPEAKERS, state.speakerData);
commit(INITIALIZE_SPEAKERS, state.scheduleData);
commit(READY, true);
} else {
await Promise.all([dispatch(FETCH_SCHEDULE)]);
......
......@@ -16,3 +16,4 @@ export const GET_SPEAKER = "GET_SPEAKER";
export const READY = "READY";
export const SYNC_RESOURCES = "SYNC_RESOURCES";
export const GET_EVENTS = "GET_EVENTS";
export const LAST_SYNC = "LAST_SYNC";
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment