Initial project scaffolding
This commit is contained in:
23
app/stores/boat.ts
Normal file
23
app/stores/boat.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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 }
|
||||
})
|
||||
Reference in New Issue
Block a user