Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/components/categoryPanel/CategoryPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import styles from "./CategoryPanel.module.css";
import CategoryService from "@/services/CategoryService.ts";
import Skeleton from "../skeleton/Skeleton";
import { useAsyncResource } from "@/hooks/UseAsyncResource";
import { useAuth } from "@/contexts/AuthContext";

interface CategoryPanelProps {
selectedCategoryId?: string | number;
Expand Down Expand Up @@ -55,11 +56,21 @@ const buildCategoryTree = (list: RawCategory[]): Category[] => {

const CategoryPanel: React.FC<CategoryPanelProps> = ({ selectedCategoryId, onCategoryClick }) => {
const { t } = useTranslation("components");
const { user, loading: authLoading } = useAuth();
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
const { data: categories = [], loading } = useAsyncResource<Category[]>(async (signal) => {
const response = await CategoryService.queryCategory({ signal });
return buildCategoryTree(response?.list || []);
}, []);
const { data: categories = [], loading } = useAsyncResource<Category[]>(
async (signal) => {
const response = await CategoryService.queryMyCategory({ signal });
return buildCategoryTree(response?.list || []);
},
[user?.id],
{ enabled: !!user?.id },
);

// 分类已下放到个人用户,游客没有分类,整块面板不展示
if (authLoading || !user) {
return null;
}

const toggleExpand = (categoryId: string | number) => {
setExpanded((prev) => ({
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/en-US/Article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const article = {
typeRepost: "Repost",
categoryLabel: "Category",
categorySelect: "Category",
categoryCreateFailed: "Failed to create category",
tagLabel: "Tags",
tagSelect: "Tag",
contentLabel: "Content",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/en-US/Personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import stats from "./personal/Stats";
import center from "./personal/Center";
import articles from "./personal/Articles";
import tags from "./personal/Tags";
import categories from "./personal/Categories";
import assignments from "./personal/Assignments";
import organizations from "./personal/Organizations";
import notifications from "./personal/Notifications";
Expand All @@ -15,6 +16,7 @@ const personal = {
center,
articles,
tags,
categories,
assignments,
organizations,
notifications,
Expand Down
7 changes: 7 additions & 0 deletions src/i18n/locales/en-US/admin/Categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const section = {
clear: "Clear Filters",
searchLabel: "Search Categories",
searchPlaceholder: "Category name or description",
userLabel: "Owner",
userPlaceholder: "Select user...",
allUsers: "All Users",
statusLabel: "Category Status",
statusPlaceholder: "Select status...",
sortLabel: "Sort By",
Expand Down Expand Up @@ -41,6 +44,7 @@ const section = {
},
icons: {
default: "Default",
folder: "Folder",
tech: "Technology",
life: "Life",
travel: "Travel",
Expand All @@ -58,6 +62,7 @@ const section = {
total: "{{total}} categories in total",
headers: {
info: "Category Info",
owner: "Owner",
parent: "Parent Category",
status: "Status",
stats: "Stats",
Expand All @@ -74,6 +79,8 @@ const section = {
modal: {
createTitle: "New Category",
editTitle: "Edit Category",
ownerLabel: "Owner",
ownerPlaceholder: "Select owner",
nameLabel: "Category Name *",
namePlaceholder: "Enter category name",
slugLabel: "URL Slug *",
Expand Down
36 changes: 36 additions & 0 deletions src/i18n/locales/en-US/personal/Categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const section = {
title: "My Categories",
createCategory: "New Category",
loading: "Loading categories...",
emptyTitle: "No categories yet",
emptyHint: 'Click the "New Category" button to create your first article category',
unknownDescription: "N/A",
unknownTime: "Unknown time",
articleCount: "{{value}} articles",
createdOn: "Created on {{value}}",
parentNone: "None (Top-level category)",
parentLabel: "Parent Category",
parentPlaceholder: "Select parent category",
parentValue: "Parent: {{value}}",
editTitle: "Edit Category",
nameLabel: "Category Name",
namePlaceholder: "Enter category name",
descLabel: "Category Description",
descPlaceholder: "Enter category description",
colorLabel: "Category Color",
cancel: "Cancel",
saving: "Saving...",
update: "Update",
create: "Create",
nameRequired: "Please enter a category name",
deleteConfirmTitle: "Confirm Deletion",
deleteConfirmContent:
'Are you sure you want to delete the category "{{name}}"? Articles associated with it will lose this category.',
delete: "Delete",
message: {
saveFailed: "Failed to save the category, please try again",
deleteFailed: "Failed to delete the category, please try again",
},
} as const;

export default section;
1 change: 1 addition & 0 deletions src/i18n/locales/en-US/personal/Center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const section = {
assignments: "My Tasks",
edit: "Edit Profile",
tags: "My Tags",
categories: "My Categories",
stats: "Statistics",
organizations: "My Organizations",
following: "My Following",
Expand Down
1 change: 1 addition & 0 deletions src/i18n/locales/zh-CN/Article.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const article = {
typeRepost: "转载文章",
categoryLabel: "文章分类",
categorySelect: "分类",
categoryCreateFailed: "创建分类失败",
tagLabel: "文章标签",
tagSelect: "标签",
contentLabel: "文章内容",
Expand Down
2 changes: 2 additions & 0 deletions src/i18n/locales/zh-CN/Personal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import stats from "./personal/Stats";
import center from "./personal/Center";
import articles from "./personal/Articles";
import tags from "./personal/Tags";
import categories from "./personal/Categories";
import assignments from "./personal/Assignments";
import organizations from "./personal/Organizations";
import notifications from "./personal/Notifications";
Expand All @@ -15,6 +16,7 @@ const personal = {
center,
articles,
tags,
categories,
assignments,
organizations,
notifications,
Expand Down
7 changes: 7 additions & 0 deletions src/i18n/locales/zh-CN/admin/Categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const section = {
clear: "清除筛选",
searchLabel: "搜索分类",
searchPlaceholder: "分类名称或描述",
userLabel: "所属用户",
userPlaceholder: "选择用户...",
allUsers: "全部用户",
statusLabel: "分类状态",
statusPlaceholder: "选择状态...",
sortLabel: "排序方式",
Expand Down Expand Up @@ -41,6 +44,7 @@ const section = {
},
icons: {
default: "默认",
folder: "文件夹",
tech: "技术",
life: "生活",
travel: "旅行",
Expand All @@ -58,6 +62,7 @@ const section = {
total: "共 {{total}} 个分类",
headers: {
info: "分类信息",
owner: "所属用户",
parent: "父级分类",
status: "状态",
stats: "统计数据",
Expand All @@ -74,6 +79,8 @@ const section = {
modal: {
createTitle: "新增分类",
editTitle: "编辑分类",
ownerLabel: "所属用户",
ownerPlaceholder: "选择所属用户",
nameLabel: "分类名称 *",
namePlaceholder: "输入分类名称",
slugLabel: "URL标识 *",
Expand Down
35 changes: 35 additions & 0 deletions src/i18n/locales/zh-CN/personal/Categories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const section = {
title: "我的分类",
createCategory: "新建分类",
loading: "加载分类中...",
emptyTitle: "还没有分类",
emptyHint: "点击“新建分类”创建你的第一个文章分类",
unknownDescription: "暂无描述",
unknownTime: "未知时间",
articleCount: "{{value}} 篇文章",
createdOn: "创建于 {{value}}",
parentNone: "无(顶级分类)",
parentLabel: "父级分类",
parentPlaceholder: "选择父级分类",
parentValue: "父级:{{value}}",
editTitle: "编辑分类",
nameLabel: "分类名称",
namePlaceholder: "输入分类名称",
descLabel: "分类描述",
descPlaceholder: "输入分类描述",
colorLabel: "分类颜色",
cancel: "取消",
saving: "保存中...",
update: "更新",
create: "创建",
nameRequired: "请输入分类名称",
deleteConfirmTitle: "确认删除",
deleteConfirmContent: '确定要删除分类 "{{name}}" 吗?相关文章将失去该分类。',
delete: "删除",
message: {
saveFailed: "保存分类失败,请稍后重试",
deleteFailed: "删除分类失败,请稍后重试",
},
} as const;

export default section;
1 change: 1 addition & 0 deletions src/i18n/locales/zh-CN/personal/Center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const section = {
assignments: "我的任务",
edit: "编辑资料",
tags: "我的标签",
categories: "我的分类",
stats: "数据统计",
organizations: "我的组织",
following: "我的关注",
Expand Down
2 changes: 1 addition & 1 deletion src/pages/admin/ArticleManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const ArticleManagement: React.FC = () => {
if (res) {
const options = res.list.map((cat) => ({
id: cat.id,
name: cat.name,
name: cat.author ? `${cat.name} · ${cat.author}` : cat.name,
color: cat.color || "#007bff",
}));
setCategoryOptions([{ id: "", name: t("articles.filter.allCategories"), color: "#6c757d" }, ...options]);
Expand Down
Loading
Loading