feat: add caching for backend objects
This commit is contained in:
26
app/composables/useBookingDraft.ts
Normal file
26
app/composables/useBookingDraft.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { Database } from '~/types/supabase'
|
||||
|
||||
type Boat = Database['public']['Tables']['boats']['Row']
|
||||
|
||||
export interface BookingDraft {
|
||||
boat: Boat
|
||||
startTime: string
|
||||
endTime: string
|
||||
}
|
||||
|
||||
const _draft = ref<BookingDraft | null>(null)
|
||||
|
||||
export function useBookingDraft() {
|
||||
function set(boat: Boat, startTime: string, endTime: string): void {
|
||||
_draft.value = { boat, startTime, endTime }
|
||||
}
|
||||
|
||||
/** Reads and clears the draft — call once in the destination page. */
|
||||
function take(): BookingDraft | null {
|
||||
const val = _draft.value
|
||||
_draft.value = null
|
||||
return val
|
||||
}
|
||||
|
||||
return { set, take }
|
||||
}
|
||||
Reference in New Issue
Block a user