Add app shell and navigation

This commit is contained in:
iamdoubz committed 2026-11-05 16:08:38 -06:00
1 parent bb032b9512
commit 6201730be9
1 file changed
+99
+99
View File
@@ -0,0 +1,99 @@
<script lang="ts">
import { app, loadHousehold } from './lib/state.svelte';
import Home from './routes/Home.svelte';
import NewScan from './routes/NewScan.svelte';
import ScanPage from './routes/ScanPage.svelte';
import CalendarPage from './routes/CalendarPage.svelte';
import LunchPage from './routes/LunchPage.svelte';
import SettingsPage from './routes/SettingsPage.svelte';
let error = $state('');
loadHousehold().catch((e) => (error = e.message));
const path = $derived(app.route.replace(/^#/, '') || '/');
const scanId = $derived(path.match(/^\/scan\/(\d+)$/)?.[1]);
const tabs = [
{ href: '#/', label: 'Scans', match: (p: string) => p === '/' || p === '/new' || p.startsWith('/scan/'),
icon: 'M4 7V5a1 1 0 0 1 1-1h2M17 4h2a1 1 0 0 1 1 1v2M20 17v2a1 1 0 0 1-1 1h-2M7 20H5a1 1 0 0 1-1-1v-2M8 12h8' },
{ href: '#/calendar', label: 'Calendar', match: (p: string) => p === '/calendar',
icon: 'M5 6h14a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1zM4 10h16M8 3v4M16 3v4' },
{ href: '#/lunch', label: 'Lunch', match: (p: string) => p === '/lunch',
icon: 'M6 3v8a2 2 0 0 0 2 2v8M10 3v8M8 3v8M16 21V3c2 1 3 4 3 8h-3' },
{ href: '#/settings', label: 'Settings', match: (p: string) => p === '/settings',
icon: 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19.4 15a1.6 1.6 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.6 1.6 0 0 0-1.5 1z' },
];
</script>
<main>
{#if error}
<p class="error">Can't reach the ParentCalendar server: {error}</p>
{:else if !app.household}
<p class="muted">Loading…</p>
{:else if path === '/new'}
<NewScan />
{:else if scanId}
{#key scanId}<ScanPage id={Number(scanId)} />{/key}
{:else if path === '/calendar'}
<CalendarPage />
{:else if path === '/lunch'}
<LunchPage />
{:else if path === '/settings'}
<SettingsPage />
{:else}
<Home />
{/if}
</main>
<nav aria-label="Main">
{#each tabs as tab}
<a href={tab.href} aria-current={tab.match(path) ? 'page' : undefined}>
<svg viewBox="0 0 24 24" aria-hidden="true"><path d={tab.icon} /></svg>
<span>{tab.label}</span>
</a>
{/each}
</nav>
{#if app.toast}
<div class="toast" role="status">{app.toast}</div>
{/if}
<style>
nav {
position: fixed;
inset: auto 0 0 0;
display: flex;
justify-content: center;
background: var(--surface);
border-top: 1px solid var(--border);
padding-bottom: env(safe-area-inset-bottom);
z-index: 10;
}
nav a {
flex: 1;
max-width: 160px;
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
padding: 8px 4px;
min-height: 56px;
color: var(--muted);
text-decoration: none;
font-size: 0.75rem;
}
nav a[aria-current='page'] { color: var(--accent); font-weight: 600; }
nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.toast {
position: fixed;
left: 50%;
bottom: calc(72px + env(safe-area-inset-bottom));
transform: translateX(-50%);
background: var(--text);
color: var(--bg);
padding: 10px 16px;
border-radius: 10px;
max-width: calc(100vw - 32px);
z-index: 20;
box-shadow: var(--shadow);
}
</style>