"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useRef } from "react"; import { MessageSquareText, Clock, Sparkles } from "lucide-react"; export type FeedSort = "latest" | "new" | "recommended"; const TAB_KEYS: FeedSort[] = ["latest", "new", "recommended"]; // 在指定板块内切换排序时保留 ?board= function tabHref(key: FeedSort, boardId: number) { const params = new URLSearchParams(); if (boardId > 0) params.set("board", String(boardId)); if (key !== "latest") params.set("sort", key); const qs = params.toString(); return qs ? `/?${qs}` : "/"; } // 中栏排序分段控件:URL query 驱动、SSR 直出,键盘 ←/→ 可切换 export default function FeedTabs({ current, boardId = 0 }: { current: FeedSort; boardId?: number }) { const router = useRouter(); const tabRefs = useRef<(HTMLAnchorElement | null)[]>([]); const handleKeyDown = (e: React.KeyboardEvent, i: number) => { if (e.key !== "ArrowRight" && e.key !== "ArrowLeft") return; e.preventDefault(); const next = (i + (e.key === "ArrowRight" ? 1 : TAB_KEYS.length - 1)) % TAB_KEYS.length; tabRefs.current[next]?.focus(); router.push(tabHref(TAB_KEYS[next], boardId)); }; return (