Skip to content

Commit

Permalink
Scroll to Now on Init
Browse files Browse the repository at this point in the history
  • Loading branch information
holloway committed Jul 31, 2024
1 parent 88e009b commit 251fb76
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
19 changes: 16 additions & 3 deletions client/agenda/AgendaQuickAccess.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
})
})()
</script>
<style lang="scss">
Expand Down
28 changes: 1 addition & 27 deletions client/agenda/AgendaScheduleList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
</template>

<script setup>
import { computed, h, onBeforeUnmount, onMounted, onUpdated, reactive } from 'vue'
import { computed, h, onBeforeUnmount, onMounted, reactive } from 'vue'
import { DateTime } from 'luxon'
import find from 'lodash/find'
import sortBy from 'lodash/sortBy'
Expand Down Expand Up @@ -575,38 +575,12 @@ function recalculateRedLine () {
}
}
/**
* Scrolls to #now
*/
function scrollToNowInit() {
console.log("scrollToNowInit ()", window.location.hash)
let hasScrolledToNow = false;
if (window.location.hash !== "#now") return
agendaStore.$subscribe((mutation, agendaStoreState) => {
console.log("agendaStoreState.schedule.length", agendaStoreState.schedule.length)
console.log("state.redhandOffset", state.redhandOffset)
if (hasScrolledToNow === true ||
agendaStoreState.schedule.length === 0 ||
state.redhandOffset === 0) {
return
}
window.scrollTo(0, state.redhandOffset)
hasScrolledToNow = true;
})
}
// MOUNTED
onMounted(() => {
// -> Update Redhand Position
recalculateRedLine()
redhandScheduler = setInterval(recalculateRedLine, 5000)
scrollToNowInit()
})
// BEFORE UNMOUNT
Expand Down
1 change: 0 additions & 1 deletion client/agenda/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const useAgendaStore = defineStore('agenda', {
}).map(s => {
// -> Adjust times to selected timezone
let eventStartDate = DateTime.fromISO(s.startDateTime, { zone: state.meeting.timezone }).setZone(state.timezone)
eventStartDate = eventStartDate.plus({ days: 6.5 })
const eventEndDate = eventStartDate.plus({ seconds: s.duration })

// -> Find remote call-in URL
Expand Down

0 comments on commit 251fb76

Please sign in to comment.