This commit is contained in:
Andras Schmelczer 2026-06-25 22:29:52 +01:00
parent 2efa4d9f47
commit 5e73287eaf
99 changed files with 6392 additions and 1462 deletions

View file

@ -1,4 +1,5 @@
import { useState, useCallback, useRef, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import pb from '../lib/pocketbase';
import { apiUrl, authHeaders } from '../lib/api';
import { trackEvent } from '../lib/analytics';
@ -24,6 +25,7 @@ function nextPollDelay(attempt: number): number {
}
export function useSavedSearches(userId: string | null) {
const { t } = useTranslation();
const [searches, setSearches] = useState<SavedSearch[]>([]);
const [loading, setLoading] = useState(false);
const [saving, setSaving] = useState(false);
@ -127,11 +129,11 @@ export function useSavedSearches(userId: string | null) {
stopPolling();
}
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load searches');
setError(err instanceof Error ? err.message : t('savedPage.loadFailed'));
} finally {
setLoading(false);
}
}, [userId, fetchRecords, startPolling, stopPolling]);
}, [userId, fetchRecords, startPolling, stopPolling, t]);
const saveSearch = useCallback(
async (name: string, paramsOverride?: string) => {
@ -169,14 +171,14 @@ export function useSavedSearches(userId: string | null) {
console.warn('Background screenshot failed:', err);
});
} catch (err) {
const msg = err instanceof Error ? err.message : 'Failed to save search';
const msg = err instanceof Error ? err.message : t('savedPage.saveFailed');
setError(msg);
throw err;
} finally {
setSaving(false);
}
},
[userId, fetchSearches]
[userId, fetchSearches, t]
);
const deleteSearch = useCallback(async (id: string) => {
@ -186,27 +188,27 @@ export function useSavedSearches(userId: string | null) {
trackEvent('Search Delete');
setSearches((prev) => prev.filter((s) => s.id !== id));
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to delete search');
setError(err instanceof Error ? err.message : t('savedPage.deleteFailed'));
}
}, []);
}, [t]);
const updateSearchNotes = useCallback(async (id: string, notes: string) => {
try {
await pb.collection('saved_searches').update(id, { notes });
setSearches((prev) => prev.map((s) => (s.id === id ? { ...s, notes } : s)));
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to update notes');
setError(err instanceof Error ? err.message : t('savedPage.updateNotesFailed'));
}
}, []);
}, [t]);
const updateSearchName = useCallback(async (id: string, name: string) => {
try {
await pb.collection('saved_searches').update(id, { name });
setSearches((prev) => prev.map((s) => (s.id === id ? { ...s, name } : s)));
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to update name');
setError(err instanceof Error ? err.message : t('savedPage.updateNameFailed'));
}
}, []);
}, [t]);
const updateSearchParams = useCallback(
async (id: string, params: string) => {
@ -238,14 +240,14 @@ export function useSavedSearches(userId: string | null) {
console.warn('Background screenshot failed:', err);
});
} catch (err) {
const msg = err instanceof Error ? err.message : 'Failed to update search';
const msg = err instanceof Error ? err.message : t('savedPage.updateFailed');
setError(msg);
throw err;
} finally {
setSaving(false);
}
},
[userId, fetchSearches]
[userId, fetchSearches, t]
);
return {