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>
This commit is contained in:
1 parent
6cec404e21
commit
ad2956e868
56 files changed
+4020
-156
No files matched your search
@@ -37,7 +37,7 @@ const CameraIcon = () => (
|
||||
* The live camera with its controls on a bar along the bottom edge. `onIsbn` gets every ISBN it reads.
|
||||
* `captureRef.current` is set to a function that takes one careful picture (it returns false when the camera is off).
|
||||
*/
|
||||
export function Camera({ onIsbn, captureRef }: { onIsbn: (isbn: string) => void; captureRef: { current: (() => boolean) | null } }) {
|
||||
export function Camera({ onIsbn, onCard, captureRef }: { onIsbn: (isbn: string) => void; onCard: (text: string) => void; captureRef: { current: (() => boolean) | null } }) {
|
||||
const cam = useCamera();
|
||||
const video = useRef<HTMLVideoElement>(null);
|
||||
const scanner = useRef<Scanner | null>(null);
|
||||
@@ -65,9 +65,18 @@ export function Camera({ onIsbn, captureRef }: { onIsbn: (isbn: string) => void;
|
||||
say(`Read ${isbn}`, 'ok');
|
||||
onIsbn(isbn);
|
||||
};
|
||||
const handlers = useRef({ onIsbn: gotIsbn, onOther: () => {}, onEnded: () => {} });
|
||||
const gotCard = (text: string) => {
|
||||
beepAccept();
|
||||
setFlash(true);
|
||||
clearTimeout(flashTimer.current);
|
||||
flashTimer.current = setTimeout(() => setFlash(false), 600);
|
||||
say('Read a card', 'ok');
|
||||
onCard(text);
|
||||
};
|
||||
const handlers = useRef({ onIsbn: gotIsbn, onCard: gotCard, onOther: () => {}, onEnded: () => {} });
|
||||
handlers.current = {
|
||||
onIsbn: gotIsbn,
|
||||
onCard: gotCard,
|
||||
onOther: () => { beepLow(); say('That barcode is not an ISBN', 'warn'); },
|
||||
onEnded: () => {
|
||||
scanner.current = null; setState('off'); setStatus(null); updateCamera({ resolution: '' });
|
||||
@@ -91,7 +100,7 @@ export function Camera({ onIsbn, captureRef }: { onIsbn: (isbn: string) => void;
|
||||
setState('starting'); setProblem('');
|
||||
try {
|
||||
const sc = await startScanner(video.current, getCamera().deviceId || undefined, {
|
||||
onIsbn: i => handlers.current.onIsbn(i), onOther: c => handlers.current.onOther(), onEnded: () => handlers.current.onEnded(),
|
||||
onIsbn: i => handlers.current.onIsbn(i), onCard: t => handlers.current.onCard(t), onOther: c => handlers.current.onOther(), onEnded: () => handlers.current.onEnded(),
|
||||
}, ac.signal);
|
||||
if (!sc) return; // turned off or left the screen while the permission prompt was open
|
||||
if (ac.signal.aborted) { sc.stop(); return; }
|
||||
@@ -121,7 +130,8 @@ export function Camera({ onIsbn, captureRef }: { onIsbn: (isbn: string) => void;
|
||||
try {
|
||||
const r = await sc.capture(n => say(`Trying… ${n} frames`, 'info', true));
|
||||
if (scanner.current !== sc) return;
|
||||
if (r.isbn) gotIsbn(r.isbn);
|
||||
if (r.card) gotCard(r.card);
|
||||
else if (r.isbn) gotIsbn(r.isbn);
|
||||
else if (r.other) { beepLow(); say('That barcode is not an ISBN', 'warn', true); }
|
||||
else { beepLow(); say(r.saved ? NOT_FOUND_SAVED : NOT_FOUND, 'warn', true); }
|
||||
} catch {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef } from 'preact/hooks';
|
||||
import { addByIsbn } from '../actions.ts';
|
||||
import { addByIsbn, addFromCard } from '../actions.ts';
|
||||
import { dialogOpen } from '../dialog.ts';
|
||||
import { unlockAudio } from '../sound.ts';
|
||||
import type { EditorTarget } from '../components/Editor.tsx';
|
||||
@@ -53,7 +53,8 @@ export function Scan({ onEdit }: { onEdit: (t: EditorTarget) => void }) {
|
||||
return (
|
||||
<div class="scan">
|
||||
<div class="scan-left">
|
||||
<Camera captureRef={capture} onIsbn={isbn => { void addByIsbn(isbn); }} />
|
||||
<Camera captureRef={capture} onIsbn={isbn => { void addByIsbn(isbn); }}
|
||||
onCard={text => { void addFromCard(text, id => onEdit({ kind: 'edit', id })); }} />
|
||||
<LastScan onFix={fix} />
|
||||
<Entry inputRef={entry} onEdit={onEdit} />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user