From cf5a863ea31ac66dc1efff50e0ea92e0ab9b6abb Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Tue, 18 Mar 2025 15:41:34 +1300 Subject: [PATCH 1/4] fix: agenda now fallback to next event if there is no current event --- client/agenda/AgendaMobileBar.vue | 8 +++---- client/agenda/AgendaQuickAccess.vue | 6 +++--- client/agenda/AgendaScheduleList.vue | 16 ++++++++------ client/agenda/store.js | 32 ++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/client/agenda/AgendaMobileBar.vue b/client/agenda/AgendaMobileBar.vue index 63611e21c2..43480bedd3 100644 --- a/client/agenda/AgendaMobileBar.vue +++ b/client/agenda/AgendaMobileBar.vue @@ -124,11 +124,11 @@ const downloadIcsOptions = [ function jumpToDay (dayId) { if (dayId === 'now') { - const lastEventId = agendaStore.findCurrentEventId() - if (lastEventId) { - document.getElementById(`agenda-rowid-${lastEventId}`)?.scrollIntoView(true) + const nowEventId = agendaStore.findNowEventId() + if (nowEventId) { + document.getElementById(`agenda-rowid-${nowEventId}`)?.scrollIntoView(true) } else { - message.warning('There is no event happening right now.') + message.warning('There is no event happening right now or in the future.') } } else { document.getElementById(dayId)?.scrollIntoView(true) diff --git a/client/agenda/AgendaQuickAccess.vue b/client/agenda/AgendaQuickAccess.vue index b226d09c60..99d000eac3 100644 --- a/client/agenda/AgendaQuickAccess.vue +++ b/client/agenda/AgendaQuickAccess.vue @@ -204,10 +204,10 @@ function scrollToDay (daySlug, ev) { } function scrollToNow (ev) { - const lastEventId = agendaStore.findCurrentEventId() + const nowEventId = agendaStore.findNowEventId() - if (lastEventId) { - document.getElementById(`agenda-rowid-${lastEventId}`)?.scrollIntoView(true) + if (nowEventId) { + document.getElementById(`agenda-rowid-${nowEventId}`)?.scrollIntoView(true) } else { message.warning('There is no event happening right now.') } diff --git a/client/agenda/AgendaScheduleList.vue b/client/agenda/AgendaScheduleList.vue index ab0f6e0184..2432776e05 100644 --- a/client/agenda/AgendaScheduleList.vue +++ b/client/agenda/AgendaScheduleList.vue @@ -590,10 +590,10 @@ function renderLinkLabel (opt) { function recalculateRedLine () { state.currentMinute = DateTime.local().minute - const lastEventId = agendaStore.findCurrentEventId() + const currentEventId = agendaStore.findCurrentEventId() - if (lastEventId) { - state.redhandOffset = document.getElementById(`agenda-rowid-${lastEventId}`)?.offsetTop || 0 + if (currentEventId) { + state.redhandOffset = document.getElementById(`agenda-rowid-${currentEventId}`)?.offsetTop || 0 } else { state.redhandOffset = 0 } @@ -614,9 +614,13 @@ function recalculateRedLine () { return } unsubscribe() // we only need to scroll once, so unsubscribe from future updates - if(window.location.hash === "#now") { - const lastEventId = agendaStore.findCurrentEventId() - document.getElementById(`agenda-rowid-${lastEventId}`)?.scrollIntoView(true) + if (window.location.hash === "#now") { + const nowEventId = agendaStore.findNowEvent() + if (nowEventId) { + document.getElementById(`agenda-rowid-${nowEventId}`)?.scrollIntoView(true) + } else { + message.warning('There is no event happening right now or in the future.') + } } else if(window.location.hash.startsWith(`#${daySlugPrefix}`)) { document.getElementById(window.location.hash.substring(1))?.scrollIntoView(true) } diff --git a/client/agenda/store.js b/client/agenda/store.js index 71c1219725..a826b086b4 100644 --- a/client/agenda/store.js +++ b/client/agenda/store.js @@ -230,6 +230,38 @@ export const useAgendaStore = defineStore('agenda', { return lastEvent.id || null }, + findNowEventId () { + const currentEventId = this.findCurrentEventId() + + if (currentEventId) return currentEventId + + // if there isn't a current event then instead find the next event + + const current = (this.nowDebugDiff ? DateTime.local().minus(this.nowDebugDiff) : DateTime.local()).setZone(this.timezone) + + // -> Find next event after current time + let nextEvent = {} + for(const sh of this.scheduleAdjusted) { + if (sh.adjustedStart > current) { + // -> Use the first event of multiple events having identical times + if (nextEvent.start === sh.adjustedStart.toMillis()) { + continue + } else { + nextEvent = { + id: sh.id, + start: sh.adjustedStart.toMillis(), + end: sh.adjustedEnd.toMillis() + } + } + } + // -> Skip other future events + if (sh.adjustedStart > current) { + break + } + } + + return nextEvent.id || null + }, hideLoadingScreen () { // -> Hide loading screen const loadingRef = document.querySelector('#app-loading') From d4c582090e585c8f586e9f9b6caf34ef962b8fcd Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Tue, 18 Mar 2025 19:16:28 +1300 Subject: [PATCH 2/4] chore: agenda goto now PR feedback --- client/agenda/AgendaQuickAccess.vue | 2 +- client/agenda/store.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/agenda/AgendaQuickAccess.vue b/client/agenda/AgendaQuickAccess.vue index 99d000eac3..c9412f6663 100644 --- a/client/agenda/AgendaQuickAccess.vue +++ b/client/agenda/AgendaQuickAccess.vue @@ -209,7 +209,7 @@ function scrollToNow (ev) { if (nowEventId) { document.getElementById(`agenda-rowid-${nowEventId}`)?.scrollIntoView(true) } else { - message.warning('There is no event happening right now.') + message.warning('There is no event happening right now or in the future.') } } diff --git a/client/agenda/store.js b/client/agenda/store.js index a826b086b4..56d7423e8c 100644 --- a/client/agenda/store.js +++ b/client/agenda/store.js @@ -233,7 +233,9 @@ export const useAgendaStore = defineStore('agenda', { findNowEventId () { const currentEventId = this.findCurrentEventId() - if (currentEventId) return currentEventId + if (currentEventId) { + return currentEventId + } // if there isn't a current event then instead find the next event @@ -245,7 +247,7 @@ export const useAgendaStore = defineStore('agenda', { if (sh.adjustedStart > current) { // -> Use the first event of multiple events having identical times if (nextEvent.start === sh.adjustedStart.toMillis()) { - continue + break } else { nextEvent = { id: sh.id, From 52678da03ecb74ee81d3b587b0e8874acc543525 Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Tue, 18 Mar 2025 19:17:41 +1300 Subject: [PATCH 3/4] chore: simplifying 'agenda goto now' next event logic --- client/agenda/store.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/client/agenda/store.js b/client/agenda/store.js index 56d7423e8c..8fb00c0c70 100644 --- a/client/agenda/store.js +++ b/client/agenda/store.js @@ -245,19 +245,11 @@ export const useAgendaStore = defineStore('agenda', { let nextEvent = {} for(const sh of this.scheduleAdjusted) { if (sh.adjustedStart > current) { - // -> Use the first event of multiple events having identical times - if (nextEvent.start === sh.adjustedStart.toMillis()) { - break - } else { - nextEvent = { - id: sh.id, - start: sh.adjustedStart.toMillis(), - end: sh.adjustedEnd.toMillis() - } + nextEvent = { + id: sh.id, + start: sh.adjustedStart.toMillis(), + end: sh.adjustedEnd.toMillis() } - } - // -> Skip other future events - if (sh.adjustedStart > current) { break } } From e6a64420bbbc6f767d0cde1289d2668bfa5557aa Mon Sep 17 00:00:00 2001 From: Matthew Holloway Date: Tue, 18 Mar 2025 19:20:52 +1300 Subject: [PATCH 4/4] chore: simplifying 'agenda goto now' nextEvent var --- client/agenda/store.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client/agenda/store.js b/client/agenda/store.js index 8fb00c0c70..359c5fbf05 100644 --- a/client/agenda/store.js +++ b/client/agenda/store.js @@ -242,19 +242,15 @@ export const useAgendaStore = defineStore('agenda', { const current = (this.nowDebugDiff ? DateTime.local().minus(this.nowDebugDiff) : DateTime.local()).setZone(this.timezone) // -> Find next event after current time - let nextEvent = {} + let nextEventId = undefined for(const sh of this.scheduleAdjusted) { if (sh.adjustedStart > current) { - nextEvent = { - id: sh.id, - start: sh.adjustedStart.toMillis(), - end: sh.adjustedEnd.toMillis() - } + nextEventId = sh.id break } } - return nextEvent.id || null + return nextEventId || null }, hideLoadingScreen () { // -> Hide loading screen