Move to Phase 4-5

This commit is contained in:
gpt-engineer-app[bot]
2025-10-21 18:15:22 +00:00
parent ae548aa389
commit 3b82887974
8 changed files with 329 additions and 77 deletions

View File

@@ -2,6 +2,7 @@ import { useState, useEffect, useMemo, useCallback } from 'react';
import { supabase } from '@/integrations/supabase/client';
import { Park, Ride, Company } from '@/types/database';
import { logger } from '@/lib/logger';
import * as storage from '@/lib/localStorage';
export interface SearchResult {
id: string;
@@ -59,27 +60,9 @@ export function useSearch(options: UseSearchOptions = {}) {
// Load recent searches from localStorage
useEffect(() => {
try {
const stored = localStorage.getItem('thrillwiki_recent_searches');
if (stored) {
try {
const parsed = JSON.parse(stored);
if (Array.isArray(parsed)) {
setRecentSearches(parsed);
} else {
// Invalid format, clear it
logger.warn('Recent searches data is not an array, clearing');
localStorage.removeItem('thrillwiki_recent_searches');
}
} catch (parseError: unknown) {
// JSON parse failed, data is corrupted
console.error('Failed to parse recent searches from localStorage:', parseError);
localStorage.removeItem('thrillwiki_recent_searches');
}
}
} catch (error: unknown) {
// localStorage access failed
console.error('Error accessing localStorage:', error);
const searches = storage.getJSON<string[]>('thrillwiki_recent_searches', []);
if (Array.isArray(searches)) {
setRecentSearches(searches);
}
}, []);
@@ -206,13 +189,13 @@ export function useSearch(options: UseSearchOptions = {}) {
const updated = [searchQuery, ...recentSearches.filter(s => s !== searchQuery)].slice(0, 5);
setRecentSearches(updated);
localStorage.setItem('thrillwiki_recent_searches', JSON.stringify(updated));
storage.setJSON('thrillwiki_recent_searches', updated);
};
// Clear recent searches
const clearRecentSearches = () => {
setRecentSearches([]);
localStorage.removeItem('thrillwiki_recent_searches');
storage.removeItem('thrillwiki_recent_searches');
};
// Get suggestions (recent searches when no query)