refactor: remove unused cache management and selection clearing logic from hooks

This commit is contained in:
kuekhaoyang
2025-11-18 18:11:17 +08:00
parent 694a015a1e
commit 58f7c16d7b
3 changed files with 1 additions and 31 deletions
-13
View File
@@ -11,8 +11,6 @@ const CACHE_KEY = 'kvideo_search_cache';
const CACHE_DURATION = 10 * 60 * 1000; // 10 minutes
export function useSearchCache() {
const hasLoadedCache = useRef(false);
const saveToCache = (
query: string,
results: any[],
@@ -53,19 +51,8 @@ export function useSearchCache() {
}
};
const clearCache = () => {
try {
localStorage.removeItem(CACHE_KEY);
console.log('🗑️ Cache cleared');
} catch (error) {
console.error('Failed to clear cache:', error);
}
};
return {
saveToCache,
loadFromCache,
clearCache,
hasLoadedCache,
};
}
-7
View File
@@ -46,11 +46,6 @@ export function useSourceBadges<T extends { source?: string; sourceName?: string
});
}, []);
// Clear all selections
const clearSelection = useCallback(() => {
setSelectedSources(new Set());
}, []);
// Auto-cleanup: remove selected sources that no longer exist
useEffect(() => {
const availableSourceIds = new Set(availableSources.map(s => s.id));
@@ -72,7 +67,5 @@ export function useSourceBadges<T extends { source?: string; sourceName?: string
selectedSources,
filteredVideos,
toggleSource,
clearSelection,
hasFilters: selectedSources.size > 0,
};
}
+1 -11
View File
@@ -1,6 +1,6 @@
'use client';
import { useState, useEffect, useMemo, useCallback, useTransition } from 'react';
import { useState, useEffect, useMemo, useCallback } from 'react';
interface TypeBadge {
type: string;
@@ -19,7 +19,6 @@ interface TypeBadge {
*/
export function useTypeBadges<T extends { type_name?: string }>(videos: T[]) {
const [selectedTypes, setSelectedTypes] = useState<Set<string>>(new Set());
const [isPending, startTransition] = useTransition();
// Collect and count type badges from videos
const typeBadges = useMemo<TypeBadge[]>(() => {
@@ -50,7 +49,6 @@ export function useTypeBadges<T extends { type_name?: string }>(videos: T[]) {
}, [videos, selectedTypes]);
// Toggle type selection - useCallback to prevent re-creation
// Use startTransition to make UI feel responsive
const toggleType = useCallback((type: string) => {
// Update selected types immediately (high priority)
setSelectedTypes(prev => {
@@ -64,11 +62,6 @@ export function useTypeBadges<T extends { type_name?: string }>(videos: T[]) {
});
}, []);
// Clear all selections - useCallback to prevent re-creation
const clearSelection = useCallback(() => {
setSelectedTypes(new Set());
}, []);
// Auto-cleanup: remove selected types that no longer exist in badges
useEffect(() => {
const availableTypes = new Set(typeBadges.map(b => b.type));
@@ -91,8 +84,5 @@ export function useTypeBadges<T extends { type_name?: string }>(videos: T[]) {
selectedTypes,
filteredVideos,
toggleType,
clearSelection,
hasFilters: selectedTypes.size > 0,
isPending, // Export pending state
};
}