Redesign scan page states
This commit is contained in:
1 parent
e3a6b92026
commit
7d9692932f
1 file changed
+80
-43
@@ -1,7 +1,16 @@
|
||||
<script lang="ts">
|
||||
import CalendarDays from '@lucide/svelte/icons/calendar-days';
|
||||
import CircleAlert from '@lucide/svelte/icons/circle-alert';
|
||||
import CircleCheck from '@lucide/svelte/icons/circle-check';
|
||||
import Download from '@lucide/svelte/icons/download';
|
||||
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
|
||||
import RefreshCw from '@lucide/svelte/icons/refresh-cw';
|
||||
import Sandwich from '@lucide/svelte/icons/sandwich';
|
||||
import Trash2 from '@lucide/svelte/icons/trash-2';
|
||||
import { api, type Scan } from '../lib/api';
|
||||
import { app, go, toast } from '../lib/state.svelte';
|
||||
import { monthLabel } from '../lib/dates';
|
||||
import PageHeader from '../lib/ui/PageHeader.svelte';
|
||||
import StatusBadge from './StatusBadge.svelte';
|
||||
import Review from './Review.svelte';
|
||||
|
||||
@@ -9,6 +18,7 @@
|
||||
let scan = $state<Scan | null>(null);
|
||||
let error = $state('');
|
||||
let confirmDiscard = $state(false);
|
||||
let retrying = $state(false);
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
@@ -26,12 +36,23 @@
|
||||
});
|
||||
|
||||
async function retry() {
|
||||
scan = await api<Scan>(`/scans/${id}/retry`, { method: 'POST' });
|
||||
retrying = true;
|
||||
try {
|
||||
scan = await api<Scan>(`/scans/${id}/retry`, { method: 'POST' });
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
} finally {
|
||||
retrying = false;
|
||||
}
|
||||
}
|
||||
async function discard() {
|
||||
await api(`/scans/${id}`, { method: 'DELETE' });
|
||||
toast('Scan discarded');
|
||||
go('#/');
|
||||
try {
|
||||
await api(`/scans/${id}`, { method: 'DELETE' });
|
||||
toast('Scan discarded');
|
||||
go('#/');
|
||||
} catch (e: any) {
|
||||
toast(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
const calendars = $derived.by(() => {
|
||||
@@ -44,63 +65,79 @@
|
||||
</script>
|
||||
|
||||
{#if error}
|
||||
<p class="error">{error}</p>
|
||||
<PageHeader title="Scan" back="#/" />
|
||||
<div class="alert error" role="alert"><CircleAlert size={18} aria-hidden="true" /><span>{error}</span></div>
|
||||
{:else if !scan}
|
||||
<p class="muted">Loading…</p>
|
||||
{:else}
|
||||
<div class="row spread">
|
||||
<h1>{scan.source_name} <span class="muted">· {monthLabel(scan.hint_month)}</span></h1>
|
||||
<StatusBadge status={scan.status} />
|
||||
<div class="stack" aria-busy="true" aria-label="Loading scan">
|
||||
<div class="skeleton" style="height:48px;width:60%"></div>
|
||||
<div class="skeleton" style="height:240px"></div>
|
||||
</div>
|
||||
{:else}
|
||||
<PageHeader title={scan.source_name} subtitle={monthLabel(scan.hint_month)} back="#/">
|
||||
{#snippet actions()}<StatusBadge status={scan!.status} />{/snippet}
|
||||
</PageHeader>
|
||||
|
||||
{#if scan.status === 'queued'}
|
||||
<div class="card stack" aria-live="polite">
|
||||
<p><span class="spinner" aria-hidden="true"></span> Reading the page. This usually takes under a minute; you can leave this screen.</p>
|
||||
</div>
|
||||
<section class="card state" aria-live="polite">
|
||||
<span class="state-icon info"><LoaderCircle size={28} class="spin" aria-hidden="true" /></span>
|
||||
<h2>Reading the page</h2>
|
||||
<p class="muted">This usually takes under a minute. You can leave this screen; the scan waits on the Scans tab.</p>
|
||||
</section>
|
||||
{:else if scan.status === 'failed'}
|
||||
<div class="card stack">
|
||||
<p class="error">Reading failed: {scan.error}</p>
|
||||
<section class="card state">
|
||||
<span class="state-icon danger"><CircleAlert size={28} aria-hidden="true" /></span>
|
||||
<h2>Reading failed</h2>
|
||||
<p class="muted small">{scan.error}</p>
|
||||
<div class="row">
|
||||
<button class="primary" onclick={retry}>Try again</button>
|
||||
<button onclick={discard}>Discard</button>
|
||||
<button class="primary" onclick={retry} disabled={retrying}><RefreshCw size={18} aria-hidden="true" /> Try again</button>
|
||||
<button onclick={discard}><Trash2 size={18} aria-hidden="true" /> Discard</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{:else if scan.status === 'abandoned'}
|
||||
<p class="card">This scan was discarded.</p>
|
||||
<section class="card state">
|
||||
<span class="state-icon"><Trash2 size={28} aria-hidden="true" /></span>
|
||||
<h2>Discarded</h2>
|
||||
<p class="muted">This scan was discarded. Nothing from it reached your calendar.</p>
|
||||
</section>
|
||||
{:else if scan.status === 'published'}
|
||||
<div class="card stack">
|
||||
<p>Published {scan.events.length} events{scan.menu_items.length ? ` and ${scan.menu_items.length} menu days` : ''}.</p>
|
||||
{#if scan.layout_type === 'menu'}
|
||||
<a class="button primary" href="#/lunch">Pick lunch days</a>
|
||||
{/if}
|
||||
{#each calendars as c (c.id)}
|
||||
<div class="row">
|
||||
<a class="button" href={`/api/calendars/${c.id}/export.ics`} download>Download new events for {c.name} (.ics)</a>
|
||||
</div>
|
||||
{/each}
|
||||
<a href="#/calendar">See the calendar</a>
|
||||
</div>
|
||||
<section class="card state">
|
||||
<span class="state-icon ok"><CircleCheck size={28} aria-hidden="true" /></span>
|
||||
<h2>Published</h2>
|
||||
<p class="muted">
|
||||
{scan.events.length} {scan.events.length === 1 ? 'event' : 'events'}{scan.menu_items.length ? ` and ${scan.menu_items.length} menu days` : ''} are on your calendar.
|
||||
</p>
|
||||
<div class="actions">
|
||||
{#if scan.layout_type === 'menu'}
|
||||
<a class="btn primary" href="#/lunch"><Sandwich size={18} aria-hidden="true" /> Pick lunch days</a>
|
||||
{/if}
|
||||
{#each calendars as c, i (c.id)}
|
||||
<a class="btn" class:primary={i === 0 && scan.layout_type !== 'menu'} href={`/api/calendars/${c.id}/export.ics`} download>
|
||||
<Download size={18} aria-hidden="true" /> Download for {c.name}
|
||||
</a>
|
||||
{/each}
|
||||
<a class="btn ghost" href="#/calendar"><CalendarDays size={18} aria-hidden="true" /> See the calendar</a>
|
||||
</div>
|
||||
</section>
|
||||
{:else}
|
||||
<Review bind:scan />
|
||||
<div class="discard">
|
||||
{#if confirmDiscard}
|
||||
<button class="danger" onclick={discard}>Discard this scan</button>
|
||||
<button class="quiet" onclick={() => (confirmDiscard = false)}>Keep it</button>
|
||||
<button class="danger solid" onclick={discard}><Trash2 size={18} aria-hidden="true" /> Discard this scan</button>
|
||||
<button class="ghost" onclick={() => (confirmDiscard = false)}>Keep it</button>
|
||||
{:else}
|
||||
<button class="quiet" onclick={() => (confirmDiscard = true)}>Discard scan…</button>
|
||||
<button class="ghost" onclick={() => (confirmDiscard = true)}><Trash2 size={18} aria-hidden="true" /> Discard scan…</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
h1 { margin-bottom: 8px; }
|
||||
.discard { margin-top: 32px; display: flex; gap: 8px; }
|
||||
.spinner {
|
||||
display: inline-block; width: 16px; height: 16px; margin-right: 6px; vertical-align: -2px;
|
||||
border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
|
||||
animation: spin 0.8s linear infinite;
|
||||
}
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
|
||||
.state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s3); padding: var(--s6) var(--s4); }
|
||||
.state-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--surface-2); color: var(--text-2); }
|
||||
.state-icon.info { background: var(--info-soft); color: var(--info); }
|
||||
.state-icon.ok { background: var(--ok-soft); color: var(--ok); }
|
||||
.state-icon.danger { background: var(--danger-soft); color: var(--danger); }
|
||||
.state p { max-width: 48ch; }
|
||||
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--s2); margin-top: var(--s2); }
|
||||
.discard { margin-top: var(--s6); padding-top: var(--s4); border-top: 1px solid var(--border); display: flex; gap: var(--s2); }
|
||||
</style>
|
||||
Reference in new issue
Block a user