import { Heart, Images } from "lucide-react"; import Link from "next/link"; import { memo, type ReactNode, useEffect, useRef } from "react"; import { awemeHref } from "@/lib/playback-context"; import type { PlaylistState } from "../hooks/usePlaylist"; interface WorksGridProps { /** 所在标签页当前可见 */ active: boolean; list: PlaylistState; currentId: string; /** 点击作品跳转时带上的播放上下文查询串 */ hrefQuery: string; onSelect: () => void; /** 列表只有当前这一个作品时的提示 */ singleHint?: string; /** 网格上方的标题栏 */ header: ReactNode; /** 标题栏下方的附加内容(如相关 tag) */ subheader?: ReactNode; } function formatCount(n: number): string { if (n >= 10000) return `${(n / 10000).toFixed(n >= 100000 ? 0 : 1)}万`; return String(n); } function PlayingBars() { return ( {[60, 100, 40].map((height, i) => ( ))} ); } // 侧栏里的作品封面网格(TA的作品 / 搜索结果 / hashtag 共用):当前作品标「播放中」,点作品就地切换 export const WorksGrid = memo(function WorksGrid({ active, list, currentId, hrefQuery, onSelect, singleHint, header, subheader, }: WorksGridProps) { const scrollRef = useRef(null); const currentRef = useRef(null); const items = list.items ?? []; // 让「播放中」的作品保持在可见区域(切换作品或列表加载完成时重新定位) // biome-ignore lint/correctness/useExhaustiveDependencies: currentId / items.length 只用来触发重新定位 useEffect(() => { if (!active) return; const container = scrollRef.current; const el = currentRef.current; if (!container || !el) return; const top = el.offsetTop - container.offsetTop; const bottom = top + el.offsetHeight; if ( top < container.scrollTop || bottom > container.scrollTop + container.clientHeight ) { container.scrollTop = top - (container.clientHeight - el.offsetHeight) / 2; } }, [active, currentId, items.length]); return (
{header}
{subheader}
{list.loading && !list.items && (
加载中...
)} {list.error && !list.items && (
{list.error}
)}
{items.map((item) => { const isCurrent = item.aweme_id === currentId; return ( {item.cover_url ? ( // biome-ignore lint/performance/noImgElement: 封面来自对象存储,不走 next/image {item.desc?.slice(0, ) : null}
{item.type === "image" && ( 图文 )} {isCurrent ? (
播放中
) : ( {formatCount(item.likes)} )} ); })}
{list.items && items.length <= 1 && singleHint && (
{singleHint}
)} {list.items && list.total > items.length && (
只列出前 {items.length} 个,共 {list.total} 个
)}
); });