Files
jiang13-bbs/frontend/components/home/FeedTabs.tsx
freefire 9bae6f2513 feat: 添加每日签到功能,新增帖子排序与社区面板优化
本次提交完成了多个核心功能迭代:
1.  新增用户每日签到系统,包含签到状态查询、连续天数统计、积分累计逻辑
2.  新增"新帖子"排序选项,替换原有的latest排序为新评论排序
3.  重构首页信息流布局,优化移动端与桌面端展示样式
4.  新增最新评论、最新注册用户模块,完善社区面板数据展示
5.  新增静态友情链接配置模块
6.  提取通用时间格式化工具函数,统一全站相对时间展示
7.  补充数据库签到模型与后端API接口,完善前后端交互链路
2026-09-13 06:03:40 +08:00

59 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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 (
<div className="flex items-center gap-1.5 sm:gap-2" role="tablist" aria-label="帖子排序">
{TAB_KEYS.map((key, i) => {
const Icon = key === "latest" ? MessageSquareText : key === "new" ? Clock : Sparkles;
return (
<Link
key={key}
ref={(el) => {
tabRefs.current[i] = el;
}}
href={tabHref(key, boardId)}
role="tab"
className="j13-tab inline-flex items-center gap-1"
aria-selected={current === key}
tabIndex={current === key ? 0 : -1}
onKeyDown={(e) => handleKeyDown(e, i)}
>
<Icon size={13} className="opacity-80" />
{key === "latest" ? "新评论" : key === "new" ? "新帖子" : "推荐帖"}
</Link>
);
})}
</div>
);
}