feat: 统计页面添加分类筛选与搜索优化

- 统计页面添加分类多选筛选功能
- 点击分类可跳转到搜索页面查看详情
- 搜索页面添加 URL 同步与自动搜索
- 提取 useCategories hook 消除重复代码
- 修复自定义分类图标显示问题
- 添加 useMemo 优化计算性能

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Developer
2026-03-17 13:35:40 +08:00
co-authored by Claude Opus 4.6
parent b5f9a238bb
commit a89d4f2402
6 changed files with 345 additions and 60 deletions
+45
View File
@@ -0,0 +1,45 @@
import { useState, useEffect } from 'react';
import { getCategories, isLoggedIn } from '../lib/api';
import { DEFAULT_CATEGORIES } from '../lib/categories';
export function useCategories() {
const [categories, setCategories] = useState(DEFAULT_CATEGORIES);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (!isLoggedIn()) {
setLoading(false);
return;
}
const loadCategories = async () => {
try {
const categoriesData = await getCategories();
if (categoriesData) {
setCategories({
expense: [
...DEFAULT_CATEGORIES.expense,
...(categoriesData.expense || []).filter(
c => !DEFAULT_CATEGORIES.expense.some(d => d.name === c.name)
)
],
income: [
...DEFAULT_CATEGORIES.income,
...(categoriesData.income || []).filter(
c => !DEFAULT_CATEGORIES.income.some(d => d.name === c.name)
)
],
});
}
} catch (err) {
console.error(err);
} finally {
setLoading(false);
}
};
loadCategories();
}, []);
return { categories, loading };
}