From f80f74fd3bf4fd822ab46e3b4de02b994669829c Mon Sep 17 00:00:00 2001 From: Mel <97147377+MelissaAutumn@users.noreply.github.com> Date: Tue, 28 May 2024 06:50:53 -0700 Subject: [PATCH] Use hashes for navigating calendar modes (#430) * Use hashes for navigating calendar modes * Fix the opacity that the frontend linter does not want us to have. --- frontend/src/components/CalendarQalendar.vue | 23 ++++++++++++++++++-- frontend/src/router.js | 15 +------------ frontend/src/views/BookingView.vue | 2 +- frontend/src/views/CalendarView.vue | 4 ++-- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/CalendarQalendar.vue b/frontend/src/components/CalendarQalendar.vue index 088d78337..b5059a1ac 100644 --- a/frontend/src/components/CalendarQalendar.vue +++ b/frontend/src/components/CalendarQalendar.vue @@ -14,9 +14,12 @@ import { qalendarSlotDurations, } from '@/definitions'; import { getLocale, getPreferredTheme, timeFormat } from '@/utils'; +import { useRoute, useRouter } from 'vue-router'; // component constants const dj = inject('dayjs'); +const router = useRouter(); +const route = useRoute(); // component properties const props = defineProps({ @@ -37,10 +40,12 @@ const { const qalendarRef = ref(); +const isValidMode = (mode) => ['#day', '#week', '#month'].indexOf(mode) !== -1; + const displayFormat = timeFormat(); const calendarColors = ref({}); const selectedDate = ref(null); -const calendarMode = ref('month'); +const calendarMode = ref(isValidMode(route.hash) ? route.hash.slice(1) : 'month'); const preferredTheme = getPreferredTheme(); // component emits @@ -109,7 +114,9 @@ const dateChange = (evt) => { * On mode change. e.g. month, week, day. */ const modeChange = (evt) => { - calendarMode.value = evt?.mode ?? 'month'; + const hash = evt?.mode ?? 'month'; + calendarMode.value = hash; + router.push({ hash: `#${hash}` }); }; /* Functions */ @@ -339,6 +346,18 @@ watch(dayBoundary, () => { qalendarRef.value.time.DAY_START = dayBoundary.value.start * 100; qalendarRef.value.time.DAY_END = dayBoundary.value.end * 100; }); + +watch(route, () => { + if (!qalendarRef?.value) { + return; + } + + // Route.hash never returns null, so need to do falsey default here. + const hash = route.hash || '#month'; + if (isValidMode(hash)) { + qalendarRef.value.mode = hash.replace('#', ''); + } +});