Files
jiang13-forum/frontend/src/components/FeedHeader.tsx

75 lines
2.5 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.
import { Users, FileText, LayoutGrid } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
import type { Board, ForumStats } from '../api/types';
interface Props {
boardId: number;
keyword: string;
tag?: string;
boards: Board[];
stats: ForumStats | null;
postTotal: number;
/** 搜索页用 h1首页/板块页中间栏不再展示标题 */
titleAs?: 'h1' | 'h2';
}
export default function FeedHeader({ boardId, keyword, tag = '', boards, stats, postTotal, titleAs = 'h1' }: Props) {
const nav = useNavigate();
const board = boards.find(b => b.id === boardId);
const filtered = !!(keyword || tag);
const inBoard = !filtered && boardId > 0 && !!board;
/** 侧栏已有「全部帖子 / 板块名」,中间栏不再重复;仅搜索/标签保留标题 */
const title = tag ? `标签:${tag}` : (keyword ? `搜索:${keyword}` : '');
const TitleTag = titleAs;
return (
<div className={`feed-head${filtered ? ' feed-head--solo' : ' feed-head--stats-only'}`}>
<div className="feed-head__title">
{title ? <TitleTag>{title}</TitleTag> : null}
{!filtered && inBoard && (
<div className="feed-head__stats">
<span className="feed-stat-chip">
<FileText aria-hidden />
<strong>{postTotal}</strong>
</span>
{stats && (
<span className="feed-stat-chip feed-stat-chip--muted" title="全站统计">
{stats.posts} · {stats.users}
</span>
)}
</div>
)}
{!filtered && !inBoard && stats && (
<div className="feed-head__stats">
<span className="feed-stat-chip">
<Users aria-hidden />
<strong>{stats.users}</strong>
</span>
<span className="feed-stat-chip">
<FileText aria-hidden />
<strong>{stats.posts}</strong>
</span>
<span className="feed-stat-chip">
<LayoutGrid aria-hidden />
<strong>{stats.boards}</strong>
</span>
</div>
)}
</div>
{filtered && (
<button
type="button"
className="feed-head__clear"
onClick={() => nav('/')}
>
{tag ? '清除标签' : '清除搜索'}
</button>
)}
{filtered && (
<span className="feed-toolbar__count"> {postTotal} </span>
)}
</div>
);
}