doctor-mail/apps/web/src/components/layout/main/useNavItem.tsx

67 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-01-22 23:19:58 +08:00
import { api } from "@nice/client";
import { TaxonomySlug } from "@nice/common";
import { useMemo } from "react";
2025-01-25 19:51:16 +08:00
import {
FileTextOutlined,
ScheduleOutlined,
QuestionCircleOutlined,
FolderOutlined,
TagsOutlined
} from "@ant-design/icons";
export interface NavItem {
to: string;
label: string;
icon?: React.ReactNode;
}
2025-01-22 23:19:58 +08:00
export function useNavItem() {
const { data } = api.term.findMany.useQuery({
where: {
taxonomy: { slug: TaxonomySlug.CATEGORY }
}
});
const navItems = useMemo(() => {
2025-01-23 23:59:49 +08:00
// 定义固定的导航项
const staticItems = {
2025-01-25 19:51:16 +08:00
letterList: {
to: "/",
label: "公开信件",
icon: <FileTextOutlined className="text-base" />
},
letterProgress: {
to: "/letter-progress",
label: "进度查询",
icon: <ScheduleOutlined className="text-base" />
},
help: {
to: "/help",
label: "使用帮助",
icon: <QuestionCircleOutlined className="text-base" />
}
2025-01-23 23:59:49 +08:00
};
2025-01-22 23:19:58 +08:00
2025-01-23 23:59:49 +08:00
if (!data) {
return [staticItems.letterList, staticItems.letterProgress, staticItems.help];
}
2025-01-22 23:19:58 +08:00
2025-01-23 23:59:49 +08:00
// 构建分类导航项
const categoryItems = data.map(term => ({
2025-01-25 02:27:40 +08:00
to: `/write-letter?termId=${term.id}`,
2025-01-25 19:51:16 +08:00
label: term.name,
icon: <TagsOutlined className="text-base"></TagsOutlined>
2025-01-23 23:59:49 +08:00
}));
// 按照指定顺序返回导航项
return [
staticItems.letterList,
staticItems.letterProgress,
2025-01-25 19:51:16 +08:00
...categoryItems,
2025-01-23 23:59:49 +08:00
staticItems.help
];
2025-01-22 23:19:58 +08:00
}, [data]);
return { navItems };
2025-01-23 23:59:49 +08:00
}