46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
import type { Book } from '../../shared/types.ts';
|
||
import { rowState } from '../bookstate.ts';
|
||
import { CallNo } from './CallNo.tsx';
|
||
import { StateMark, StateText } from './StateMark.tsx';
|
||
|
||
function Main({ book, showYear }: { book: Book; showYear: boolean }) {
|
||
const byline = [book.authors.join(', '), showYear ? book.year : null].filter(Boolean).join(' · ');
|
||
return (
|
||
<span class="row-main">
|
||
<span class="row-title">{book.title}</span>
|
||
{byline ? <span class="row-sub">{byline}</span> : null}
|
||
<StateText book={book} />
|
||
</span>
|
||
);
|
||
}
|
||
|
||
/** A queued book on the Scan screen: state, call number, title, and the actions that apply. */
|
||
export function QueueRow({ book, onFix, onRemove }: { book: Book; onFix: () => void; onRemove: () => void }) {
|
||
const kind = rowState(book).kind;
|
||
return (
|
||
<li class={'row row-queue row-' + kind} data-book-id={book.id}>
|
||
<StateMark book={book} />
|
||
<CallNo value={kind === 'looking' ? null : book.callNumber} approximate={book.confidence === 'approximate'} source={book.source} />
|
||
<Main book={book} showYear={false} />
|
||
<span class="row-actions">
|
||
{kind === 'attention' ? <button type="button" class="btn" onClick={onFix}>Fix</button> : null}
|
||
<button type="button" class="btn-icon" onClick={onRemove} aria-label={`Remove "${book.title}"`} title="Remove">×</button>
|
||
</span>
|
||
</li>
|
||
);
|
||
}
|
||
|
||
/** A book in the Library: the whole row opens the editor. */
|
||
export function LibraryRow({ book, onOpen }: { book: Book; onOpen: () => void }) {
|
||
const kind = rowState(book).kind;
|
||
return (
|
||
<li data-book-id={book.id}>
|
||
<button type="button" class={'row row-library row-' + kind} onClick={onOpen}>
|
||
<StateMark book={book} />
|
||
<CallNo value={kind === 'looking' ? null : book.callNumber} approximate={book.confidence === 'approximate'} source={book.source} />
|
||
<Main book={book} showYear />
|
||
</button>
|
||
</li>
|
||
);
|
||
}
|