"use client"; import { Plus } from "lucide-react"; import { cn } from "@/lib/utils"; import type { FileRef, RowOut } from "@/lib/databases/types"; import { isEmpty } from "@/lib/databases/values"; import { useDb } from "../hooks"; import { CellDisplay } from "../cells/Cell"; import { isImage } from "../cells/FileCell"; export function GalleryView() { const ctx = useDb(); const coverId = ctx.view.config.coverProperty; const fileProps = ctx.props.filter((p) => p.type === "file"); const cover = (r: RowOut): FileRef | null => { const ps = coverId ? ctx.props.filter((p) => p.id === coverId) : fileProps; for (const p of ps) { const f = (Array.isArray(r.values[p.id]) ? (r.values[p.id] as FileRef[]) : []).find(isImage); if (f) return f; } return null; }; return (
{ctx.rows.map((r) => { const c = cover(r); const props = ctx.visibleProps.filter((p) => p.type !== "title" && p.type !== "file" && !isEmpty(r.values[p.id])).slice(0, 4); return ( ); })}
); }