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:
swaitsandClaude Fable 5.2 committed 2026-11-18 11:01:50 -07:00
1 parent 308c0e1ed3
commit 6cec404e21
71 files changed
+8634 -1502

No files matched your search

+27 -2
View File
@@ -3,8 +3,16 @@ import type { Book } from '../shared/types.ts';
import { api } from './api.ts';
import { emptyState, reduce, shelfOrder } from './store.ts';
import type { BookAction, BookState } from './store.ts';
import { emptyPending, queueVisible, visible } from './pending.ts';
import { queueOrder } from './bookstate.ts';
import type { PendingState } from './pending.ts';
let state: BookState = emptyState;
/** Books removed from view whose real delete has not been sent yet (see removal.ts). */
let pending: PendingState = emptyPending;
/** The book most recently scanned or added, for the Last scan card. `existed` means it was in the library already. */
export interface LastScan { id: number; existed: boolean }
let lastScan: LastScan | null = null;
const listeners = new Set<() => void>();
/** When each book was first seen waiting for its lookup, for the elapsed-seconds display. */
@@ -34,11 +42,22 @@ export function useNow(active: boolean): number {
return now;
}
function notify(): void { listeners.forEach(l => l()); }
export function dispatch(action: BookAction): void {
trackPending(action);
state = reduce(state, action);
listeners.forEach(l => l());
if (action.type === 'delete' && action.id in pending.items) { // the real delete is done
const items = { ...pending.items };
delete items[action.id];
pending = { items };
}
notify();
}
export const getPending = () => pending;
export function setPending(next: PendingState): void { pending = next; notify(); }
export function setLastScan(id: number, existed: boolean): void { lastScan = { id, existed }; notify(); }
export function useLastScan(): LastScan | null { useBooks(); return lastScan; }
export const upsertBook = (book: Book) => dispatch({ type: 'upsert', book });
export function useBooks(): Book[] {
@@ -48,7 +67,13 @@ export function useBooks(): Book[] {
listeners.add(l);
return () => { listeners.delete(l); };
}, []);
return shelfOrder(state);
return visible(shelfOrder(state), pending);
}
/** The queued books for "Cards to print": attention first, then newest first. */
export function useQueue(): Book[] {
const books = useBooks();
return queueOrder(queueVisible(books, pending));
}
export function getBook(id: number): Book | undefined { return state.byId[id]; }