fix: sources panel mobile optimize

This commit is contained in:
shinya
2025-08-17 16:53:22 +08:00
parent ad9fe27637
commit 714c4e0e9c
2 changed files with 15 additions and 42 deletions

View File

@@ -66,22 +66,8 @@ function SearchPageClient() {
}); });
return res; return res;
})(); })();
const douban_id = (() => {
const idMap = new Map<number, number>();
group.forEach((g) => {
if (g.douban_id && g.douban_id !== 0) {
idMap.set(g.douban_id, (idMap.get(g.douban_id) || 0) + 1);
}
});
let max = 0;
let res: number | undefined = undefined;
idMap.forEach((v, k) => {
if (v > max) { max = v; res = k; }
});
return res;
})();
const source_names = Array.from(new Set(group.map((g) => g.source_name).filter(Boolean))) as string[]; const source_names = Array.from(new Set(group.map((g) => g.source_name).filter(Boolean))) as string[];
return { episodes, douban_id, source_names }; return { episodes, source_names };
}; };
// 过滤器:非聚合与聚合 // 过滤器:非聚合与聚合
const [filterAll, setFilterAll] = useState<{ source: string; title: string; year: string; yearOrder: 'none' | 'asc' | 'desc' }>({ const [filterAll, setFilterAll] = useState<{ source: string; title: string; year: string; yearOrder: 'none' | 'asc' | 'desc' }>({
@@ -189,9 +175,6 @@ function SearchPageClient() {
// 对比变化并调用对应的 set 方法 // 对比变化并调用对应的 set 方法
const ref = groupRefs.current.get(mapKey); const ref = groupRefs.current.get(mapKey);
if (ref && ref.current) { if (ref && ref.current) {
if (prev.douban_id !== stats.douban_id) {
ref.current.setDoubanId(stats.douban_id);
}
if (prev.episodes !== stats.episodes) { if (prev.episodes !== stats.episodes) {
ref.current.setEpisodes(stats.episodes); ref.current.setEpisodes(stats.episodes);
} }
@@ -680,12 +663,12 @@ function SearchPageClient() {
const title = group[0]?.title || ''; const title = group[0]?.title || '';
const poster = group[0]?.poster || ''; const poster = group[0]?.poster || '';
const year = group[0]?.year || 'unknown'; const year = group[0]?.year || 'unknown';
const { episodes, douban_id, source_names } = computeGroupStats(group); const { episodes, source_names } = computeGroupStats(group);
const type = episodes === 1 ? 'movie' : 'tv'; const type = episodes === 1 ? 'movie' : 'tv';
// 如果该聚合第一次出现,写入初始统计 // 如果该聚合第一次出现,写入初始统计
if (!groupStatsRef.current.has(mapKey)) { if (!groupStatsRef.current.has(mapKey)) {
groupStatsRef.current.set(mapKey, { episodes, douban_id, source_names }); groupStatsRef.current.set(mapKey, { episodes, source_names });
} }
return ( return (
@@ -698,7 +681,6 @@ function SearchPageClient() {
poster={poster} poster={poster}
year={year} year={year}
episodes={episodes} episodes={episodes}
douban_id={douban_id}
source_names={source_names} source_names={source_names}
query={ query={
searchQuery.trim() !== title searchQuery.trim() !== title

View File

@@ -47,7 +47,6 @@ export interface VideoCardProps {
} }
export type VideoCardHandle = { export type VideoCardHandle = {
setDoubanId: (id?: number) => void;
setEpisodes: (episodes?: number) => void; setEpisodes: (episodes?: number) => void;
setSourceNames: (names?: string[]) => void; setSourceNames: (names?: string[]) => void;
}; };
@@ -80,9 +79,6 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
// 可外部修改的可控字段 // 可外部修改的可控字段
const [dynamicDoubanId, setDynamicDoubanId] = useState<number | undefined>(
douban_id
);
const [dynamicEpisodes, setDynamicEpisodes] = useState<number | undefined>( const [dynamicEpisodes, setDynamicEpisodes] = useState<number | undefined>(
episodes episodes
); );
@@ -90,10 +86,6 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
source_names source_names
); );
useEffect(() => {
setDynamicDoubanId(douban_id);
}, [douban_id]);
useEffect(() => { useEffect(() => {
setDynamicEpisodes(episodes); setDynamicEpisodes(episodes);
}, [episodes]); }, [episodes]);
@@ -103,7 +95,6 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
}, [source_names]); }, [source_names]);
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
setDoubanId: (id?: number) => setDynamicDoubanId(id),
setEpisodes: (eps?: number) => setDynamicEpisodes(eps), setEpisodes: (eps?: number) => setDynamicEpisodes(eps),
setSourceNames: (names?: string[]) => setDynamicSourceNames(names), setSourceNames: (names?: string[]) => setDynamicSourceNames(names),
})); }));
@@ -112,7 +103,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
const actualPoster = poster; const actualPoster = poster;
const actualSource = source; const actualSource = source;
const actualId = id; const actualId = id;
const actualDoubanId = dynamicDoubanId; const actualDoubanId = douban_id;
const actualEpisodes = dynamicEpisodes; const actualEpisodes = dynamicEpisodes;
const actualYear = year; const actualYear = year;
const actualQuery = query || ''; const actualQuery = query || '';
@@ -274,7 +265,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
}, },
}; };
return configs[from] || configs.search; return configs[from] || configs.search;
}, [from, isAggregate, actualDoubanId, rate]); }, [from, isAggregate, douban_id, rate]);
return ( return (
<div <div
@@ -395,7 +386,7 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
return ( return (
<div className='absolute bottom-2 right-2 opacity-0 transition-all duration-300 ease-in-out delay-75 group-hover:opacity-100'> <div className='absolute bottom-2 right-2 opacity-0 transition-all duration-300 ease-in-out delay-75 group-hover:opacity-100'>
<div className='relative group/sources'> <div className='relative group/sources'>
<div className='bg-gray-700 text-white text-xs font-bold w-7 h-7 rounded-full flex items-center justify-center shadow-md hover:bg-gray-600 hover:scale-[1.1] transition-all duration-300 ease-out cursor-pointer'> <div className='bg-gray-700 text-white text-xs font-bold w-6 h-6 sm:w-7 sm:h-7 rounded-full flex items-center justify-center shadow-md hover:bg-gray-600 hover:scale-[1.1] transition-all duration-300 ease-out cursor-pointer'>
{sourceCount} {sourceCount}
</div> </div>
@@ -420,14 +411,14 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
const remainingCount = sortedSources.length - maxDisplayCount; const remainingCount = sortedSources.length - maxDisplayCount;
return ( return (
<div className='absolute bottom-full right-0 mb-2 opacity-0 invisible group-hover/sources:opacity-100 group-hover/sources:visible transition-all duration-200 ease-out delay-100 pointer-events-none z-50'> <div className='absolute bottom-full mb-2 opacity-0 invisible group-hover/sources:opacity-100 group-hover/sources:visible transition-all duration-200 ease-out delay-100 pointer-events-none z-50 right-0 sm:right-0 -translate-x-0 sm:translate-x-0'>
<div className='bg-gray-800/90 backdrop-blur-sm text-white text-xs rounded-lg shadow-xl border border-white/10 p-2 min-w-[120px] max-w-[200px]'> <div className='bg-gray-800/90 backdrop-blur-sm text-white text-xs sm:text-xs rounded-lg shadow-xl border border-white/10 p-1.5 sm:p-2 min-w-[100px] sm:min-w-[120px] max-w-[140px] sm:max-w-[200px] overflow-hidden'>
{/* 单列布局 */} {/* 单列布局 */}
<div className='space-y-1'> <div className='space-y-0.5 sm:space-y-1'>
{displaySources.map((sourceName, index) => ( {displaySources.map((sourceName, index) => (
<div key={index} className='flex items-center gap-1.5'> <div key={index} className='flex items-center gap-1 sm:gap-1.5'>
<div className='w-1 h-1 bg-blue-400 rounded-full flex-shrink-0'></div> <div className='w-0.5 h-0.5 sm:w-1 sm:h-1 bg-blue-400 rounded-full flex-shrink-0'></div>
<span className='truncate text-xs' title={sourceName}> <span className='truncate text-[10px] sm:text-xs leading-tight' title={sourceName}>
{sourceName} {sourceName}
</span> </span>
</div> </div>
@@ -436,15 +427,15 @@ const VideoCard = forwardRef<VideoCardHandle, VideoCardProps>(function VideoCard
{/* 显示更多提示 */} {/* 显示更多提示 */}
{hasMore && ( {hasMore && (
<div className='mt-2 pt-1.5 border-t border-gray-700/50'> <div className='mt-1 sm:mt-2 pt-1 sm:pt-1.5 border-t border-gray-700/50'>
<div className='flex items-center justify-center text-gray-400'> <div className='flex items-center justify-center text-gray-400'>
<span className='text-xs font-medium'>+{remainingCount} </span> <span className='text-[10px] sm:text-xs font-medium'>+{remainingCount} </span>
</div> </div>
</div> </div>
)} )}
{/* 小箭头 */} {/* 小箭头 */}
<div className='absolute top-full right-3 w-0 h-0 border-l-[6px] border-r-[6px] border-t-[6px] border-transparent border-t-gray-800/90'></div> <div className='absolute top-full right-2 sm:right-3 w-0 h-0 border-l-[4px] border-r-[4px] border-t-[4px] sm:border-l-[6px] sm:border-r-[6px] sm:border-t-[6px] border-transparent border-t-gray-800/90'></div>
</div> </div>
</div> </div>
); );