import { createSignal, For, Show } from 'solid-js' import QrScanner from '../components/QrScanner' import { searchBook, downloadBook, type GmeEntry } from '../api' type State = | { type: 'idle' } | { type: 'searching' } | { type: 'found'; title: string; gmeUrls: GmeEntry[] } | { type: 'not_found' } | { type: 'downloading' } | { type: 'done'; filename: string } | { type: 'error'; message: string } export default function ScanPage() { const [state, setState] = createSignal({ type: 'idle' }) const [query, setQuery] = createSignal('') const search = async (q: string) => { if (!q.trim()) return setState({ type: 'searching' }) try { const data = await searchBook(q.trim()) if (data.error || !data.gmeUrls?.length) { setState({ type: 'not_found' }) } else { setState({ type: 'found', title: data.title!, gmeUrls: data.gmeUrls! }) } } catch (e) { setState({ type: 'error', message: e instanceof Error ? e.message : String(e) }) } } const download = async (gmeUrl: string, imageUrl?: string) => { setState({ type: 'downloading' }) try { const data = await downloadBook(gmeUrl, imageUrl) if (data.filename) { setState({ type: 'done', filename: data.filename }) } else { setState({ type: 'error', message: data.message }) } } catch (e) { setState({ type: 'error', message: e instanceof Error ? e.message : String(e) }) } } const reset = () => { setState({ type: 'idle' }) setQuery('') } const isIdle = () => ['idle', 'not_found', 'done'].includes(state().type) return (
{/* Suchfeld */}

Kein Buch gefunden – Titel oder Artikelnummer eingeben:

setQuery(e.currentTarget.value)} onKeyDown={e => e.key === 'Enter' && search(query())} />
{/* Scanner */} {/* Suche läuft */}
Suche läuft…
{/* Ergebnis */} {(() => { const s = state() as { type: 'found'; title: string; gmeUrls: GmeEntry[] } return (

{s.title}

{(entry) => (
{entry.label}
)}
) })()}
{/* Download läuft */}
Download läuft…
{/* Erfolg */} {(() => { const s = state() as { type: 'done'; filename: string } return (

{s.filename} wurde gespeichert

) })()}
{/* Fehler */} {(() => { const s = state() as { type: 'error'; message: string } return (

Fehler: {s.message}

) })()}
{/* Zurück */}
) } function IconSearch() { return ( ) } function IconDownload() { return ( ) } function IconCheck() { return ( ) }