From 251fb763038eb440f291beafd5b64d8e77ce8e0d Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Thu, 1 Aug 2024 10:44:42 +1200 Subject: [PATCH] Scroll to Now on Init --- client/agenda/AgendaQuickAccess.vue | 19 ++++++++++++++++--- client/agenda/AgendaScheduleList.vue | 28 +--------------------------- client/agenda/store.js | 1 - 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/client/agenda/AgendaQuickAccess.vue b/client/agenda/AgendaQuickAccess.vue index 99adc1027ed..4ba06ab2cca 100644 --- a/client/agenda/AgendaQuickAccess.vue +++ b/client/agenda/AgendaQuickAccess.vue @@ -205,9 +205,7 @@ function scrollToDay (dayId, ev) { document.getElementById(`agenda-day-${dayId}`)?.scrollIntoView(true) } -function scrollToNow (ev) { - ev.preventDefault() - +function scrollToNow () { const lastEventId = agendaStore.findCurrentEventId() if (lastEventId) { @@ -217,6 +215,21 @@ function scrollToNow (ev) { } } +/** + * Scrolls to now on page load when browser location hash is "#now" + */ +(function scrollToNowHashInit() { + if (window.location.hash !== "#now") return + + const unsubscribe = agendaStore.$subscribe((mutation, agendaStoreState) => { + if (agendaStoreState.schedule.length === 0) { + return + } + scrollToNow() + unsubscribe() // we only need to scroll once, so unsubscribe from future updates + }) +})() +