Files
booksorter/src/web/store.ts
T
swaitsandClaude Fable 5.2 ad2956e868 Add QR codes to cards, stop inventing call number parts
Cards now carry a QR code holding the book's own record (call number,
title, authors, ISBN, year), and the scanner reads it back to find or
add that book.

Call number selection no longer pads catalogue numbers with generated
cutters. A number is "exact" only when it comes verbatim from a record
for this edition; a bare class is a hint that steers the other-edition
and similar-books lookups; a record fetched by LCCN must list the
book's ISBN to count as this edition. "Look up again" bypasses every
cached result, and shelf order breaks ties by author then title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 12:53:12 -07:00

34 lines
948 B
TypeScript

import type { Book } from '../shared/types.ts';
import { compareShelf } from '../shared/shelf.ts';
export interface BookState { byId: Record<number, Book> }
export type BookAction =
| { type: 'upsert'; book: Book }
| { type: 'delete'; id: number }
| { type: 'replace'; books: Book[] };
export const emptyState: BookState = { byId: {} };
export function reduce(state: BookState, action: BookAction): BookState {
switch (action.type) {
case 'upsert':
return { byId: { ...state.byId, [action.book.id]: action.book } };
case 'delete': {
const byId = { ...state.byId };
delete byId[action.id];
return { byId };
}
case 'replace': {
const byId: Record<number, Book> = {};
for (const b of action.books) byId[b.id] = b;
return { byId };
}
}
}
export { compareShelf };
export function shelfOrder(state: BookState): Book[] {
return Object.values(state.byId).sort(compareShelf);
}