Files
Kaname/src/app/(app)/page.tsx
T
Claude 7239ba2692 Library: load import folder files on demand, memoize search
The library page passed every importable folder's full file list (up to 5,000
entries each, from the worker's scan) into a client component, though it is
only used after clicking Import. With three such folders that was 84% of a
1.3 MB page, re-sent on every refresh after a job finished.

- listLocalFolders() returns path, commit and counts only; the Import button
  fetches one folder's files from GET /api/local-folders?path=…
- addModel() checks that an import folder exists without loading its files.
- LibraryView builds each model's search text once and memoizes the visible
  rows and facet counts; the facet sort uses one Intl.Collator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EooZ9biu7kFNB4eDJrwQc5
2026-11-01 20:49:18 +00:00

33 lines
1.4 KiB
TypeScript

import { auth } from "@/auth";
import { listLibrary } from "@/lib/library";
import { listLocalFolders } from "@/lib/local-folders";
import { getWorkerStatus } from "@/lib/worker-status";
import { LibraryTop } from "./library-top";
import { LibraryView } from "./library-view";
export const dynamic = "force-dynamic";
export default async function LibraryPage({ searchParams }: PageProps<"/">) {
const [rows, worker, folders, session] = await Promise.all([listLibrary(), getWorkerStatus(), listLocalFolders(), auth()]);
return (
<div className="flex flex-col gap-4">
{/* The form opens by default while the library is empty and there's nothing on disk to import,
and with ?add=1 (the ⌘K palette's "Add model"). */}
<LibraryTop
worker={worker}
defaultOpen={(rows.length === 0 && folders.length === 0) || (await searchParams).add === "1"}
hero={{
name: session?.user?.name ?? null,
models: rows.length,
libraryBytes: rows.reduce((s, r) => s + r.presentBytes, 0),
updates: rows.filter((r) => r.updateAvailable && (r.hubState === "available" || !r.hubState)).length,
goneFromHub: rows.filter((r) => r.hubState === "repo_missing" || r.hubState === "commit_missing").length,
}}
panel={{ freeBytes: worker.online ? worker.modelsDirFreeBytes : null, folders }}
/>
{rows.length > 0 && <LibraryView rows={rows} />}
</div>
);
}