24 lines
635 B
TypeScript
24 lines
635 B
TypeScript
import { defineStore } from 'pinia'
|
|
|
|
// TODO: Replace with generated Supabase types after `npx supabase gen types typescript`
|
|
interface Boat {
|
|
id: string
|
|
name: string
|
|
description: string | null
|
|
active: boolean
|
|
created_at: string
|
|
}
|
|
|
|
export const useBoatStore = defineStore('boat', () => {
|
|
const supabase = useSupabaseClient()
|
|
const boats = ref<Map<string, Boat>>(new Map())
|
|
|
|
async function fetchBoats() {
|
|
const { data, error } = await supabase.from('boats').select('*').order('name')
|
|
if (error) throw error
|
|
boats.value = new Map((data as Boat[]).map((b) => [b.id, b]))
|
|
}
|
|
|
|
return { boats, fetchBoats }
|
|
})
|