mirror of
https://github.com/KuekHaoYang/KVideo.git
synced 2026-08-15 08:43:44 +08:00
refactor: remove unused cache management and selection clearing logic from hooks
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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,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
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user