diff --git a/src/app/page.tsx b/src/app/page.tsx index da49b07..32961df 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -5,7 +5,7 @@ import Link from 'next/link'; import { Suspense, useEffect, useState } from 'react'; // 客户端收藏 API -import { getAllFavorites } from '@/lib/db.client'; +import { clearAllFavorites, getAllFavorites } from '@/lib/db.client'; import CapsuleSwitch from '@/components/CapsuleSwitch'; import ContinueWatching from '@/components/ContinueWatching'; @@ -118,9 +118,20 @@ function HomeClient() { {activeTab === 'favorites' ? ( // 收藏夹视图
-

- 我的收藏 -

+
+

我的收藏

+ {favoriteItems.length > 0 && ( + + )} +
{favoriteItems.map((item) => (
diff --git a/src/components/ContinueWatching.tsx b/src/components/ContinueWatching.tsx index 03a4d00..d5a7489 100644 --- a/src/components/ContinueWatching.tsx +++ b/src/components/ContinueWatching.tsx @@ -4,7 +4,7 @@ import { useEffect, useState } from 'react'; import type { PlayRecord } from '@/lib/db.client'; -import { getAllPlayRecords } from '@/lib/db.client'; +import { clearAllPlayRecords, getAllPlayRecords } from '@/lib/db.client'; import ScrollableRow from '@/components/ScrollableRow'; import VideoCard from '@/components/VideoCard'; @@ -71,9 +71,20 @@ export default function ContinueWatching({ className }: ContinueWatchingProps) { return (
-

- 继续观看 -

+
+

继续观看

+ {!loading && playRecords.length > 0 && ( + + )} +
{loading ? // 加载状态显示灰色占位数据 diff --git a/src/lib/db.client.ts b/src/lib/db.client.ts index f3b212c..6d041d8 100644 --- a/src/lib/db.client.ts +++ b/src/lib/db.client.ts @@ -439,3 +439,45 @@ export async function toggleFavorite( await saveFavorite(source, id, favoriteData); return true; } + +/** + * 清空全部播放记录 + */ +export async function clearAllPlayRecords(): Promise { + // 数据库模式 + if (STORAGE_TYPE === 'database') { + try { + await fetch('/api/playrecords', { + method: 'DELETE', + }); + } catch (err) { + console.error('清空播放记录失败:', err); + } + return; + } + + // localStorage 模式 + if (typeof window === 'undefined') return; + localStorage.removeItem(PLAY_RECORDS_KEY); +} + +/** + * 清空全部收藏 + */ +export async function clearAllFavorites(): Promise { + // 数据库模式 + if (STORAGE_TYPE === 'database') { + try { + await fetch('/api/favorites', { + method: 'DELETE', + }); + } catch (err) { + console.error('清空收藏失败:', err); + } + return; + } + + // localStorage 模式 + if (typeof window === 'undefined') return; + localStorage.removeItem(FAVORITES_KEY); +}