Files
garage/frontend/src/routes/Garage.svelte
T
2026-08-06 19:00:08 +12:00

62 lines
1.8 KiB
Svelte

<script>
import { onMount } from 'svelte'
import { apiGet } from '../lib/api.js'
import { btnPrimary, card, sectionCard, sectionHeading } from '../lib/ui.js'
import Icon from '../lib/components/Icon.svelte'
import CarCard from '../lib/components/CarCard.svelte'
import RemindersPanel from '../lib/components/RemindersPanel.svelte'
import LoadingState from '../lib/components/LoadingState.svelte'
let cars = $state([])
let loading = $state(true)
let error = $state('')
onMount(async () => {
try {
cars = await apiGet('/cars')
} catch (err) {
error = err.message
} finally {
loading = false
}
})
</script>
<div class="space-y-8">
<section class={sectionCard}>
<h2 class="{sectionHeading} mb-3">Coming up</h2>
<RemindersPanel />
</section>
<section>
<div class="mb-4 flex items-center justify-between">
<h2 class="text-lg font-semibold tracking-tight text-stone-900">Your garage</h2>
<a href="#/cars/new" class={btnPrimary}>
<Icon name="plus" class="h-4 w-4" />
Add car
</a>
</div>
{#if loading}
<LoadingState />
{:else if error}
<p class="text-sm text-red-600">{error}</p>
{:else if cars.length === 0}
<div class="{card} flex flex-col items-center gap-3 px-6 py-12 text-center">
<span class="text-4xl">🚗</span>
<p class="text-sm text-stone-500">No cars yet — add your first one to get started.</p>
<a href="#/cars/new" class={btnPrimary}>
<Icon name="plus" class="h-4 w-4" />
Add car
</a>
</div>
{:else}
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
{#each cars as car (car.id)}
<CarCard {car} />
{/each}
</div>
{/if}
</section>
</div>