直播卡片

This commit is contained in:
Developer
2026-03-13 21:52:09 +08:00
parent b447ec0c76
commit a971a65f96
10 changed files with 860 additions and 100 deletions

View File

@@ -1,9 +1,9 @@
import { useState, useCallback, useRef } from 'react';
import { useState, useCallback, useRef, useMemo } from 'react';
import { getRecommendFeed } from '../services/bilibili';
import type { VideoItem } from '../services/types';
export function useVideoList() {
const [videos, setVideos] = useState<VideoItem[]>([]);
const [pages, setPages] = useState<VideoItem[][]>([]);
const [loading, setLoading] = useState(false);
const [refreshing, setRefreshing] = useState(false);
@@ -18,7 +18,7 @@ export function useVideoList() {
setLoading(true);
try {
const data = await getRecommendFeed(idx);
setVideos(prev => reset ? data : [...prev, ...data]);
setPages(prev => reset ? [data] : [...prev, data]);
freshIdxRef.current = idx + 1;
} catch (e) {
console.error('Failed to load videos', e);
@@ -34,5 +34,7 @@ export function useVideoList() {
load(true);
}, [load]);
return { videos, loading, refreshing, load, refresh };
const videos = useMemo(() => pages.flat(), [pages]);
return { videos, pages, loading, refreshing, load, refresh };
}