Files
evanpage/frontend/app/page.tsx
evan 37cecaa1ce frontend: add bookmark management and homepage navigation
Admin-only /bookmarks page for managing entries; homepage now renders
public bookmarks as a category-grouped navigation grid (empty state
links admin to the manager). Dashboard gains a recent-bookmarks card,
dock and main layout get a bookmark entry for admins, and the
middleware protects /bookmarks.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-03 01:51:55 +08:00

65 lines
1.5 KiB
TypeScript

import { Suspense } from "react";
import { auth } from "@/auth";
import { HomePageClient } from "./home-page-client";
const SERVER_API_URL = process.env.SERVER_API_URL || "http://backend:8080";
const hasKeycloak = !!process.env.AUTH_KEYCLOAK_ISSUER;
interface Bookmark {
id: number;
title: string;
url: string;
description: string;
icon: string;
category: string;
}
async function fetchPublicBookmarks(): Promise<Bookmark[]> {
try {
const res = await fetch(`${SERVER_API_URL}/api/bookmarks/public`, {
next: { revalidate: 0 },
});
if (!res.ok) return [];
const data = await res.json();
return data.bookmarks || [];
} catch {
return [];
}
}
export default async function HomePage() {
const session = await auth();
const isAuthenticated = !!session?.user;
const isAdmin = (session?.user as any)?.role === "admin";
let healthText = "无法连接到后端服务";
let bookmarks: Bookmark[] = [];
try {
const res = await fetch(`${SERVER_API_URL}/api/health`, {
cache: "no-store",
});
if (res.ok) {
healthText = await res.text();
} else {
healthText = `后端异常: ${res.status}`;
}
} catch {
healthText = "后端连接失败";
}
bookmarks = await fetchPublicBookmarks();
return (
<Suspense>
<HomePageClient
isAuthenticated={isAuthenticated}
isAdmin={isAdmin}
healthText={healthText}
hasKeycloak={hasKeycloak}
bookmarks={bookmarks}
/>
</Suspense>
);
}