Redesign new scan screen with source cards and photo previews
This commit is contained in:
1 parent
61f37ac942
commit
e3a6b92026
1 file changed
+101
-23
@@ -1,21 +1,40 @@
|
||||
<script lang="ts">
|
||||
import CircleAlert from '@lucide/svelte/icons/circle-alert';
|
||||
import FileText from '@lucide/svelte/icons/file-text';
|
||||
import ImagePlus from '@lucide/svelte/icons/image-plus';
|
||||
import LoaderCircle from '@lucide/svelte/icons/loader-circle';
|
||||
import Settings from '@lucide/svelte/icons/settings';
|
||||
import Sparkles from '@lucide/svelte/icons/sparkles';
|
||||
import { app, go } from '../lib/state.svelte';
|
||||
import { thisMonth } from '../lib/dates';
|
||||
import { LAYOUT_ICONS } from '../lib/icons';
|
||||
import PageHeader from '../lib/ui/PageHeader.svelte';
|
||||
import EmptyState from '../lib/ui/EmptyState.svelte';
|
||||
|
||||
const sources = $derived(app.household!.sources);
|
||||
let sourceId = $state<number | ''>('');
|
||||
const layoutNames = { month_grid: 'Month calendar', menu: 'Lunch menu', list: 'Flyer or list' } as const;
|
||||
let sourceId = $state<number | null>(null);
|
||||
let month = $state(thisMonth());
|
||||
let files = $state<FileList | null>(null);
|
||||
let busy = $state(false);
|
||||
let error = $state('');
|
||||
|
||||
$effect(() => {
|
||||
if (sourceId === '' && sources.length === 1) sourceId = sources[0].id;
|
||||
if (sourceId === null && sources.length === 1) sourceId = sources[0].id;
|
||||
});
|
||||
|
||||
// Small previews of the chosen photos; object URLs are released when the selection changes.
|
||||
const previews = $derived(
|
||||
[...(files ?? [])].map((f) => ({ name: f.name, url: f.type.startsWith('image/') ? URL.createObjectURL(f) : null })),
|
||||
);
|
||||
$effect(() => {
|
||||
const urls = previews.map((p) => p.url).filter(Boolean) as string[];
|
||||
return () => urls.forEach((u) => URL.revokeObjectURL(u));
|
||||
});
|
||||
|
||||
async function submit(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
if (!files?.length || sourceId === '') return;
|
||||
if (!files?.length || sourceId === null) return;
|
||||
busy = true;
|
||||
error = '';
|
||||
const form = new FormData();
|
||||
@@ -35,34 +54,93 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1>New scan</h1>
|
||||
<PageHeader title="New scan" subtitle="The photo is read on your own server, then you review what was found." back="#/" />
|
||||
|
||||
{#if sources.length === 0}
|
||||
<p class="card">First add a source (the school calendar, a menu, a team schedule) in <a href="#/settings">Settings</a>.</p>
|
||||
<EmptyState icon={Settings} title="Add a source first">
|
||||
<p>A source is something you scan each month: the district calendar, a lunch menu, a team schedule.</p>
|
||||
<a class="btn primary" href="#/settings">Open settings</a>
|
||||
</EmptyState>
|
||||
{:else}
|
||||
<form class="card stack" onsubmit={submit}>
|
||||
<div>
|
||||
<label for="source">What is it?</label>
|
||||
<select id="source" bind:value={sourceId} required>
|
||||
<option value="" disabled>Choose a source</option>
|
||||
<form class="stack-lg" onsubmit={submit}>
|
||||
<fieldset class="section">
|
||||
<legend class="section-title">1 · What is it?</legend>
|
||||
<div class="sources">
|
||||
{#each sources as s (s.id)}
|
||||
<option value={s.id}>{s.name}</option>
|
||||
{@const Icon = LAYOUT_ICONS[s.layout_type]}
|
||||
<label class="source" class:on={sourceId === s.id}>
|
||||
<input type="radio" class="visually-hidden" name="source" bind:group={sourceId} value={s.id} required />
|
||||
<span class="src-icon"><Icon size={20} aria-hidden="true" /></span>
|
||||
<span class="grow">
|
||||
<span class="src-name">{s.name}</span>
|
||||
<span class="hint">{layoutNames[s.layout_type]}</span>
|
||||
</span>
|
||||
</label>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="section">
|
||||
<label class="section-title" for="month">2 · Month it covers</label>
|
||||
<input id="month" type="month" bind:value={month} required class="month" />
|
||||
<p class="hint">For a page that spans months, pick the first one.</p>
|
||||
</div>
|
||||
<div>
|
||||
<label for="month">Month it covers (the first month, for multi-month pages)</label>
|
||||
<input id="month" type="month" bind:value={month} required />
|
||||
</div>
|
||||
<div>
|
||||
<label for="files">Photo, screenshot or PDF</label>
|
||||
|
||||
<div class="section">
|
||||
<span class="section-title" id="photo-label">3 · Photo, screenshot or PDF</span>
|
||||
<!-- No `capture` attribute: phones then offer both the camera and the photo library. -->
|
||||
<input id="files" type="file" accept="image/*,application/pdf" multiple bind:files required />
|
||||
<p class="muted small">Two-sided sheet? Add both photos. The photo stays on your server.</p>
|
||||
<label class="drop" class:has-files={previews.length}>
|
||||
<input type="file" accept="image/*,application/pdf" multiple bind:files required aria-labelledby="photo-label" />
|
||||
{#if previews.length}
|
||||
<span class="previews">
|
||||
{#each previews as p}
|
||||
{#if p.url}<img src={p.url} alt={p.name} />{:else}<span class="pdf"><FileText size={28} aria-hidden="true" /><span>{p.name}</span></span>{/if}
|
||||
{/each}
|
||||
</span>
|
||||
<span class="hint">Tap to choose different files</span>
|
||||
{:else}
|
||||
<span class="drop-icon"><ImagePlus size={30} aria-hidden="true" /></span>
|
||||
<span class="strong">Take a photo or choose a file</span>
|
||||
<span class="hint">Two-sided sheet? Add both photos.</span>
|
||||
{/if}
|
||||
</label>
|
||||
</div>
|
||||
{#if error}<p class="error">{error}</p>{/if}
|
||||
<button class="primary" type="submit" disabled={busy || !files?.length || sourceId === ''}>
|
||||
{busy ? 'Uploading…' : 'Read it'}
|
||||
|
||||
{#if error}
|
||||
<div class="alert error" role="alert"><CircleAlert size={18} aria-hidden="true" /><span>{error}</span></div>
|
||||
{/if}
|
||||
|
||||
<button class="primary lg block" type="submit" disabled={busy || !files?.length || sourceId === null}>
|
||||
{#if busy}<LoaderCircle size={20} class="spin" aria-hidden="true" /> Uploading…{:else}<Sparkles size={20} aria-hidden="true" /> Read it{/if}
|
||||
</button>
|
||||
</form>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.sources { display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
|
||||
.source {
|
||||
display: flex; align-items: center; gap: var(--s3); min-height: 64px; padding: var(--s3) var(--s4);
|
||||
background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--r-lg); cursor: pointer;
|
||||
transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
|
||||
}
|
||||
.source:hover { border-color: var(--border-strong); }
|
||||
.source.on { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.source:has(:focus-visible) { outline: 3px solid var(--primary); outline-offset: 2px; }
|
||||
.src-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); flex: none; }
|
||||
.source.on .src-icon { background: var(--surface); color: var(--primary-text); }
|
||||
.src-name { display: block; font-weight: 650; }
|
||||
.month { max-width: 260px; }
|
||||
|
||||
.drop {
|
||||
position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2);
|
||||
min-height: 200px; padding: var(--s5); text-align: center; cursor: pointer;
|
||||
border: 2px dashed var(--border-strong); border-radius: var(--r-lg); background: var(--surface);
|
||||
transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
|
||||
}
|
||||
.drop:hover, .drop:has(:focus-visible) { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
|
||||
.drop-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-text); }
|
||||
.previews { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: center; }
|
||||
.previews img { height: 140px; width: auto; border-radius: var(--r-md); box-shadow: var(--shadow-2); object-fit: cover; }
|
||||
.pdf { display: flex; flex-direction: column; align-items: center; gap: var(--s1); padding: var(--s3); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-sm); max-width: 160px; }
|
||||
</style>
|
||||
Reference in new issue
Block a user