Skip to content

Commit 74708d9

Browse files
committed
默认数据优化
1 parent aa8c929 commit 74708d9

File tree

4 files changed

+12
-114
lines changed

4 files changed

+12
-114
lines changed

.kiro/specs/frontend-navigation-site/ICON_FALLBACK_TEST.md

Lines changed: 0 additions & 112 deletions
This file was deleted.

components/navigation/LinkGrid.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { reorderLinks } from '@/store/slices/linksSlice';
2121
import { LinkCard } from './LinkCard';
2222
import { Link } from '@/types/link';
2323
import { showSuccess } from '@/utils/feedback';
24+
import { getDefaultCategoryName } from '@/services/defaultData';
2425

2526
interface LinkGridProps {
2627
onEdit?: (link: Link) => void;
@@ -43,7 +44,7 @@ const LinkGridBase: React.FC<LinkGridProps> = ({
4344
}) => {
4445
const dispatch = useAppDispatch();
4546
const links = useAppSelector((state) => state.links.items);
46-
const currentCategory = useAppSelector((state) => state.settings.currentCategory || '主页');
47+
const currentCategory = useAppSelector((state) => state.settings.currentCategory || getDefaultCategoryName());
4748
const searchQuery = useAppSelector((state) => state.search.query);
4849
const searchResults = useAppSelector((state) => state.search.results);
4950

services/defaultData.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,11 @@ export const defaultCategories: Category[] = (() => {
187187
updatedAt: Date.now(),
188188
}));
189189
})();
190+
191+
/**
192+
* 获取默认分类名称
193+
* 返回第一个分类的名称,如果没有分类则返回空字符串
194+
*/
195+
export const getDefaultCategoryName = (): string => {
196+
return defaultCategories.length > 0 ? defaultCategories[0].name : '';
197+
};

store/slices/settingsSlice.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
22
import { Settings, ThemeMode, LayoutMode, UpdateSettingsInput } from '@/types';
3+
import { getDefaultCategoryName } from '@/services/defaultData';
34

45
/**
56
* Settings 状态接口
@@ -18,7 +19,7 @@ const defaultSettings: Settings = {
1819
theme: 'system',
1920
searchEngine: 'google',
2021
layout: 'grid',
21-
currentCategory: '常用工具',
22+
currentCategory: getDefaultCategoryName(),
2223
showDescription: true,
2324
gridColumns: 6,
2425
};

0 commit comments

Comments
 (0)