mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 15:11:12 -05:00
Improve error handling and display for searches and uploads
Enhance user feedback by displaying search errors, refine photo submission fetching, add rate limiting cleanup logic, improve image upload cleanup, and strengthen moderator permission checks. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2741d09b-80fb-4f0a-bfd6-ababb2ac4bfc Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -31,6 +31,7 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
const [query, setQuery] = useState('');
|
||||
const [results, setResults] = useState<SearchResult[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [recentSearches, setRecentSearches] = useState<string[]>([]);
|
||||
const [debouncedQuery, setDebouncedQuery] = useState('');
|
||||
|
||||
@@ -83,10 +84,12 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
const search = useCallback(async (searchQuery: string) => {
|
||||
if (searchQuery.length < minQuery) {
|
||||
setResults([]);
|
||||
setError(null);
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const searchResults: SearchResult[] = [];
|
||||
|
||||
@@ -177,6 +180,8 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
setResults(searchResults.slice(0, limit));
|
||||
} catch (error) {
|
||||
console.error('Search error:', error);
|
||||
const errorMessage = error instanceof Error ? error.message : 'Failed to search. Please try again.';
|
||||
setError(errorMessage);
|
||||
setResults([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@@ -225,6 +230,7 @@ export function useSearch(options: UseSearchOptions = {}) {
|
||||
results,
|
||||
suggestions,
|
||||
loading,
|
||||
error,
|
||||
recentSearches,
|
||||
saveSearch,
|
||||
clearRecentSearches,
|
||||
|
||||
Reference in New Issue
Block a user