From b506ab7ca9b8419f8892ec4e12e0ed459f5d90aa Mon Sep 17 00:00:00 2001 From: Patrick Toal Date: Fri, 17 May 2024 18:17:25 -0400 Subject: [PATCH] Many changes to try to improve reliability --- docs/time.md | 20 +++ .../ResourceScheduleViewerComponent.vue | 5 +- .../boat/BoatScheduleTableComponent.vue | 8 +- src/pages/schedule/BoatScheduleView.vue | 9 +- src/pages/schedule/ManageCalendar.vue | 143 ++++++++++-------- src/stores/auth.ts | 12 +- src/stores/reservation.ts | 92 +++++++---- src/stores/schedule.ts | 54 ++++--- src/stores/schedule.types.ts | 4 +- src/stores/task.ts | 1 - src/utils/misc.ts | 4 - 11 files changed, 218 insertions(+), 134 deletions(-) create mode 100644 docs/time.md diff --git a/docs/time.md b/docs/time.md new file mode 100644 index 0000000..1c7eb28 --- /dev/null +++ b/docs/time.md @@ -0,0 +1,20 @@ +# Dealing with Time + +Dealing with time sucks, okay? We have three different formats we need to deal with: + +1. ES Date - The native ECMAScript Date object. This is saddled with all the legacy of the decades. Hopefully, we will be able to retire this one day... Ref: https://tc39.es/proposal-temporal/docs/index.html +2. ISO 8601 Date - Used by Appwrite backend. This is just a string, but can represent any date, with or without a timezone. +3. Timestamp - Used internally by QCalendar. + +We can't just use one format. We need ISO8601 format for Appwrite, and we get passed Timestamp objects by QCalendar. In the middle of that, we need ES Date objects to do some underlying math. + +Componentization: +In order to make things clean and modular, we will rely on Timestamp as the main format in a component. + +In data that comes from, or goes to the backend, we will store absolute dates in ISO format. + +For any user-facing dates / times, the data will be rendered in the users local time. + +For time-only data (as used in Intervals, eg: '09:00'), the template will be stored as a string of 'hh:mm', and represent the users local time. We may want to change this in the future, as this could prove a problem when a user is travelling, but wants to apply a template to their home location. + +For now, we'll use the Timestamp object provided by QCalendar. We might need to refactor this in the future. diff --git a/src/components/ResourceScheduleViewerComponent.vue b/src/components/ResourceScheduleViewerComponent.vue index 6d85056..f8fdcca 100644 --- a/src/components/ResourceScheduleViewerComponent.vue +++ b/src/components/ResourceScheduleViewerComponent.vue @@ -107,7 +107,6 @@ import { QCalendarResource, TimestampOrNull, today, - parseDate, parseTimestamp, addToDate, Timestamp, @@ -172,8 +171,8 @@ function monthFormatter() { } function getEvents(scope: ResourceIntervalScope) { - const resourceEvents = reservationStore.getBoatReservations( - parseDate(date.extractDate(selectedDate.value, 'YYYY-MM-DD')) as Timestamp, + const resourceEvents = reservationStore.getReservationsByDate( + selectedDate.value, scope.resource.$id ); diff --git a/src/components/scheduling/boat/BoatScheduleTableComponent.vue b/src/components/scheduling/boat/BoatScheduleTableComponent.vue index 4ac93d2..b73e4e3 100644 --- a/src/components/scheduling/boat/BoatScheduleTableComponent.vue +++ b/src/components/scheduling/boat/BoatScheduleTableComponent.vue @@ -70,6 +70,7 @@ import { parseTimestamp, parseDate, addToDate, + getDate, } from '@quasar/quasar-ui-qcalendar'; import CalendarHeaderComponent from './CalendarHeaderComponent.vue'; @@ -189,13 +190,13 @@ function getBoatBlocks(scope: DayBodyScope): Interval[] { function getBoatReservations(scope: DayBodyScope): Reservation[] { const boat = boats.value[scope.columnIndex]; return boat - ? reservationStore.getBoatReservations(scope.timestamp, boat.$id) + ? reservationStore.getReservationsByDate(getDate(scope.timestamp), boat.$id) : []; } // function changeEvent({ start }: { start: string }) { // const newBlocks = scheduleStore.getIntervalsForDate(start); -// const reservations = scheduleStore.getBoatReservations( +// const reservations = scheduleStore.getReservationsByDate( // parsed(start) as Timestamp // ); // boats.value.map((boat) => { @@ -268,4 +269,7 @@ const disabledBefore = computed(() => { font-size: 0.8em .q-calendar-day__day.q-current-day padding: 1px +.q-calendar-day__head--days__column + background: $primary + color: white diff --git a/src/pages/schedule/BoatScheduleView.vue b/src/pages/schedule/BoatScheduleView.vue index 13a2acd..d3f4284 100644 --- a/src/pages/schedule/BoatScheduleView.vue +++ b/src/pages/schedule/BoatScheduleView.vue @@ -56,7 +56,12 @@ import { useReservationStore } from 'src/stores/reservation'; import { Reservation } from 'src/stores/schedule.types'; import { ref } from 'vue'; const reservationStore = useReservationStore(); -import { TimestampOrNull, parsed, today } from '@quasar/quasar-ui-qcalendar'; +import { + TimestampOrNull, + getDate, + parsed, + today, +} from '@quasar/quasar-ui-qcalendar'; import { QCalendarDay } from '@quasar/quasar-ui-qcalendar'; import { date } from 'quasar'; import { Timestamp } from '@quasar/quasar-ui-qcalendar'; @@ -87,7 +92,7 @@ function slotStyle( } function reservationEvents(timestamp: Timestamp) { - return reservationStore.getBoatReservations(timestamp); + return reservationStore.getReservationsByDate(getDate(timestamp)); } function onMoved(data: Event) { console.log('onMoved', data); diff --git a/src/pages/schedule/ManageCalendar.vue b/src/pages/schedule/ManageCalendar.vue index d0ea138..8f30367 100644 --- a/src/pages/schedule/ManageCalendar.vue +++ b/src/pages/schedule/ManageCalendar.vue @@ -23,7 +23,7 @@ >