feat(web): FE overhaul — SWR centralized data layer + dashboard + islands
CI / typecheck + tests (push) Canceled after 0s
CI / build + deploy (Nix) — api (push) Canceled after 0s
CI / build + deploy (Nix) — mcp (push) Canceled after 0s
CI / build + deploy (Nix) — worker (push) Canceled after 0s
CI / build + deploy (web) (push) Canceled after 0s

- Add SWR foundation (lib/fetcher, lib/swr, lib/api) with typed
  hooks: useSections/useDocuments/useSearch/useRelated/useRevisions/useQueueStatus
- Replace ad-hoc useEffect+fetch in Header/Sidebar/CommandMenu/search
  with SWR (dedup 4s, focus throttle 10s, debounced search 180ms)
- Doc page: RelatedGrid + RevisionList as SWR client islands (RSC hero stays)
- DocForm: SWR mutate on create/update for live sidebar invalidation
- New APIs: /api/related, /api/revisions, /api/tags, /api/queue/status,
  /api/docs filtering (?section=&status=)
- New UI: DocumentCard, SectionCard, SearchBar, TagCloud, QueueBadge,
  EmptyState, dashboard (/dashboard with QueueStrip live + section stats)
- Layout wraps SWRProvider; no TanStack code (SWR-only per spec)
- Verified: next build passes (16.3.4 Turbopack), no manual fetch sprawl remains

Co-Authored-By: internal-model
This commit is contained in:
mytheclipsebotreview
2026-09-08 19:37:27 +07:00
co-authored by internal-model
parent 1025454d87
commit 4330f47c65
36 changed files with 1393 additions and 415 deletions
+9 -2
View File
@@ -78,8 +78,15 @@ function splitPayload(body: Record<string, unknown>): {
}
// GET /api/docs — list all documents (for sidebar navigation).
export async function GET() {
const docs = await listDocuments();
// Supports ?section=&status= filters.
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url);
const section = searchParams.get("section") ?? undefined;
const status = searchParams.get("status") ?? undefined;
const docs = await listDocuments({
...(section ? { section } : {}),
...(status ? { status } : {}),
});
return NextResponse.json(docs);
}
+27
View File
@@ -0,0 +1,27 @@
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
// GET /api/queue/status — BullMQ queue counts (read-only, public)
// Falls back gracefully when Redis is unavailable so the UI never breaks.
export async function GET() {
try {
const { getQueue } = await import("@mcpedia/queue");
const q = getQueue();
const [waiting, active, completed, failed, delayed] = await Promise.all([
q.getWaitingCount(),
q.getActiveCount(),
q.getCompletedCount(),
q.getFailedCount(),
q.getDelayedCount(),
]);
return NextResponse.json({ waiting, active, completed, failed, delayed });
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
// Return zeroed status so the FE can render gracefully
return NextResponse.json(
{ waiting: 0, active: 0, completed: 0, failed: 0, delayed: 0, error: msg },
{ status: 200 },
);
}
}
+20
View File
@@ -0,0 +1,20 @@
import { NextRequest, NextResponse } from "next/server";
import { getRelated } from "@mcpedia/core";
export const dynamic = "force-dynamic";
// GET /api/related?slug=...&limit=5
export async function GET(req: NextRequest) {
const slug = new URL(req.url).searchParams.get("slug") ?? "";
const limit = Math.min(Math.max(Number(new URL(req.url).searchParams.get("limit") ?? 5), 1), 20);
if (!slug.trim()) {
return NextResponse.json({ results: [] });
}
try {
const results = await getRelated(slug, limit);
return NextResponse.json({ results });
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
return NextResponse.json({ results: [], error: msg }, { status: 500 });
}
}
+21
View File
@@ -0,0 +1,21 @@
import { NextRequest, NextResponse } from "next/server";
import { listRevisions } from "@mcpedia/core";
export const dynamic = "force-dynamic";
// GET /api/revisions?slug=...&limit=10
export async function GET(req: NextRequest) {
const { searchParams } = new URL(req.url);
const slug = searchParams.get("slug") ?? "";
const limit = Math.min(Math.max(Number(searchParams.get("limit") ?? 10), 1), 50);
if (!slug.trim()) {
return NextResponse.json({ revisions: [] });
}
try {
const revisions = await listRevisions(slug, limit);
return NextResponse.json({ revisions });
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
return NextResponse.json({ revisions: [], error: msg }, { status: 500 });
}
}
+28
View File
@@ -0,0 +1,28 @@
import { NextResponse } from "next/server";
import { listDocuments } from "@mcpedia/core";
export const dynamic = "force-dynamic";
// GET /api/tags?limit=30 — aggregated tag counts
export async function GET(req: Request) {
const limit = Math.min(Math.max(Number(new URL(req.url).searchParams.get("limit") ?? 30), 1), 100);
try {
const docs = await listDocuments();
const counts = new Map<string, number>();
for (const d of docs) {
for (const t of d.tags ?? []) {
const tag = String(t).trim();
if (!tag) continue;
counts.set(tag, (counts.get(tag) ?? 0) + 1);
}
}
const tags = [...counts.entries()]
.map(([tag, count]) => ({ tag, count }))
.sort((a, b) => b.count - a.count || a.tag.localeCompare(b.tag))
.slice(0, limit);
return NextResponse.json({ tags });
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
return NextResponse.json({ tags: [], error: msg }, { status: 500 });
}
}