feat: d1 local cache

This commit is contained in:
shinya
2025-07-14 22:09:53 +08:00
parent 7e6f4bcadc
commit b61430856a
6 changed files with 992 additions and 121 deletions

View File

@@ -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 (