Add resolver, server, PDF rendering and web app

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-18 09:46:46 -07:00
1 parent 6a7fcdc4b8
commit bdfdf581f3
59 files changed
+4088

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
import type { Book } from '../shared/types.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 };
}
}
}
/** Shelf order: by sortKey, books without one last, then title. */
export function compareShelf(a: Book, b: Book): number {
if (a.sortKey !== b.sortKey) {
if (a.sortKey === null) return 1;
if (b.sortKey === null) return -1;
return a.sortKey < b.sortKey ? -1 : 1;
}
return a.title.localeCompare(b.title);
}
export function shelfOrder(state: BookState): Book[] {
return Object.values(state.byId).sort(compareShelf);
}