frontend: redesign homepage with magic dock and login dialog

- Replace top login/register buttons with magic dock navigation
- Add dock items: home, downloads, blog, and conditional login/logout
- Show dashboard icon in dock when authenticated
- Extract HomePageClient for client-side dialog state
This commit is contained in:
2026-04-16 16:55:20 +00:00
parent baf2b26de0
commit 9f9f57b379
4 changed files with 202 additions and 42 deletions

View File

@@ -0,0 +1,74 @@
"use client";
import { Dock, DockIcon } from "@/components/ui/dock";
import { signOut } from "next-auth/react";
import { Home, User, LogOut, Download, BookOpen, LayoutDashboard } from "lucide-react";
export function HomeDock({
isAuthenticated,
onLoginClick,
}: {
isAuthenticated: boolean;
onLoginClick?: () => void;
}) {
return (
<div className="fixed bottom-8 left-1/2 -translate-x-1/2">
<Dock>
<DockIcon>
<a href="/" aria-label="首页">
<Home className="h-5 w-5 text-slate-700" />
</a>
</DockIcon>
<DockIcon>
<a
href="https://file.liukersun.com"
target="_blank"
rel="noopener noreferrer"
aria-label="下载网站"
>
<Download className="h-5 w-5 text-slate-700" />
</a>
</DockIcon>
<DockIcon>
<a
href="https://blog.liukersun.com"
target="_blank"
rel="noopener noreferrer"
aria-label="博客"
>
<BookOpen className="h-5 w-5 text-slate-700" />
</a>
</DockIcon>
{isAuthenticated && (
<DockIcon>
<a href="/dashboard" aria-label="仪表盘">
<LayoutDashboard className="h-5 w-5 text-slate-700" />
</a>
</DockIcon>
)}
<DockIcon>
{isAuthenticated ? (
<button
onClick={async () => {
await signOut({ redirect: false });
window.location.href = "/";
}}
aria-label="退出"
className="flex h-full w-full items-center justify-center"
>
<LogOut className="h-5 w-5 text-slate-700" />
</button>
) : (
<button
onClick={onLoginClick}
aria-label="登录"
className="flex h-full w-full items-center justify-center"
>
<User className="h-5 w-5 text-slate-700" />
</button>
)}
</DockIcon>
</Dock>
</div>
);
}

View File

@@ -0,0 +1,76 @@
"use client";
import { useEffect, useState } from "react";
import { useSearchParams } from "next/navigation";
import { BlurFade } from "@/components/magicui/blur-fade";
import { HomeDock } from "./home-dock";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { LoginForm } from "./login/login-form";
export function HomePageClient({
isAuthenticated,
healthText,
hasKeycloak,
}: {
isAuthenticated: boolean;
healthText: string;
hasKeycloak: boolean;
}) {
const searchParams = useSearchParams();
const [loginOpen, setLoginOpen] = useState(false);
useEffect(() => {
if (searchParams.get("login") === "1" && !isAuthenticated) {
setLoginOpen(true);
}
}, [searchParams, isAuthenticated]);
return (
<div className="relative flex min-h-screen flex-col items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 p-4 pb-24">
<BlurFade inView delay={0.1}>
<h1 className="mb-4 text-center text-4xl font-extrabold tracking-tight text-slate-900">
EvanPage
</h1>
</BlurFade>
<BlurFade inView delay={0.2}>
<p className="mb-8 max-w-md text-center text-lg text-slate-600">
</p>
</BlurFade>
<BlurFade inView delay={0.3}>
<div className="rounded-2xl border bg-white/80 px-8 py-6 shadow-lg backdrop-blur">
<p className="text-center text-sm font-medium text-slate-500">
</p>
<p className="mt-2 text-center text-xl font-semibold text-slate-800">
{healthText}
</p>
</div>
</BlurFade>
<HomeDock
isAuthenticated={isAuthenticated}
onLoginClick={() => !isAuthenticated && setLoginOpen(true)}
/>
<Dialog open={loginOpen} onOpenChange={setLoginOpen}>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle className="text-center"></DialogTitle>
</DialogHeader>
<LoginForm
hasKeycloak={hasKeycloak}
onSuccess={() => setLoginOpen(false)}
/>
</DialogContent>
</Dialog>
</div>
);
}

View File

@@ -0,0 +1,38 @@
"use client";
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { LoginForm } from "./login/login-form";
import { ReactNode, useState } from "react";
export function LoginDialog({
hasKeycloak,
children,
}: {
hasKeycloak: boolean;
children?: ReactNode;
}) {
const [open, setOpen] = useState(false);
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger className="rounded-lg bg-slate-900 px-5 py-2.5 text-sm font-medium text-white hover:bg-slate-800">
{children ?? "登录"}
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle className="text-center"></DialogTitle>
</DialogHeader>
<LoginForm
hasKeycloak={hasKeycloak}
onSuccess={() => setOpen(false)}
/>
</DialogContent>
</Dialog>
);
}

View File

@@ -1,8 +1,14 @@
import { BlurFade } from "@/components/magicui/blur-fade";
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;
export default async function HomePage() {
const session = await auth();
const isAuthenticated = !!session?.user;
let healthText = "无法连接到后端服务";
try {
@@ -19,46 +25,12 @@ export default async function HomePage() {
}
return (
<div className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 p-4">
<BlurFade inView delay={0.1}>
<h1 className="mb-4 text-center text-4xl font-extrabold tracking-tight text-slate-900">
EvanPage
</h1>
</BlurFade>
<BlurFade inView delay={0.2}>
<p className="mb-8 max-w-md text-center text-lg text-slate-600">
</p>
</BlurFade>
<BlurFade inView delay={0.3}>
<div className="rounded-2xl border bg-white/80 px-8 py-6 shadow-lg backdrop-blur">
<p className="text-center text-sm font-medium text-slate-500">
</p>
<p className="mt-2 text-center text-xl font-semibold text-slate-800">
{healthText}
</p>
</div>
</BlurFade>
<BlurFade inView delay={0.4}>
<div className="mt-8 flex gap-4">
<a
href="/login"
className="rounded-lg bg-slate-900 px-5 py-2.5 text-sm font-medium text-white hover:bg-slate-800"
>
</a>
<a
href="/register"
className="rounded-lg border border-slate-300 bg-white px-5 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-50"
>
</a>
</div>
</BlurFade>
</div>
<Suspense>
<HomePageClient
isAuthenticated={isAuthenticated}
healthText={healthText}
hasKeycloak={hasKeycloak}
/>
</Suspense>
);
}