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
+22
-38
@@ -13,46 +13,30 @@ export function rowState(book: Book): RowState {
|
||||
return { kind: 'attention', reason: book.attentionReason ?? 'This book needs a look.' };
|
||||
}
|
||||
|
||||
const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
|
||||
/** Queued books: the ones needing attention first, then newest first. */
|
||||
export function queueOrder(books: Book[]): Book[] {
|
||||
const rank = (b: Book) => (rowState(b).kind === 'attention' ? 0 : 1);
|
||||
return books
|
||||
.filter(b => b.inQueue)
|
||||
.sort((a, b) => {
|
||||
if (rank(a) !== rank(b)) return rank(a) - rank(b);
|
||||
if (a.createdAt !== b.createdAt) return a.createdAt < b.createdAt ? 1 : -1;
|
||||
return b.id - a.id;
|
||||
});
|
||||
}
|
||||
|
||||
export function sessionSummary(books: Book[]): string {
|
||||
let ready = 0, looking = 0, attention = 0;
|
||||
for (const b of books) {
|
||||
const s = rowState(b).kind;
|
||||
if (s === 'ready') ready++; else if (s === 'looking') looking++; else attention++;
|
||||
export interface PrintStatus { ready: number; looking: number; label: string; reason: string | null }
|
||||
|
||||
/** What the print button says, and why it is disabled when it is. */
|
||||
export function printStatus(queue: Book[]): PrintStatus {
|
||||
let ready = 0, looking = 0;
|
||||
for (const b of queue) {
|
||||
const k = rowState(b).kind;
|
||||
if (k === 'ready') ready++; else if (k === 'looking') looking++;
|
||||
}
|
||||
const parts = [`${books.length} scanned`];
|
||||
if (ready) parts.push(`${ready} ready`);
|
||||
if (looking) parts.push(`${looking} looking up`);
|
||||
if (attention) parts.push(`${attention} ${attention === 1 ? 'needs' : 'need'} attention`);
|
||||
return parts.join(' · ');
|
||||
}
|
||||
|
||||
export interface QueueSplit { ready: Book[]; looking: Book[] }
|
||||
|
||||
/** Queued books, split into the ones that can be printed now and the ones still being looked up. */
|
||||
export function queueSplit(books: Book[]): QueueSplit {
|
||||
const ready: Book[] = [], looking: Book[] = [];
|
||||
for (const b of books) {
|
||||
if (!b.inQueue) continue;
|
||||
const s = rowState(b).kind;
|
||||
if (s === 'ready') ready.push(b); else if (s === 'looking') looking.push(b);
|
||||
}
|
||||
return { ready, looking };
|
||||
}
|
||||
|
||||
export function queueHeader(ready: number, looking: number): string {
|
||||
const head = plural(ready, 'card', 'cards') + ' ready';
|
||||
return looking ? `${head} · ${looking} still looking up` : head;
|
||||
}
|
||||
|
||||
export function pdfLabel(ready: number): string {
|
||||
return ready ? `Make PDF (${plural(ready, 'card', 'cards')})` : 'Make PDF';
|
||||
}
|
||||
|
||||
export function queueTabLabel(ready: number, looking: number): string {
|
||||
const n = ready + looking;
|
||||
return n ? `Print queue (${n})` : 'Print queue';
|
||||
const label = ready === 0 ? 'Print cards' : `Print ${ready} ${ready === 1 ? 'card' : 'cards'}`;
|
||||
const reason = looking ? `${looking} still looking up` : ready === 0 ? 'Nothing to print yet' : null;
|
||||
return { ready, looking, label, reason };
|
||||
}
|
||||
|
||||
/** "12 s", "1 min 05 s" */
|
||||
|
||||
Reference in new issue
Block a user