feat(skill-market): 优化筛选界面并恢复真实接口
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { Button } from 'antd';
|
||||
import { ListFilter } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { SkillCardSkeleton } from './SkillCard';
|
||||
|
||||
const SKELETON_COUNT = 8;
|
||||
|
||||
/**
|
||||
* 原型 .sm-catalog:结果栏(全部技能 · N 个技能 + 页面已有操作)、提示区、独立滚动的卡片列表、
|
||||
* 加载骨架(Ant Design Card loading)、空态与分页。数据、计数与分页条件均由页面传入。
|
||||
*/
|
||||
const SkillCatalog = ({
|
||||
total,
|
||||
scope = 'all',
|
||||
selectedTagCount = 0,
|
||||
showTotal = true,
|
||||
extra = null,
|
||||
notice = null,
|
||||
loading = false,
|
||||
empty = false,
|
||||
onReset,
|
||||
pagination = null,
|
||||
children,
|
||||
scrollResetKey,
|
||||
selectedTags,
|
||||
mineCount = 0,
|
||||
filtersOpen = false,
|
||||
onToggleFilters,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const listRef = useRef(null);
|
||||
// Reset creates a fresh tag array even when no filters are active.
|
||||
useEffect(() => {
|
||||
if (listRef.current) listRef.current.scrollTop = 0;
|
||||
}, [scrollResetKey, selectedTags]);
|
||||
const noOwnedSkills = scope === 'mine' && mineCount === 0;
|
||||
let body = null;
|
||||
if (loading) {
|
||||
body = (
|
||||
<div className='sm-grid'>
|
||||
{Array.from({ length: SKELETON_COUNT }, (_, index) => (
|
||||
<SkillCardSkeleton key={index} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
} else if (empty) {
|
||||
body = (
|
||||
<div className='sm-empty'>
|
||||
<h3>
|
||||
{t(noOwnedSkills ? '还没有加入任何技能' : '没有符合条件的技能')}
|
||||
</h3>
|
||||
<p>
|
||||
{t(
|
||||
noOwnedSkills
|
||||
? '浏览技能后,可加入我的技能。'
|
||||
: '试试其他关键词或调整标签。',
|
||||
)}
|
||||
</p>
|
||||
{onReset ? (
|
||||
<Button onClick={onReset}>
|
||||
{t(noOwnedSkills ? '浏览全部技能' : '重置筛选')}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
body = <div className='sm-grid'>{children}</div>;
|
||||
}
|
||||
return (
|
||||
<section className='sm-catalog'>
|
||||
<div className='sm-result-bar'>
|
||||
<div>
|
||||
<h2>{t(scope === 'mine' ? '我的技能' : '全部技能')}</h2>
|
||||
{showTotal ? <span>{t('{{total}} 个技能', { total })}</span> : null}
|
||||
{selectedTagCount > 0 && (
|
||||
<span className='sm-selected-count'>
|
||||
{t('已选 {{count}} 个标签', { count: selectedTagCount })}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<Button
|
||||
className='sm-mobile-filter'
|
||||
aria-expanded={filtersOpen}
|
||||
aria-controls='skill-market-filters'
|
||||
onClick={onToggleFilters}
|
||||
icon={<ListFilter size={16} aria-hidden='true' />}
|
||||
>
|
||||
{t(filtersOpen ? '收起筛选' : '筛选')}
|
||||
</Button>
|
||||
{extra ? <div className='sm-result-extra'>{extra}</div> : null}
|
||||
</div>
|
||||
{notice}
|
||||
<div
|
||||
ref={listRef}
|
||||
className='sm-list'
|
||||
tabIndex={0}
|
||||
aria-label={t('技能卡片列表')}
|
||||
>
|
||||
{body}
|
||||
{!loading && !empty && pagination ? (
|
||||
<div className='sm-pager'>{pagination}</div>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default SkillCatalog;
|
||||
Reference in New Issue
Block a user