Skip to content
48 changes: 11 additions & 37 deletions src/components/DiscoveryView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,6 @@ export const DiscoveryView: React.FC = React.memo(() => {

const currentLastRefresh = discoveryLastRefresh?.[selectedDiscoveryChannel] ?? null;
const currentIsLoading = discoveryIsLoading?.[selectedDiscoveryChannel] ?? false;
const currentHasMore = discoveryHasMore?.[selectedDiscoveryChannel] ?? false;
const currentNextPage = discoveryNextPage?.[selectedDiscoveryChannel] ?? 1;
const currentChannel = safeDiscoveryChannels.find(ch => ch.id === selectedDiscoveryChannel);
const currentChannelIcon = currentChannel?.icon || 'trending';
const currentChannelStyle = discoveryChannelStyleMap[currentChannelIcon] || discoveryChannelStyleMap.trending;
Expand Down Expand Up @@ -940,12 +938,16 @@ export const DiscoveryView: React.FC = React.memo(() => {
const handlePageChange = useCallback((page: number) => {
setCurrentPage(page);

// 如果目标页的数据还没有加载,先加载数据
const requiredItems = page * ITEMS_PER_PAGE;
if (allRepos.length < requiredItems && currentHasMore && !currentIsLoading) {
refreshChannel(selectedDiscoveryChannel, currentNextPage, true);
// 分页切换时滚动到顶部
if (scrollContainerRef.current) {
scrollContainerRef.current.scrollTo({
top: 0,
behavior: 'smooth'
});
}
}, [allRepos.length, currentHasMore, currentIsLoading, currentNextPage, refreshChannel, selectedDiscoveryChannel]);

// 分页逻辑:仅设置当前页码,不再自动加载更多数据
}, [setCurrentPage]);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

const refreshAll = useCallback(async () => {
const enabledChannels = safeDiscoveryChannels.filter(ch => ch.enabled);
Expand Down Expand Up @@ -1294,12 +1296,7 @@ export const DiscoveryView: React.FC = React.memo(() => {
)}
</span>
</div>
{currentHasMore && (
<div className="flex items-center gap-1.5 text-blue-500 text-xs font-medium bg-blue-50 dark:bg-blue-900/20 px-2.5 py-1 rounded-lg">
<div className="w-1.5 h-1.5 rounded-full bg-blue-500 animate-pulse" />
{t('还有更多', 'More available')}
</div>
)}

</div>
)}

Expand All @@ -1311,30 +1308,7 @@ export const DiscoveryView: React.FC = React.memo(() => {
language={language}
/>

{/* Load More Button */}
{currentHasMore && (
<div className="flex justify-center py-4">
<button
onClick={() => refreshChannel(selectedDiscoveryChannel, currentNextPage, true)}
disabled={currentIsLoading}
className={isDesktopSafeMode
? 'group px-8 py-3 rounded-lg bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-600 border border-gray-200 dark:border-gray-700 disabled:opacity-50 disabled:cursor-not-allowed transition-colors flex items-center gap-2.5 text-sm font-medium'
: 'group px-8 py-3 rounded-xl bg-gray-100/80 dark:bg-gray-700/60 text-gray-600 dark:text-gray-300 hover:bg-blue-50 dark:hover:bg-blue-900/20 hover:text-blue-600 dark:hover:text-blue-400 border border-gray-200 dark:border-gray-700 hover:border-blue-300 dark:hover:border-blue-800 disabled:opacity-50 disabled:cursor-not-allowed transition-all duration-200 flex items-center gap-2.5 text-sm font-medium shadow-sm'}
>
{currentIsLoading ? (
<>
<Loader2 className="w-4 h-4 animate-spin" />
{t('加载中...', 'Loading...')}
</>
) : (
<>
<ChevronDown className="w-4 h-4 group-hover:translate-y-0.5 transition-transform" />
{t('加载更多数据', 'Load More Data')}
</>
)}
</button>
</div>
)}

</div>

{/* 滚动到底部按钮 */}
Expand Down
18 changes: 9 additions & 9 deletions src/components/RepositoryEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const RepositoryEditModal: React.FC<RepositoryEditModalProps> = ({
// 优先级: custom_description(非undefined) > ai_summary > description
// custom_description === '' 表示用户明确清空,来源为 'none'
let descSource: DataSource;
if (repo.custom_description !== undefined) {
if (repo.custom_description !== undefined && repo.custom_description !== null) {
if (repo.custom_description.trim() !== '') {
descSource = 'custom';
} else {
Expand Down Expand Up @@ -176,7 +176,7 @@ export const RepositoryEditModal: React.FC<RepositoryEditModalProps> = ({
// custom_description === '' 表示用户明确清空,表单中显示为空
// custom_description === undefined 表示无自定义,回退到AI/原始
let effectiveDescription = '';
if (repo.custom_description !== undefined) {
if (repo.custom_description !== undefined && repo.custom_description !== null) {
effectiveDescription = repo.custom_description;
} else if (repo.ai_summary && repo.ai_summary.trim() !== '') {
effectiveDescription = repo.ai_summary;
Expand Down Expand Up @@ -277,7 +277,7 @@ export const RepositoryEditModal: React.FC<RepositoryEditModalProps> = ({
case 'keep-custom':
default: {
// 保持自定义:检查内容是否与原始来源一致
const descTrimmed = formData.description.trim();
const descTrimmed = (formData.description || '').trim();

// 如果内容为空,视为清除
if (descTrimmed === '') {
Expand Down Expand Up @@ -457,9 +457,9 @@ export const RepositoryEditModal: React.FC<RepositoryEditModalProps> = ({
if (!repository) return { description: false, tags: false, category: false };

const isDescCustom = editIntent.description === 'keep-custom' &&
formData.description.trim() !== '' &&
formData.description.trim() !== (repository.ai_summary || '').trim() &&
formData.description.trim() !== (repository.description || '').trim();
(formData.description || '').trim() !== '' &&
(formData.description || '').trim() !== (repository.ai_summary || '').trim() &&
(formData.description || '').trim() !== (repository.description || '').trim();

const aiTags = repository.ai_tags || [];
const topics = repository.topics || [];
Expand Down Expand Up @@ -644,12 +644,12 @@ export const RepositoryEditModal: React.FC<RepositoryEditModalProps> = ({
{/* Source Indicator */}
<div className="flex items-center gap-2 mb-3">
<span className="text-xs text-gray-500 dark:text-gray-400">{t('当前来源:', 'Source:')}</span>
{editIntent.description === 'keep-custom' && formData.description.trim() !== '' ? (
{editIntent.description === 'keep-custom' && (formData.description || '').trim() !== '' ? (
<span className="inline-flex items-center px-2 py-0.5 text-[11px] font-medium bg-orange-100 text-orange-700 dark:bg-orange-900 dark:text-orange-300 rounded-full">
<Edit3 className="w-3 h-3 mr-1" />
{t('自定义', 'Custom')}
</span>
) : editIntent.description === 'keep-custom' && formData.description.trim() === '' ? (
) : editIntent.description === 'keep-custom' && (formData.description || '').trim() === '' ? (
<span className="inline-flex items-center px-2 py-0.5 text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300 rounded-full">
<AlertTriangle className="w-3 h-3 mr-1" />
{t('将回退', 'Will fallback')}
Expand Down Expand Up @@ -720,7 +720,7 @@ export const RepositoryEditModal: React.FC<RepositoryEditModalProps> = ({
</span>
</p>
</div>
) : editIntent.description === 'keep-custom' && formData.description.trim() === '' ? (
) : editIntent.description === 'keep-custom' && (formData.description || '').trim() === '' ? (
<div className="mt-3 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg">
<p className="text-xs text-amber-700 dark:text-amber-400 flex items-start">
<AlertTriangle className="w-4 h-4 mr-1.5 mt-0.5 flex-shrink-0" />
Expand Down
Loading