refactor(advancedSearch): reorder exports and improve type definitions
refactor(types): reorganize SearchCondition and AdvancedSearchState interfaces refactor(filterPresets): streamline useFilterPresets hook and localStorage handling refactor(filtering): clean up ColumnFilterButton and ColumnFilterPopover components refactor(loading): separate GriddyLoadingOverlay from GriddyLoadingSkeleton refactor(searchHistory): enhance useSearchHistory hook with persistence refactor(index): update exports for adapters and core components refactor(rendering): improve EditableCell and TableCell components for clarity refactor(rendering): enhance TableHeader and VirtualBody components for better readability
This commit is contained in:
@@ -1,42 +1,45 @@
|
||||
import { useCallback, useState } from 'react'
|
||||
import { useCallback, useState } from 'react';
|
||||
|
||||
const MAX_HISTORY = 10
|
||||
const MAX_HISTORY = 10;
|
||||
|
||||
export function useSearchHistory(persistenceKey?: string) {
|
||||
const key = persistenceKey ?? 'default';
|
||||
const [history, setHistory] = useState<string[]>(() => loadHistory(key));
|
||||
|
||||
const addEntry = useCallback(
|
||||
(query: string) => {
|
||||
if (!query.trim()) return;
|
||||
setHistory((prev) => {
|
||||
const filtered = prev.filter((h) => h !== query);
|
||||
const next = [query, ...filtered].slice(0, MAX_HISTORY);
|
||||
saveHistory(key, next);
|
||||
return next;
|
||||
});
|
||||
},
|
||||
[key]
|
||||
);
|
||||
|
||||
const clearHistory = useCallback(() => {
|
||||
setHistory([]);
|
||||
localStorage.removeItem(getStorageKey(key));
|
||||
}, [key]);
|
||||
|
||||
return { addEntry, clearHistory, history };
|
||||
}
|
||||
|
||||
function getStorageKey(persistenceKey: string) {
|
||||
return `griddy-search-history-${persistenceKey}`
|
||||
return `griddy-search-history-${persistenceKey}`;
|
||||
}
|
||||
|
||||
function loadHistory(persistenceKey: string): string[] {
|
||||
try {
|
||||
const raw = localStorage.getItem(getStorageKey(persistenceKey))
|
||||
return raw ? JSON.parse(raw) : []
|
||||
const raw = localStorage.getItem(getStorageKey(persistenceKey));
|
||||
return raw ? JSON.parse(raw) : [];
|
||||
} catch {
|
||||
return []
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function saveHistory(persistenceKey: string, history: string[]) {
|
||||
localStorage.setItem(getStorageKey(persistenceKey), JSON.stringify(history))
|
||||
}
|
||||
|
||||
export function useSearchHistory(persistenceKey?: string) {
|
||||
const key = persistenceKey ?? 'default'
|
||||
const [history, setHistory] = useState<string[]>(() => loadHistory(key))
|
||||
|
||||
const addEntry = useCallback((query: string) => {
|
||||
if (!query.trim()) return
|
||||
setHistory((prev) => {
|
||||
const filtered = prev.filter((h) => h !== query)
|
||||
const next = [query, ...filtered].slice(0, MAX_HISTORY)
|
||||
saveHistory(key, next)
|
||||
return next
|
||||
})
|
||||
}, [key])
|
||||
|
||||
const clearHistory = useCallback(() => {
|
||||
setHistory([])
|
||||
localStorage.removeItem(getStorageKey(key))
|
||||
}, [key])
|
||||
|
||||
return { addEntry, clearHistory, history }
|
||||
localStorage.setItem(getStorageKey(persistenceKey), JSON.stringify(history));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user