修复首页/api/favorites接口重复加载
This commit is contained in:
@@ -75,8 +75,20 @@ function DoubanPageClient() {
|
||||
sort: 'T',
|
||||
});
|
||||
|
||||
// 星期选择器状态
|
||||
const [selectedWeekday, setSelectedWeekday] = useState<string>('');
|
||||
// 星期选择器状态 - 默认选中今天
|
||||
const getTodayWeekday = (): string => {
|
||||
const today = new Date().getDay();
|
||||
// getDay() 返回 0-6,0 是周日,1-6 是周一到周六
|
||||
const weekdayMap = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
return weekdayMap[today];
|
||||
};
|
||||
|
||||
const [selectedWeekday, setSelectedWeekday] = useState<string>(() => {
|
||||
if (type === 'anime') {
|
||||
return getTodayWeekday();
|
||||
}
|
||||
return '';
|
||||
});
|
||||
|
||||
// 获取自定义分类数据
|
||||
useEffect(() => {
|
||||
@@ -146,23 +158,29 @@ function DoubanPageClient() {
|
||||
setSecondarySelection(firstCategory.query);
|
||||
}
|
||||
}
|
||||
setSelectedWeekday(''); // 清空星期选择
|
||||
} else {
|
||||
// 原有逻辑
|
||||
if (type === 'movie') {
|
||||
setPrimarySelection('热门');
|
||||
setSecondarySelection('全部');
|
||||
setSelectedWeekday(''); // 清空星期选择
|
||||
} else if (type === 'tv') {
|
||||
setPrimarySelection('最近热门');
|
||||
setSecondarySelection('tv');
|
||||
setSelectedWeekday(''); // 清空星期选择
|
||||
} else if (type === 'show') {
|
||||
setPrimarySelection('最近热门');
|
||||
setSecondarySelection('show');
|
||||
setSelectedWeekday(''); // 清空星期选择
|
||||
} else if (type === 'anime') {
|
||||
setPrimarySelection('每日放送');
|
||||
setSecondarySelection('全部');
|
||||
setSelectedWeekday(getTodayWeekday()); // 默认选中今天
|
||||
} else {
|
||||
setPrimarySelection('');
|
||||
setSecondarySelection('全部');
|
||||
setSelectedWeekday(''); // 清空星期选择
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,6 +642,15 @@ function DoubanPageClient() {
|
||||
} else {
|
||||
setPrimarySelection(value);
|
||||
}
|
||||
|
||||
// 动漫类型:切换到"每日放送"时设置当天,切换到其他分类时清空星期选择
|
||||
if (type === 'anime') {
|
||||
if (value === '每日放送') {
|
||||
setSelectedWeekday(getTodayWeekday());
|
||||
} else {
|
||||
setSelectedWeekday('');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -369,40 +369,81 @@ function HomeClient() {
|
||||
</ScrollableRow>
|
||||
</section>
|
||||
|
||||
{/* 番剧时间表 */}
|
||||
{bangumiCalendarData.length > 0 && (
|
||||
<section className='mb-8'>
|
||||
<div className='mb-4'>
|
||||
<h2 className='text-xl font-bold text-gray-800 dark:text-gray-200'>
|
||||
番剧时间表
|
||||
</h2>
|
||||
</div>
|
||||
{bangumiCalendarData.map((day) => (
|
||||
<div key={day.weekday.en} className='mb-6'>
|
||||
<h3 className='text-sm text-gray-600 dark:text-gray-400 mb-3'>
|
||||
{day.weekday.en}
|
||||
</h3>
|
||||
<ScrollableRow>
|
||||
{day.items.map((item) => (
|
||||
{/* 每日新番放送 */}
|
||||
<section className='mb-8'>
|
||||
<div className='mb-4 flex items-center justify-between'>
|
||||
<h2 className='text-xl font-bold text-gray-800 dark:text-gray-200'>
|
||||
新番放送
|
||||
</h2>
|
||||
<Link
|
||||
href='/douban?type=anime'
|
||||
className='flex items-center text-sm text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200'
|
||||
>
|
||||
查看更多
|
||||
<ChevronRight className='w-4 h-4 ml-1' />
|
||||
</Link>
|
||||
</div>
|
||||
<ScrollableRow>
|
||||
{loading
|
||||
? // 加载状态显示灰色占位数据
|
||||
Array.from({ length: 8 }).map((_, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className='min-w-[96px] w-24 sm:min-w-[180px] sm:w-44'
|
||||
>
|
||||
<div className='relative aspect-[2/3] w-full overflow-hidden rounded-lg bg-gray-200 animate-pulse dark:bg-gray-800'>
|
||||
<div className='absolute inset-0 bg-gray-300 dark:bg-gray-700'></div>
|
||||
</div>
|
||||
<div className='mt-2 h-4 bg-gray-200 rounded animate-pulse dark:bg-gray-800'></div>
|
||||
</div>
|
||||
))
|
||||
: // 展示当前日期的番剧
|
||||
(() => {
|
||||
// 获取当前日期对应的星期
|
||||
const today = new Date();
|
||||
const weekdays = [
|
||||
'Sun',
|
||||
'Mon',
|
||||
'Tue',
|
||||
'Wed',
|
||||
'Thu',
|
||||
'Fri',
|
||||
'Sat',
|
||||
];
|
||||
const currentWeekday = weekdays[today.getDay()];
|
||||
|
||||
// 找到当前星期对应的番剧数据
|
||||
const todayAnimes =
|
||||
bangumiCalendarData.find(
|
||||
(item) => item.weekday.en === currentWeekday
|
||||
)?.items || [];
|
||||
|
||||
return todayAnimes.map((anime, index) => (
|
||||
<div
|
||||
key={item.id}
|
||||
key={`${anime.id}-${index}`}
|
||||
className='min-w-[96px] w-24 sm:min-w-[180px] sm:w-44'
|
||||
>
|
||||
<VideoCard
|
||||
id={String(item.id)}
|
||||
poster={item.images.large}
|
||||
title={item.name}
|
||||
year={item.air_date || ''}
|
||||
type='tv'
|
||||
from='douban'
|
||||
title={anime.name_cn || anime.name}
|
||||
poster={
|
||||
anime.images?.large ||
|
||||
anime.images?.common ||
|
||||
anime.images?.medium ||
|
||||
anime.images?.small ||
|
||||
anime.images?.grid ||
|
||||
''
|
||||
}
|
||||
douban_id={anime.id}
|
||||
rate={anime.rating?.score?.toFixed(1) || ''}
|
||||
year={anime.air_date?.split('-')?.[0] || ''}
|
||||
isBangumi={true}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</ScrollableRow>
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
));
|
||||
})()}
|
||||
</ScrollableRow>
|
||||
</section>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user