Initial commit

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
谢宇宁
2026-10-26 17:51:31 +07:00
co-authored by Claude Opus 5.5
commit 61d0a11dfa
371 changed files with 35836 additions and 0 deletions
+304
View File
@@ -0,0 +1,304 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect, useState, type ReactNode } from "react";
import { openAppDownload, useAppDownloadHref } from "@/components/download/download-dialog";
import { footerNavItems } from "@/components/layout/footer-nav-items";
import type { AppTranslationInfo, ConfigInfo, TranslationCategory, TranslationInfo } from "@/lib/api/types";
import { resolveAboutPlatformHref, resolveNavHref } from "./nav-href";
import { categoryHref, isNavActive } from "./nav-utils";
function isDownloadAppNav(name?: string | null) {
return (name || "").trim() === "下载APP";
}
function withDividers(items: ReactNode[], divider: string) {
return items.flatMap((item, index) =>
index === 0 ? [item] : [<span key={`divider-${index}`} className={`shrink-0 ${divider}`} />, item],
);
}
/** 仅接口有值才展示,不造假数据 */
function buildContacts(config?: ConfigInfo | null) {
const email = config?.gmailAddr?.trim();
const business = config?.telegram?.trim();
const group = config?.tgGroup?.trim() || config?.telegramAdd?.trim();
const items: { key: string; node: ReactNode }[] = [];
if (email) {
items.push({
key: "email",
node: (
<a href={`mailto:${email}`} className="text-xs leading-[18px] text-[#615970]">
E-mail:{email}
</a>
),
});
}
if (business) {
items.push({
key: "business",
node: (
<a href={business} target="_blank" rel="noopener noreferrer" className="text-xs leading-[18px] text-[#615970]">
商务合作: 立即联系
</a>
),
});
}
if (group) {
items.push({
key: "group",
node: (
<a href={group} target="_blank" rel="noopener noreferrer" className="text-xs leading-[18px] text-[#615970]">
官方群: 立即加入
</a>
),
});
}
return items;
}
function buildSocials(config?: ConfigInfo | null) {
const telegram = config?.tgGroup?.trim() || config?.telegramAdd?.trim() || config?.telegram?.trim();
const twitter = config?.twitterAddr?.trim();
return [
telegram ? { label: "Telegram", icon: "/images/footer_tg.svg", href: telegram } : null,
twitter ? { label: "X", icon: "/images/footer_x.svg", href: twitter } : null,
].filter(Boolean) as { label: string; icon: string; href: string }[];
}
function InfoNavLink({ item, onClose }: { item: TranslationInfo; onClose: () => void }) {
const href = resolveAboutPlatformHref(item);
const external = /^https?:\/\//i.test(href);
const className = "text-xs leading-[18px] text-[#948AA3]/90";
if (external) {
return (
<a href={href} target="_blank" rel="noopener noreferrer" onClick={onClose} className={className}>
{item.name}
</a>
);
}
return (
<Link href={href} onClick={onClose} className={className}>
{item.name}
</Link>
);
}
export function MobileMenu({
open,
onClose,
categoryList,
bottonTranslations,
config,
}: {
open: boolean;
onClose: () => void;
categoryList?: TranslationCategory[] | null;
bottonTranslations?: AppTranslationInfo | null;
config?: ConfigInfo | null;
}) {
const pathname = usePathname();
const categories = categoryList ?? [];
const [expandedId, setExpandedId] = useState<number | null>(null);
// 仅渲染接口 bottonTranslations,不补自定义项
const bottomNavLinks = footerNavItems(bottonTranslations);
const downloadHref = useAppDownloadHref();
const contacts = buildContacts(config);
const socials = buildSocials(config);
useEffect(() => {
if (!open) return;
const onKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") onClose();
};
const { overflow } = document.body.style;
document.body.style.overflow = "hidden";
window.addEventListener("keydown", onKeyDown);
return () => {
document.body.style.overflow = overflow;
window.removeEventListener("keydown", onKeyDown);
};
}, [open, onClose]);
return (
<div
data-component="mobile-menu"
className={`fixed inset-0 z-50 lg:hidden ${open ? "" : "pointer-events-none"}`}
{...(open ? {} : { inert: true as const })}
>
<div
className={`absolute inset-0 bg-black/60 transition-opacity duration-300 ${open ? "opacity-100" : "opacity-0"}`}
onClick={onClose}
/>
<div
role="dialog"
aria-modal="true"
aria-label="菜单"
className={`absolute inset-y-0 left-0 flex w-[281px] max-w-[85vw] flex-col items-center gap-6 overflow-y-auto [scrollbar-width:none] bg-[#0B0914] px-9 py-[60px] transition-transform duration-300 ${
open ? "translate-x-0" : "-translate-x-full"
}`}
>
<button type="button" aria-label="关闭菜单" onClick={onClose} className="absolute top-[26px] right-[13px] size-6 cursor-pointer">
<svg viewBox="0 0 24 24" fill="none" className="size-full" aria-hidden="true">
<path d="M6 6l12 12M18 6L6 18" stroke="white" strokeWidth="2" strokeLinecap="round" />
</svg>
</button>
<Link href="/" onClick={onClose} aria-label="海角社区" className="shrink-0">
<img src="/logo.svg" alt="海角社区" className="h-[62px] w-[137px]" />
</Link>
<nav className="flex w-full flex-col gap-[11px]" aria-label="主导航">
{categories.map((category) => {
const href = categoryHref(category);
const active = isNavActive(pathname, href);
const children = category.translationList?.filter((item) => item.name) ?? [];
const hasChildren = children.length > 0;
const expanded = expandedId === category.id;
if (hasChildren) {
return (
<div key={category.id} className="flex flex-col gap-1.5">
<button
type="button"
aria-expanded={expanded}
onClick={() => setExpandedId(expanded ? null : category.id)}
className={`flex h-11 shrink-0 items-center justify-between rounded-[9px] bg-white/10 px-[18px] text-base leading-[22px] font-medium ${
active ? "text-[#F12B9E]" : "text-white/90"
}`}
>
<span>{category.name}</span>
<span className={`text-xs transition-transform ${expanded ? "rotate-180" : ""}`}>▾</span>
</button>
{expanded ? (
<div className="flex flex-col gap-1 pl-2">
{children.map((item) => {
const childHref = resolveNavHref(item.urlValue);
const childActive = isNavActive(pathname, childHref);
return (
<Link
key={item.id}
href={childHref}
onClick={onClose}
className={`flex h-9 items-center rounded-lg px-4 text-sm ${
childActive ? "text-[#F12B9E]" : "text-white/70"
}`}
>
{item.name}
</Link>
);
})}
</div>
) : null}
</div>
);
}
if (isDownloadAppNav(category.name)) {
const className =
"flex h-11 w-full shrink-0 cursor-pointer items-center rounded-[9px] bg-white/10 px-[18px] text-left text-base leading-[22px] font-medium text-white/90";
if (downloadHref) {
return (
<a
key={category.id}
href={downloadHref}
target="_blank"
rel="noopener noreferrer"
onClick={onClose}
className={className}
>
{category.name}
</a>
);
}
return (
<button
key={category.id}
type="button"
onClick={() => {
onClose();
openAppDownload();
}}
className={className}
>
{category.name}
</button>
);
}
return (
<Link
key={category.id}
href={href}
onClick={onClose}
aria-current={active ? "page" : undefined}
className={`flex h-11 shrink-0 items-center rounded-[9px] bg-white/10 px-[18px] text-base leading-[22px] font-medium ${
active ? "text-[#F12B9E]" : "text-white/90"
}`}
>
{category.name}
</Link>
);
})}
<Link
href="/profile"
onClick={onClose}
aria-current={pathname === "/profile" || pathname.startsWith("/profile/") ? "page" : undefined}
className={`flex h-11 shrink-0 items-center rounded-[9px] bg-white/10 px-[18px] text-base leading-[22px] font-medium ${
pathname === "/profile" || pathname.startsWith("/profile/") ? "text-[#F12B9E]" : "text-white/90"
}`}
>
我的
</Link>
</nav>
{bottomNavLinks.length ? (
<nav
aria-label="底部导航"
className="flex w-full flex-wrap items-center justify-center gap-1.5 py-0.5"
>
{withDividers(
bottomNavLinks.map((link) => (
<InfoNavLink key={link.id || link.name} item={link} onClose={onClose} />
)),
"h-5 w-px bg-white/20",
)}
</nav>
) : null}
{contacts.length ? (
<div className="flex w-full flex-wrap items-center justify-center gap-3">
{withDividers(
contacts.map((item) => <span key={item.key}>{item.node}</span>),
"h-[18px] w-px bg-[#615970]",
)}
</div>
) : null}
{socials.length ? (
<div className="flex items-center gap-6">
{withDividers(
socials.map((social) => (
<a
key={social.label}
href={social.href}
target={social.href.startsWith("http") ? "_blank" : undefined}
rel={social.href.startsWith("http") ? "noopener noreferrer" : undefined}
aria-label={social.label}
className="size-6"
>
<img src={social.icon} alt="" className="size-full" />
</a>
)),
"h-[15px] w-px bg-white/20",
)}
</div>
) : null}
</div>
</div>
);
}