From e5e4ec624488a990e8a0e2917879577c822155b3 Mon Sep 17 00:00:00 2001 From: shinya Date: Mon, 21 Jul 2025 22:37:01 +0800 Subject: [PATCH] fix: douban selector reselect --- src/app/douban/page.tsx | 23 ++++++++++++++++------- src/components/DoubanSelector.tsx | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/app/douban/page.tsx b/src/app/douban/page.tsx index 0663b33..8f5c18e 100644 --- a/src/app/douban/page.tsx +++ b/src/app/douban/page.tsx @@ -226,16 +226,25 @@ function DoubanPageClient() { // 处理选择器变化 const handlePrimaryChange = useCallback( (value: string) => { - setLoading(true); - setPrimarySelection(value); + // 只有当值真正改变时才设置loading状态 + if (value !== primarySelection) { + setLoading(true); + setPrimarySelection(value); + } }, - [type] + [primarySelection] ); - const handleSecondaryChange = useCallback((value: string) => { - setLoading(true); - setSecondarySelection(value); - }, []); + const handleSecondaryChange = useCallback( + (value: string) => { + // 只有当值真正改变时才设置loading状态 + if (value !== secondarySelection) { + setLoading(true); + setSecondarySelection(value); + } + }, + [secondarySelection] + ); const getPageTitle = () => { // 根据 type 生成标题 diff --git a/src/components/DoubanSelector.tsx b/src/components/DoubanSelector.tsx index c297622..cfe6e3c 100644 --- a/src/components/DoubanSelector.tsx +++ b/src/components/DoubanSelector.tsx @@ -241,8 +241,8 @@ const DoubanSelector: React.FC = ({ onClick={() => onChange(option.value)} className={`relative z-10 px-2 py-1 sm:px-4 sm:py-2 text-xs sm:text-sm font-medium rounded-full transition-all duration-200 whitespace-nowrap ${ isActive - ? 'text-gray-900 dark:text-gray-100' - : 'text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100' + ? 'text-gray-900 dark:text-gray-100 cursor-default' + : 'text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 cursor-pointer' }`} > {option.label}