@@ -21,7 +21,6 @@ import { reorderLinks } from '@/store/slices/linksSlice';
2121import { LinkCard } from './LinkCard' ;
2222import { Link } from '@/types/link' ;
2323import { showSuccess } from '@/utils/feedback' ;
24- import { getDefaultCategoryName } from '@/services/defaultData' ;
2524
2625interface LinkGridProps {
2726 onEdit ?: ( link : Link ) => void ;
@@ -36,15 +35,10 @@ interface LinkGridProps {
3635 * 支持根据分类和搜索状态过滤链接
3736 * 使用 React.memo 和 useMemo 优化性能
3837 */
39- const LinkGridBase : React . FC < LinkGridProps > = ( {
40- onEdit,
41- onDelete,
42- className,
43- style
44- } ) => {
38+ const LinkGridBase : React . FC < LinkGridProps > = ( { onEdit, onDelete, className, style } ) => {
4539 const dispatch = useAppDispatch ( ) ;
4640 const links = useAppSelector ( ( state ) => state . links . items ) ;
47- const currentCategory = useAppSelector ( ( state ) => state . settings . currentCategory || getDefaultCategoryName ( ) ) ;
41+ const currentCategory = useAppSelector ( ( state ) => state . ui . currentCategory || '主页' ) ;
4842 const searchQuery = useAppSelector ( ( state ) => state . search . query ) ;
4943 const searchResults = useAppSelector ( ( state ) => state . search . results ) ;
5044
@@ -97,20 +91,23 @@ const LinkGridBase: React.FC<LinkGridProps> = ({
9791 } , [ links , currentCategory , searchQuery , searchResults ] ) ;
9892
9993 // 处理拖拽结束
100- const handleDragEnd = useCallback ( ( event : DragEndEvent ) => {
101- const { active, over } = event ;
102-
103- if ( over && active . id !== over . id ) {
104- // 在所有链接中查找索引(不是 displayedLinks)
105- const oldIndex = links . findIndex ( ( link ) => link . id === active . id ) ;
106- const newIndex = links . findIndex ( ( link ) => link . id === over . id ) ;
107-
108- if ( oldIndex !== - 1 && newIndex !== - 1 ) {
109- dispatch ( reorderLinks ( { fromIndex : oldIndex , toIndex : newIndex } ) ) ;
110- showSuccess ( '链接排序已更新' ) ;
94+ const handleDragEnd = useCallback (
95+ ( event : DragEndEvent ) => {
96+ const { active, over } = event ;
97+
98+ if ( over && active . id !== over . id ) {
99+ // 在所有链接中查找索引(不是 displayedLinks)
100+ const oldIndex = links . findIndex ( ( link ) => link . id === active . id ) ;
101+ const newIndex = links . findIndex ( ( link ) => link . id === over . id ) ;
102+
103+ if ( oldIndex !== - 1 && newIndex !== - 1 ) {
104+ dispatch ( reorderLinks ( { fromIndex : oldIndex , toIndex : newIndex } ) ) ;
105+ showSuccess ( '链接排序已更新' ) ;
106+ }
111107 }
112- }
113- } , [ links , dispatch ] ) ;
108+ } ,
109+ [ links , dispatch ]
110+ ) ;
114111
115112 // 空状态判断
116113 const isEmpty = displayedLinks . length === 0 ;
@@ -121,24 +118,34 @@ const LinkGridBase: React.FC<LinkGridProps> = ({
121118 if ( isEmpty ) {
122119 if ( isSearchEmpty ) {
123120 return (
124- < div className = { className } style = { { ...style , display : 'flex' , alignItems : 'center' , justifyContent : 'center' , minHeight : '400px' } } >
125- < Empty
126- description = {
127- < span >
128- 没有找到与 "{ searchQuery } " 相关的链接
129- </ span >
130- }
131- />
121+ < div
122+ className = { className }
123+ style = { {
124+ ...style ,
125+ display : 'flex' ,
126+ alignItems : 'center' ,
127+ justifyContent : 'center' ,
128+ minHeight : '400px' ,
129+ } }
130+ >
131+ < Empty description = { < span > 没有找到与 "{ searchQuery } " 相关的链接</ span > } />
132132 </ div >
133133 ) ;
134134 }
135135
136136 if ( isCategoryEmpty ) {
137137 return (
138- < div className = { className } style = { { ...style , display : 'flex' , alignItems : 'center' , justifyContent : 'center' , minHeight : '400px' } } >
139- < Empty
140- description = { `${ currentCategory } 分类暂无链接` }
141- />
138+ < div
139+ className = { className }
140+ style = { {
141+ ...style ,
142+ display : 'flex' ,
143+ alignItems : 'center' ,
144+ justifyContent : 'center' ,
145+ minHeight : '400px' ,
146+ } }
147+ >
148+ < Empty description = { `${ currentCategory } 分类暂无链接` } />
142149 </ div >
143150 ) ;
144151 }
@@ -159,11 +166,17 @@ const LinkGridBase: React.FC<LinkGridProps> = ({
159166 strategy = { rectSortingStrategy }
160167 disabled = { ! isDraggingEnabled }
161168 >
162- < div
163- className = { `grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 3xl:grid-cols-6 4xl:grid-cols-7 5xl:grid-cols-8 6xl:grid-cols-9 7xl:grid-cols-10 gap-x-8 gap-y-6 p-4 sm:p-8 md:px-10 max-w-full ${ className || '' } ` }
169+ < div
170+ className = { `grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5 3xl:grid-cols-6 4xl:grid-cols-7 5xl:grid-cols-8 6xl:grid-cols-9 7xl:grid-cols-10 gap-x-8 gap-y-6 p-4 sm:p-8 md:px-10 max-w-full ${
171+ className || ''
172+ } `}
164173 style = { { ...style , width : '100%' , boxSizing : 'border-box' } }
165174 role = "region"
166- aria-label = { searchQuery . trim ( ) ? `搜索结果:${ displayedLinks . length } 个链接` : `${ currentCategory } 分类:${ displayedLinks . length } 个链接` }
175+ aria-label = {
176+ searchQuery . trim ( )
177+ ? `搜索结果:${ displayedLinks . length } 个链接`
178+ : `${ currentCategory } 分类:${ displayedLinks . length } 个链接`
179+ }
167180 >
168181 { displayedLinks . map ( ( link ) => (
169182 < LinkCard
0 commit comments