From c1bfb4914a2b41d42f7fc866db949be76754bbc4 Mon Sep 17 00:00:00 2001 From: Julian Leucker <leuckerj@gmail.com> Date: Fri, 15 Nov 2024 14:29:22 +0100 Subject: [PATCH 1/3] Scroll to date once events are loaded for the first time --- aleksis/core/frontend/components/calendar/Calendar.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aleksis/core/frontend/components/calendar/Calendar.vue b/aleksis/core/frontend/components/calendar/Calendar.vue index 2809e7247..648cc12be 100644 --- a/aleksis/core/frontend/components/calendar/Calendar.vue +++ b/aleksis/core/frontend/components/calendar/Calendar.vue @@ -119,6 +119,7 @@ export default { }, firstTime: 1, + scrolled: false, ready: false, @@ -355,6 +356,10 @@ export default { const minTime = minuteTimes.length > 0 ? Math.min.apply(Math, minuteTimes) : 0; this.firstTime = minTime; + + if (!this.scrolled) { + this.scrollToTime(); + } }, getMinutesAfterMidnight(date) { return 60 * date.hour + date.minute; @@ -492,7 +497,6 @@ export default { mounted() { this.ready = true; this.$refs.calendar.move(0); - this.scrollToTime(); this.updateTime(); }, }; -- GitLab From c6b92e3aae22cb08d5f2e5983707b5689f804908 Mon Sep 17 00:00:00 2001 From: Julian Leucker <leuckerj@gmail.com> Date: Fri, 15 Nov 2024 14:29:42 +0100 Subject: [PATCH 2/3] Correctly calculate the first event time --- aleksis/core/frontend/components/calendar/Calendar.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aleksis/core/frontend/components/calendar/Calendar.vue b/aleksis/core/frontend/components/calendar/Calendar.vue index 648cc12be..144a5b0c1 100644 --- a/aleksis/core/frontend/components/calendar/Calendar.vue +++ b/aleksis/core/frontend/components/calendar/Calendar.vue @@ -353,8 +353,12 @@ export default { this.getMinutesAfterMidnight(event.startDateTime), ); - const minTime = + let minTime = minuteTimes.length > 0 ? Math.min.apply(Math, minuteTimes) : 0; + + // instead of first time take the previous full hour + minTime = Math.floor(Math.max(0, minTime - 1) / 60) * 60; + this.firstTime = minTime; if (!this.scrolled) { -- GitLab From 7b81f89e29c113af03a134c95ea999ca95cc60a1 Mon Sep 17 00:00:00 2001 From: Julian Leucker <leuckerj@gmail.com> Date: Fri, 15 Nov 2024 14:44:02 +0100 Subject: [PATCH 3/3] Offset calendar scrolling by firstTime of cal --- .../core/frontend/components/calendar/Calendar.vue | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aleksis/core/frontend/components/calendar/Calendar.vue b/aleksis/core/frontend/components/calendar/Calendar.vue index 144a5b0c1..f66c3421e 100644 --- a/aleksis/core/frontend/components/calendar/Calendar.vue +++ b/aleksis/core/frontend/components/calendar/Calendar.vue @@ -361,7 +361,8 @@ export default { this.firstTime = minTime; - if (!this.scrolled) { + // When events are loaded, scroll once + if (!this.scrolled && minuteTimes.length > 0) { this.scrollToTime(); } }, @@ -489,9 +490,15 @@ export default { }, scrollToTime() { const time = this.getCurrentTime(); - const first = Math.max(0, time - (time % 30) - 30); + let first = Math.max(0, time - (time % 30) - 30); + + if (this.startWithFirstTime) { + first = first - this.firstTime; + } this.cal.scrollToTime(first); + + this.scrolled = true; }, updateTime() { // TODO: is this destroyed when unloading? -- GitLab