Spaces:
Sleeping
Sleeping
File size: 980 Bytes
9b70d7b 41178f4 9b70d7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import type { FileMeta, Session } from "../types/session";
export const BASE_W = 595;
export const BASE_H = 842;
export function getSelectedPhotos(session: Session | null | undefined): FileMeta[] {
if (!session) return [];
const all = session.uploads?.photos ?? [];
const selectedOrder = session.selected_photo_ids ?? [];
const byId = new Map(all.map((photo) => [photo.id, photo]));
const selected = selectedOrder
.map((id) => byId.get(id))
.filter(Boolean) as FileMeta[];
return selected.length ? selected : all;
}
export function getPhotosForPage(
session: Session | null | undefined,
pageIndex: number,
perPage = 1,
): FileMeta[] {
const selected = getSelectedPhotos(session);
const start = pageIndex * perPage;
return selected.slice(start, start + perPage);
}
export function formatDocNumber(session: Session | null | undefined): string {
if (!session?.id) return "REP-00000000";
return `REP-${session.id.slice(0, 8).toUpperCase()}`;
}
|