Move "Add model" into the library page
The add form now opens inline from the library instead of living on its own page with a separate menu entry. After adding, the panel closes and the new model's download progress shows in the list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
49440154a2
commit
c7cb6ed433
6 files changed
+53
-42
No files matched your search
@@ -6,6 +6,12 @@ step 1 (Hugging Face downloader) is released as a minor version.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- The library is the only main page: "Add model" opens the lookup/selection form inline (open by
|
||||
default while the library is empty). After adding, the form closes and the new model shows its
|
||||
download progress in the list. The separate `/models/new` page and its menu entry are gone.
|
||||
|
||||
## [0.3.0] - 2026-10-05
|
||||
|
||||
Milestone (c): worker and downloads with live progress.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMemo, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -28,8 +27,13 @@ async function postJson<T>(url: string, body: unknown): Promise<T> {
|
||||
return json;
|
||||
}
|
||||
|
||||
export function AddModelForm({ freeBytes }: { freeBytes: number | null }) {
|
||||
const router = useRouter();
|
||||
export function AddModelForm({
|
||||
freeBytes,
|
||||
onAdded,
|
||||
}: {
|
||||
freeBytes: number | null;
|
||||
onAdded: (modelId: string) => void;
|
||||
}) {
|
||||
const [repo, setRepo] = useState("");
|
||||
const [revision, setRevision] = useState("main");
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -127,9 +131,10 @@ export function AddModelForm({ freeBytes }: { freeBytes: number | null }) {
|
||||
exclude: excludePatterns,
|
||||
});
|
||||
toast.success(`${result.repoId} added, download queued`);
|
||||
router.push(`/models/${id}`);
|
||||
onAdded(id);
|
||||
} catch (err) {
|
||||
toast.error(err instanceof Error ? err.message : String(err));
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { AddModelForm } from "./add-model-form";
|
||||
|
||||
/** Library header with an "Add model" toggle that opens the lookup/selection form inline. */
|
||||
export function AddModelPanel({ freeBytes, defaultOpen }: { freeBytes: number | null; defaultOpen: boolean }) {
|
||||
const router = useRouter();
|
||||
const [open, setOpen] = useState(defaultOpen);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold">Library</h1>
|
||||
<Button variant={open ? "outline" : "default"} onClick={() => setOpen((o) => !o)}>
|
||||
{open ? "Close" : "Add model"}
|
||||
</Button>
|
||||
</div>
|
||||
{open && (
|
||||
<AddModelForm
|
||||
freeBytes={freeBytes}
|
||||
onAdded={() => {
|
||||
setOpen(false);
|
||||
router.refresh();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -22,9 +22,6 @@ export default async function AppLayout({ children }: LayoutProps<"/">) {
|
||||
<Link href="/" className="hover:text-foreground">
|
||||
Library
|
||||
</Link>
|
||||
<Link href="/models/new" className="hover:text-foreground">
|
||||
Add model
|
||||
</Link>
|
||||
</nav>
|
||||
<div className="ml-auto flex items-center gap-3">
|
||||
<WorkerIndicator initial={worker} />
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
import { AddModelForm } from "./add-model-form";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AddModelPage() {
|
||||
const worker = await getWorkerStatus();
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<h1 className="text-xl font-semibold">Add model</h1>
|
||||
<AddModelForm freeBytes={worker.online ? worker.modelsDirFreeBytes : null} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+6
-21
@@ -1,33 +1,18 @@
|
||||
import Link from "next/link";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { listLibrary } from "@/lib/library";
|
||||
import { getWorkerStatus } from "@/lib/worker-status";
|
||||
import { AddModelPanel } from "./add-model-panel";
|
||||
import { LibraryTable } from "./library-table";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function LibraryPage() {
|
||||
const rows = await listLibrary();
|
||||
const [rows, worker] = await Promise.all([listLibrary(), getWorkerStatus()]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold">Library</h1>
|
||||
<Link href="/models/new" className={buttonVariants()}>
|
||||
Add model
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{rows.length === 0 ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>No models yet</CardTitle>
|
||||
<CardDescription>Add a Hugging Face repo to get started.</CardDescription>
|
||||
</CardHeader>
|
||||
</Card>
|
||||
) : (
|
||||
<LibraryTable rows={rows} />
|
||||
)}
|
||||
{/* Opens by default while the library is empty. */}
|
||||
<AddModelPanel freeBytes={worker.online ? worker.modelsDirFreeBytes : null} defaultOpen={rows.length === 0} />
|
||||
{rows.length > 0 && <LibraryTable rows={rows} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user