From b0921ccf32797747d6d8cfa97b226cdb5d97e81b Mon Sep 17 00:00:00 2001 From: Patrick Toal Date: Mon, 13 May 2024 12:31:27 -0400 Subject: [PATCH] refactor utils --- src/pages/schedule/BoatReservationPage.vue | 5 ++--- src/pages/schedule/ManageCalendar.vue | 2 +- src/stores/schedule.ts | 14 +------------- src/utils/misc.ts | 11 +++++++++++ 4 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 src/utils/misc.ts diff --git a/src/pages/schedule/BoatReservationPage.vue b/src/pages/schedule/BoatReservationPage.vue index 1a0d65a..36682c1 100644 --- a/src/pages/schedule/BoatReservationPage.vue +++ b/src/pages/schedule/BoatReservationPage.vue @@ -101,9 +101,9 @@ import { ref, computed, watch } from 'vue'; import { useAuthStore } from 'src/stores/auth'; import { Boat, useBoatStore } from 'src/stores/boat'; import { date } from 'quasar'; -import { useScheduleStore } from 'src/stores/schedule'; import { Interval } from 'src/stores/schedule.types'; import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue'; +import { getNewId } from 'src/utils/misc'; interface BookingForm { bookingId: string; @@ -118,10 +118,9 @@ interface BookingForm { const auth = useAuthStore(); const dateFormat = 'MMM D, YYYY h:mm A'; const resourceView = ref(true); -const scheduleStore = useScheduleStore(); const timeblock = ref(); const bookingForm = ref({ - bookingId: scheduleStore.getNewId(), + bookingId: getNewId(), name: auth.currentUser?.name, boat: undefined, startDate: date.formatDate(new Date(), dateFormat), diff --git a/src/pages/schedule/ManageCalendar.vue b/src/pages/schedule/ManageCalendar.vue index 291927a..d0ea138 100644 --- a/src/pages/schedule/ManageCalendar.vue +++ b/src/pages/schedule/ManageCalendar.vue @@ -145,9 +145,9 @@ import { blocksOverlapped, buildInterval, useScheduleStore, - buildISODate, } from 'src/stores/schedule'; import { onMounted, ref } from 'vue'; +import { buildISODate } from 'src/utils/misc'; import type { Interval, IntervalTemplate, diff --git a/src/stores/schedule.ts b/src/stores/schedule.ts index 69673d1..aa7e7da 100644 --- a/src/stores/schedule.ts +++ b/src/stores/schedule.ts @@ -16,6 +16,7 @@ import { } from './schedule.types'; import { AppwriteIds, databases } from 'src/boot/appwrite'; import { ID, Models } from 'appwrite'; +import { buildISODate } from 'src/utils/misc'; export function arrayToTimeTuples(arr: string[]) { const timeTuples: TimeTuple[] = []; @@ -65,10 +66,6 @@ export function copyIntervalTemplate( }; } -export function buildISODate(date: string, time: string | null): string { - return new Date(date + 'T' + time || '00:00').toISOString(); -} - export function buildInterval( resource: Boat, time: TimeTuple, @@ -212,14 +209,6 @@ export const useScheduleStore = defineStore('schedule', () => { ); }; - const getNewId = (): string => { - return [...Array(20)] - .map(() => Math.floor(Math.random() * 16).toString(16)) - .join(''); - // Trivial placeholder - //return Math.max(...reservations.value.map((item) => item.id)) + 1; - }; - const addOrCreateReservation = (reservation: Reservation) => { const index = reservations.value.findIndex( (res) => res.id == reservation.id @@ -339,7 +328,6 @@ export const useScheduleStore = defineStore('schedule', () => { getIntervals, fetchIntervals, fetchIntervalTemplates, - getNewId, createInterval, updateInterval, deleteInterval, diff --git a/src/utils/misc.ts b/src/utils/misc.ts new file mode 100644 index 0000000..f0402e1 --- /dev/null +++ b/src/utils/misc.ts @@ -0,0 +1,11 @@ +export function buildISODate(date: string, time: string | null): string { + return new Date(date + 'T' + time || '00:00').toISOString(); +} + +export function getNewId(): string { + return [...Array(20)] + .map(() => Math.floor(Math.random() * 16).toString(16)) + .join(''); + // Trivial placeholder + //return Math.max(...reservations.value.map((item) => item.id)) + 1; +}