Rework scan screen, make lookups non-blocking, fix review findings

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 10:19:32 -07:00
1 parent 468cafc6db
commit b5defb4e4f
46 files changed
+1957 -406

No files matched your search

+13 -4
View File
@@ -2,6 +2,7 @@ import { useState } from 'preact/hooks';
import type { Book } from '../../shared/types.ts';
import { api } from '../api.ts';
import { upsertBook, dispatch } from '../live.ts';
import { parseYear } from '../year.ts';
export function BookEditor({ book, onClose }: { book: Book; onClose: () => void }) {
const [title, setTitle] = useState(book.title);
@@ -10,6 +11,7 @@ export function BookEditor({ book, onClose }: { book: Book; onClose: () => void
const [year, setYear] = useState(book.year?.toString() ?? '');
const [callNumber, setCallNumber] = useState(book.callNumber ?? '');
const [msg, setMsg] = useState('');
const [yearError, setYearError] = useState('');
const [busy, setBusy] = useState(false);
async function run(fn: () => Promise<void>) {
@@ -18,17 +20,23 @@ export function BookEditor({ book, onClose }: { book: Book; onClose: () => void
setBusy(false);
}
const save = (ev: Event) => { ev.preventDefault(); void run(async () => {
const save = (ev: Event) => {
ev.preventDefault();
const y = parseYear(year);
if (!y.ok) { setYearError('Enter the year as digits, for example 2018, or leave it empty.'); return; }
setYearError('');
void run(async () => {
const patch: Record<string, unknown> = {
title: title.trim(),
authors: authors.split(/[;\n]/).map(a => a.trim()).filter(Boolean),
publisher: publisher.trim() || null,
year: year.trim() ? Number(year) : null,
year: y.value,
};
if (callNumber.trim() !== (book.callNumber ?? '')) patch.callNumber = callNumber.trim();
upsertBook(await api.patchBook(book.id, patch));
onClose();
}); };
});
};
return (
<form class="card editor" onSubmit={save}>
@@ -36,8 +44,9 @@ export function BookEditor({ book, onClose }: { book: Book; onClose: () => void
<label>Authors (separate with ;)<input value={authors} onInput={e => setAuthors(e.currentTarget.value)} /></label>
<div class="row">
<label class="grow">Publisher<input value={publisher} onInput={e => setPublisher(e.currentTarget.value)} /></label>
<label class="year">Year<input inputMode="numeric" value={year} onInput={e => setYear(e.currentTarget.value)} /></label>
<label class="year">Year<input inputMode="numeric" value={year} aria-invalid={yearError ? 'true' : undefined} onInput={e => { setYear(e.currentTarget.value); setYearError(''); }} /></label>
</div>
{yearError ? <p class="error" role="alert">{yearError}</p> : null}
<label>Call number
<input class="mono" value={callNumber} onInput={e => setCallNumber(e.currentTarget.value)} />
<small>Changing this locks the number</small>
+23
View File
@@ -0,0 +1,23 @@
import type { Book } from '../../shared/types.ts';
import { elapsedText, rowState } from '../bookstate.ts';
import { lookupStartedAt, useNow } from '../live.ts';
const CheckIcon = () => (
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8.5l3.2 3.2L13 4.8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" /></svg>
);
const AlertIcon = () => (
<svg class="icon" viewBox="0 0 16 16" aria-hidden="true"><path d="M8 2.2L14.6 13.5H1.4L8 2.2z" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linejoin="round" /><path d="M8 6.6v3.2M8 11.6v.1" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" /></svg>
);
function Looking({ book }: { book: Book }) {
const now = useNow(true);
return <span class="state-label"><span class="spinner" aria-hidden="true" />Looking up… <span class="elapsed">{elapsedText(now - lookupStartedAt(book))}</span></span>;
}
/** The one label a book shows: Looking up… (spinner, seconds), Ready, or Needs attention. */
export function StateLabel({ book }: { book: Book }) {
const s = rowState(book);
if (s.kind === 'looking') return <Looking book={book} />;
if (s.kind === 'ready') return <span class="state-label"><CheckIcon />Ready</span>;
return <span class="state-label"><AlertIcon />Needs attention</span>;
}
+1 -1
View File
@@ -7,7 +7,7 @@ export function CallNo({ value, approximate }: { value: string | null; approxima
return (
<span class="callno">
<span class="callno-line">{lines[0]}{approximate ? <span class="approx" title="Approximate number"> ~</span> : null}</span>
<span class="callno-line">{lines[1] || ' '}</span>
<span class="callno-line">{lines[1] || ' '}</span>
</span>
);
}