diff --git a/src/App.vue b/src/App.vue index 3dd5266..698d4cc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,17 +2,21 @@ - diff --git a/src/pages/schedule/ManageCalendar.vue b/src/pages/schedule/ManageCalendar.vue index 81c79b1..f3c66a6 100644 --- a/src/pages/schedule/ManageCalendar.vue +++ b/src/pages/schedule/ManageCalendar.vue @@ -1,38 +1,52 @@ @@ -40,8 +54,11 @@ diff --git a/src/stores/sampledata/schedule.ts b/src/stores/sampledata/schedule.ts index 962b8e3..cdb79a5 100644 --- a/src/stores/sampledata/schedule.ts +++ b/src/stores/sampledata/schedule.ts @@ -12,12 +12,13 @@ import type { Reservation, TimeBlockTemplate, Timeblock, + TimeTuple, } from '../schedule.types'; export const templateA: TimeBlockTemplate = { id: '1', name: 'WeekdayBlocks', - blocks: [ + timeTuple: [ ['08:00', '12:00'], ['12:00', '16:00'], ['17:00', '21:00'], @@ -27,7 +28,7 @@ export const templateA: TimeBlockTemplate = { export const templateB: TimeBlockTemplate = { id: '2', name: 'WeekendBlocks', - blocks: [ + timeTuple: [ ['07:00', '10:00'], ['10:00', '13:00'], ['13:00', '16:00'], @@ -46,7 +47,7 @@ export function getSampleTimeBlocks(): Timeblock[] { result.push( ...boats.value .map((b): Timeblock[] => { - return template.blocks.map((t): Timeblock => { + return template.blocks.map((t: TimeTuple): Timeblock => { return { $id: 'id' + Math.random().toString(32).slice(2), boatId: b.$id, diff --git a/src/stores/schedule.ts b/src/stores/schedule.ts index 14f5a5c..0fb54b0 100644 --- a/src/stores/schedule.ts +++ b/src/stores/schedule.ts @@ -8,13 +8,19 @@ import { compareDate, } from '@quasar/quasar-ui-qcalendar'; -import { Reservation, Timeblock } from './schedule.types'; +import { + Reservation, + TimeBlockTemplate, + TimeTuple, + Timeblock, +} from './schedule.types'; import { AppwriteIds, databases } from 'src/boot/appwrite'; export const useScheduleStore = defineStore('schedule', () => { // TODO: Implement functions to dynamically pull this data. const reservations = ref([]); const timeblocks = ref([]); + const timeblockTemplates = ref([]); const getTimeblocksForDate = (date: string): Timeblock[] => { // TODO: This needs to actually make sure we have the dates we need, stay in sync, etc. @@ -55,6 +61,25 @@ export const useScheduleStore = defineStore('schedule', () => { console.error('Failed to fetch timeblocks', error); } } + + async function fetchTimeBlockTemplates() { + try { + const response = await databases.listDocuments( + AppwriteIds.databaseId, + AppwriteIds.collection.timeBlockTemplate + ); + const res = response.documents.map((d) => { + const timeTuples: TimeTuple[] = []; + for (let i = 0; i < d.timeTuple.length; i += 2) { + timeTuples.push([d.timeTuple[i], d.timeTuple[i + 1]]); + } + return { ...d, timeTuple: timeTuples }; + }) as TimeBlockTemplate[]; + timeblockTemplates.value = res; + } catch (error) { + console.error('Failed to fetch timeblock templates', error); + } + } // const getConflicts = (timeblock: Timeblock, boat: Boat) => { // const start = date.buildDate({ // hour: timeblock.start.hour, @@ -117,10 +142,12 @@ export const useScheduleStore = defineStore('schedule', () => { return { reservations, timeblocks, + timeblockTemplates, getBoatReservations, getConflictingReservations, getTimeblocksForDate, fetchTimeBlocks, + fetchTimeBlockTemplates, getNewId, addOrCreateReservation, isReservationOverlapped, diff --git a/src/stores/schedule.types.ts b/src/stores/schedule.types.ts index dfba260..f9a0d20 100644 --- a/src/stores/schedule.types.ts +++ b/src/stores/schedule.types.ts @@ -17,7 +17,7 @@ export interface Reservation { e.g.: Should there be any qcalendar stuff in this store? Or should we have just JS Date objects in here? */ -export type timeTuple = [start: string, end: string]; +export type TimeTuple = [start: string, end: string]; export type Timeblock = Partial & { boatId: string; start: string; @@ -25,8 +25,7 @@ export type Timeblock = Partial & { selected?: false; }; -export interface TimeBlockTemplate { - id: string; +export type TimeBlockTemplate = Partial & { name: string; - blocks: timeTuple[]; -} + timeTuple: TimeTuple[]; +};