mirror of
https://github.com/MoonTechLab/LunaTV.git
synced 2026-05-14 00:39:37 +08:00
feat: d1 local cache
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
getAllPlayRecords,
|
||||
isFavorited,
|
||||
savePlayRecord,
|
||||
subscribeToDataUpdates,
|
||||
toggleFavorite,
|
||||
} from '@/lib/db.client';
|
||||
import { SearchResult } from '@/lib/types';
|
||||
@@ -916,6 +917,22 @@ function PlayPageClient() {
|
||||
})();
|
||||
}, [currentSource, currentId]);
|
||||
|
||||
// 监听收藏数据更新事件
|
||||
useEffect(() => {
|
||||
if (!currentSource || !currentId) return;
|
||||
|
||||
const unsubscribe = subscribeToDataUpdates(
|
||||
'favoritesUpdated',
|
||||
(favorites: Record<string, any>) => {
|
||||
const key = generateStorageKey(currentSource, currentId);
|
||||
const isFav = !!favorites[key];
|
||||
setFavorited(isFav);
|
||||
}
|
||||
);
|
||||
|
||||
return unsubscribe;
|
||||
}, [currentSource, currentId]);
|
||||
|
||||
// 切换收藏
|
||||
const handleToggleFavorite = async () => {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user