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,40 @@
|
||||
import type { Book } from '../shared/types.ts';
|
||||
|
||||
/**
|
||||
* Rows the person removed from "Cards to print". They are hidden at once; the real request waits so Undo can
|
||||
* bring them back. A book never printed is deleted; one already in the library is only taken off the queue.
|
||||
*/
|
||||
export type RemovalKind = 'delete' | 'dequeue';
|
||||
export interface Removal { book: Book; kind: RemovalKind }
|
||||
export interface PendingState { items: Record<number, Removal> }
|
||||
|
||||
export const emptyPending: PendingState = { items: {} };
|
||||
|
||||
export function removeKind(book: Book): RemovalKind {
|
||||
return book.printedAt ? 'dequeue' : 'delete';
|
||||
}
|
||||
|
||||
export function removeLater(s: PendingState, book: Book): PendingState {
|
||||
return { items: { ...s.items, [book.id]: { book, kind: removeKind(book) } } };
|
||||
}
|
||||
|
||||
/** Undo (or a failed request): the book is shown again. `removal` is null when nothing was pending. */
|
||||
export function restore(s: PendingState, id: number): { state: PendingState; removal: Removal | null } {
|
||||
const removal = s.items[id] ?? null;
|
||||
if (!removal) return { state: s, removal: null };
|
||||
const items = { ...s.items };
|
||||
delete items[id];
|
||||
return { state: { items }, removal };
|
||||
}
|
||||
|
||||
export function isPending(s: PendingState, id: number): boolean { return id in s.items; }
|
||||
export function pendingIds(s: PendingState): number[] { return Object.keys(s.items).map(Number); }
|
||||
|
||||
/** For the library: only books waiting to be deleted are hidden. */
|
||||
export function visible(books: Book[], s: PendingState): Book[] {
|
||||
return books.filter(b => s.items[b.id]?.kind !== 'delete');
|
||||
}
|
||||
/** For the print list: every removed row is hidden. */
|
||||
export function queueVisible(books: Book[], s: PendingState): Book[] {
|
||||
return books.filter(b => !isPending(s, b.id));
|
||||
}
|
||||
Reference in new issue
Block a user