Redesign the interface around Scan and Library, classify uncatalogued books from similar ones
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
308c0e1ed3
commit
6cec404e21
71 files changed
+8634
-1502
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import type { SearchResult } from '../../shared/types.ts';
|
||||
|
||||
/** Next highlighted index for an arrow key; -1 means nothing is highlighted. */
|
||||
export function moveActive(key: string, active: number, count: number): number {
|
||||
if (count === 0) return -1;
|
||||
if (key === 'ArrowDown') return active < count - 1 ? active + 1 : 0;
|
||||
if (key === 'ArrowUp') return active > 0 ? active - 1 : count - 1;
|
||||
return active;
|
||||
}
|
||||
|
||||
export interface Footer { label: string; onPick: () => void }
|
||||
|
||||
/** Search results as a listbox. The input that owns it keeps focus and points at the highlighted option. */
|
||||
export function ResultList({ id, label, results, active, onPick, onHover, footer }: {
|
||||
id: string; label: string; results: SearchResult[]; active: number;
|
||||
onPick: (r: SearchResult) => void; onHover: (i: number) => void; footer?: Footer;
|
||||
}) {
|
||||
const keep = (e: Event) => e.preventDefault(); // a click must not take focus from the input
|
||||
return (
|
||||
<ul class="results" role="listbox" id={id} aria-label={label}>
|
||||
{results.map((r, i) => (
|
||||
<li role="option" id={`${id}-${i}`} class={'result' + (i === active ? ' active' : '')} aria-selected={i === active}
|
||||
onMouseDown={keep} onMouseMove={() => onHover(i)} onClick={() => onPick(r)}>
|
||||
<span class="result-title">{r.title}</span>
|
||||
<span class="result-sub">{[r.authors.join(', '), r.year, r.publisher].filter(Boolean).join(' · ')}</span>
|
||||
</li>
|
||||
))}
|
||||
{footer ? (
|
||||
<li role="option" id={`${id}-${results.length}`} class={'result result-footer' + (active === results.length ? ' active' : '')}
|
||||
aria-selected={active === results.length} onMouseDown={keep} onMouseMove={() => onHover(results.length)} onClick={footer.onPick}>
|
||||
<span class="result-title">{footer.label}</span>
|
||||
</li>
|
||||
) : null}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user