Add home screen with recent scans
This commit is contained in:
1 parent
273ed3a632
commit
ac4c45bb36
1 file changed
+83
@@ -0,0 +1,83 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { api, type ScanSummary } from '../lib/api';
|
||||||
|
import { app } from '../lib/state.svelte';
|
||||||
|
import { monthLabel } from '../lib/dates';
|
||||||
|
import StatusBadge from './StatusBadge.svelte';
|
||||||
|
|
||||||
|
let scans = $state<ScanSummary[] | null>(null);
|
||||||
|
let error = $state('');
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
try {
|
||||||
|
scans = await api<ScanSummary[]>('/scans');
|
||||||
|
} catch (e: any) {
|
||||||
|
error = e.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
load();
|
||||||
|
|
||||||
|
// Keep the list fresh while a page is being read.
|
||||||
|
$effect(() => {
|
||||||
|
if (!scans?.some((s) => s.status === 'queued')) return;
|
||||||
|
const t = setInterval(load, 4000);
|
||||||
|
return () => clearInterval(t);
|
||||||
|
});
|
||||||
|
|
||||||
|
const h = $derived(app.household!);
|
||||||
|
const setup = $derived([
|
||||||
|
{ done: h.children.length > 0, text: 'Add your children' },
|
||||||
|
{ done: h.sources.length > 0, text: 'Add the paper calendars and menus you get (sources)' },
|
||||||
|
{ done: h.calendars.length > 0, text: 'Add a calendar to send events to' },
|
||||||
|
]);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>ParentCalendar</h1>
|
||||||
|
|
||||||
|
{#if setup.some((s) => !s.done)}
|
||||||
|
<section class="card stack">
|
||||||
|
<h2 style="margin-top:0">Get started</h2>
|
||||||
|
<ol>
|
||||||
|
{#each setup as step}
|
||||||
|
<li class:done={step.done}>{step.text}</li>
|
||||||
|
{/each}
|
||||||
|
</ol>
|
||||||
|
<a class="button" href="#/settings">Open settings</a>
|
||||||
|
</section>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<a class="button primary scan" href="#/new">
|
||||||
|
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 8a2 2 0 0 1 2-2h2l2-2h4l2 2h2a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zM12 17a4 4 0 1 0 0-8 4 4 0 0 0 0 8z" /></svg>
|
||||||
|
Scan a calendar or menu
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<h2>Recent scans</h2>
|
||||||
|
{#if error}
|
||||||
|
<p class="error">{error}</p>
|
||||||
|
{:else if scans === null}
|
||||||
|
<p class="muted">Loading…</p>
|
||||||
|
{:else if scans.length === 0}
|
||||||
|
<p class="empty">No scans yet.</p>
|
||||||
|
{:else}
|
||||||
|
<ul class="list">
|
||||||
|
{#each scans as s (s.id)}
|
||||||
|
<li>
|
||||||
|
<a class="card row spread" href={`#/scan/${s.id}`}>
|
||||||
|
<span>
|
||||||
|
<strong>{s.source_name}</strong><br />
|
||||||
|
<span class="muted small">{monthLabel(s.hint_month)} · {s.event_count} events</span>
|
||||||
|
</span>
|
||||||
|
<StatusBadge status={s.status} />
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{/each}
|
||||||
|
</ul>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.scan { width: 100%; min-height: 56px; font-size: 1.05rem; margin-top: 8px; }
|
||||||
|
.scan svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
|
||||||
|
ol { margin: 0; padding-left: 20px; }
|
||||||
|
li.done { color: var(--muted); text-decoration: line-through; }
|
||||||
|
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||||
|
.list a { color: var(--text); text-decoration: none; min-height: 56px; }
|
||||||
|
</style>
|
||||||
Reference in new issue
Block a user