feat(SearchOverlay): persist search state across overlay open/close cycles
This commit is contained in:
parent
e93bca4e3e
commit
6d12cebc05
|
|
@ -127,6 +127,19 @@ function scanPhaseLabel(phase: ScanPhase, value: number): string {
|
||||||
type SortField = 'name' | 'size';
|
type SortField = 'name' | 'size';
|
||||||
type SortDir = 'asc' | 'desc';
|
type SortDir = 'asc' | 'desc';
|
||||||
|
|
||||||
|
// Persisted across overlay open/close cycles (survives unmount).
|
||||||
|
const _store = {
|
||||||
|
query: '',
|
||||||
|
results: [] as SearchResult[],
|
||||||
|
hasSearched: false,
|
||||||
|
showFilter: false,
|
||||||
|
filterSystem: null as string | null,
|
||||||
|
filterVideo: null as string | null,
|
||||||
|
filterLanguage: null as string | null,
|
||||||
|
sortField: 'name' as SortField,
|
||||||
|
sortDir: 'asc' as SortDir,
|
||||||
|
};
|
||||||
|
|
||||||
function FilterChips({
|
function FilterChips({
|
||||||
label, values, selected, onSelect,
|
label, values, selected, onSelect,
|
||||||
}: {
|
}: {
|
||||||
|
|
@ -153,29 +166,42 @@ function FilterChips({
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function SearchOverlay({ config, setConfig, onClose, onOpenFolder }: SearchOverlayProps) {
|
export default function SearchOverlay({ config, setConfig, onClose, onOpenFolder }: SearchOverlayProps) {
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState(() => _store.query);
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
const [isScanning, setIsScanning] = useState(false);
|
const [isScanning, setIsScanning] = useState(false);
|
||||||
const [scanPhase, setScanPhase] = useState<ScanPhase | null>(null);
|
const [scanPhase, setScanPhase] = useState<ScanPhase | null>(null);
|
||||||
const [scanValue, setScanValue] = useState(0);
|
const [scanValue, setScanValue] = useState(0);
|
||||||
const [results, setResults] = useState<SearchResult[]>([]);
|
const [results, setResults] = useState<SearchResult[]>(() => _store.results);
|
||||||
const [hasSearched, setHasSearched] = useState(false);
|
const [hasSearched, setHasSearched] = useState(() => _store.hasSearched);
|
||||||
const [mountEntry, setMountEntry] = useState<SearchResult | null>(null);
|
const [mountEntry, setMountEntry] = useState<SearchResult | null>(null);
|
||||||
const [actionEntry, setActionEntry] = useState<SearchResult | null>(null);
|
const [actionEntry, setActionEntry] = useState<SearchResult | null>(null);
|
||||||
const [searchError, setSearchError] = useState<string | null>(null);
|
const [searchError, setSearchError] = useState<string | null>(null);
|
||||||
const [dbBytes, setDbBytes] = useState<number | null>(null);
|
const [dbBytes, setDbBytes] = useState<number | null>(null);
|
||||||
const [dbPhase, setDbPhase] = useState<'idle' | 'downloading' | 'ready'>('idle');
|
const [dbPhase, setDbPhase] = useState<'idle' | 'downloading' | 'ready'>('idle');
|
||||||
const [showFilter, setShowFilter] = useState(false);
|
const [showFilter, setShowFilter] = useState(() => _store.showFilter);
|
||||||
const [filterSystem, setFilterSystem] = useState<string | null>(null);
|
const [filterSystem, setFilterSystem] = useState<string | null>(() => _store.filterSystem);
|
||||||
const [filterVideo, setFilterVideo] = useState<string | null>(null);
|
const [filterVideo, setFilterVideo] = useState<string | null>(() => _store.filterVideo);
|
||||||
const [filterLanguage, setFilterLanguage] = useState<string | null>(null);
|
const [filterLanguage, setFilterLanguage] = useState<string | null>(() => _store.filterLanguage);
|
||||||
const [sortField, setSortField] = useState<SortField>('name');
|
const [sortField, setSortField] = useState<SortField>(() => _store.sortField);
|
||||||
const [sortDir, setSortDir] = useState<SortDir>('asc');
|
const [sortDir, setSortDir] = useState<SortDir>(() => _store.sortDir);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLocateDbLoaded()) setDbPhase('ready');
|
if (isLocateDbLoaded()) setDbPhase('ready');
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
// Persist search state so it survives overlay close/reopen.
|
||||||
|
useEffect(() => {
|
||||||
|
_store.query = query;
|
||||||
|
_store.results = results;
|
||||||
|
_store.hasSearched = hasSearched;
|
||||||
|
_store.showFilter = showFilter;
|
||||||
|
_store.filterSystem = filterSystem;
|
||||||
|
_store.filterVideo = filterVideo;
|
||||||
|
_store.filterLanguage = filterLanguage;
|
||||||
|
_store.sortField = sortField;
|
||||||
|
_store.sortDir = sortDir;
|
||||||
|
}, [query, results, hasSearched, showFilter, filterSystem, filterVideo, filterLanguage, sortField, sortDir]);
|
||||||
|
|
||||||
const handleSearch = async () => {
|
const handleSearch = async () => {
|
||||||
if (!query.trim()) { toast.error('Please enter a search term'); return; }
|
if (!query.trim()) { toast.error('Please enter a search term'); return; }
|
||||||
setIsSearching(true);
|
setIsSearching(true);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user