mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 23:31:12 -05:00
Refactor: Implement logging and JSONB cleanup
This commit is contained in:
@@ -2,6 +2,7 @@ import { useState, useEffect } from 'react';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { TechnicalSpecFilter, CoasterStatFilter } from '@/components/search/AdvancedRideFilters';
|
||||
import { useDebounce } from './useDebounce';
|
||||
import { handleError } from '@/lib/errorHandler';
|
||||
|
||||
interface AdvancedSearchOptions {
|
||||
query?: string;
|
||||
@@ -151,7 +152,14 @@ export function useAdvancedRideSearch(options: AdvancedSearchOptions) {
|
||||
|
||||
setResults(filteredResults);
|
||||
} catch (err) {
|
||||
console.error('Advanced search error:', err);
|
||||
handleError(err, {
|
||||
action: 'Advanced Ride Search',
|
||||
metadata: {
|
||||
query: options.query,
|
||||
category: options.category,
|
||||
manufacturer: options.manufacturer
|
||||
}
|
||||
});
|
||||
setError(err instanceof Error ? err.message : 'Search failed');
|
||||
setResults([]);
|
||||
} finally {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useAuth } from '@/hooks/useAuth';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { toast } from '@/hooks/use-toast';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
export function useBanCheck() {
|
||||
const { user } = useAuth();
|
||||
@@ -56,7 +57,7 @@ export function useBanCheck() {
|
||||
navigate('/');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Ban check error:', error);
|
||||
logger.error('Ban check error', { error, userId: user.id });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -203,7 +203,6 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
supabase.removeChannel(channelRef.current);
|
||||
} catch (error: unknown) {
|
||||
logger.error('Failed to cleanup realtime subscription', { entityType, entityId, error: getErrorMessage(error) });
|
||||
console.error('Error removing previous channel:', error);
|
||||
} finally {
|
||||
channelRef.current = null;
|
||||
}
|
||||
@@ -236,7 +235,6 @@ export function useEntityVersions(entityType: EntityType, entityId: string) {
|
||||
if (channelRef.current) {
|
||||
supabase.removeChannel(channelRef.current).catch((error) => {
|
||||
logger.error('Failed to cleanup realtime subscription', { entityType, entityId, error: getErrorMessage(error) });
|
||||
console.error('Error removing channel:', error);
|
||||
});
|
||||
channelRef.current = null;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
const STORAGE_KEY = 'queue-filter-panel-collapsed';
|
||||
|
||||
@@ -21,7 +22,7 @@ export function useFilterPanelState(): UseFilterPanelStateReturn {
|
||||
const isMobile = window.innerWidth < 768;
|
||||
return stored ? JSON.parse(stored) : isMobile;
|
||||
} catch (error) {
|
||||
console.error('Error reading filter panel state from localStorage:', error);
|
||||
logger.warn('Error reading filter panel state from localStorage', { error });
|
||||
return window.innerWidth < 768;
|
||||
}
|
||||
});
|
||||
@@ -31,7 +32,7 @@ export function useFilterPanelState(): UseFilterPanelStateReturn {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(isCollapsed));
|
||||
} catch (error) {
|
||||
console.error('Error saving filter panel state to localStorage:', error);
|
||||
logger.warn('Error saving filter panel state to localStorage', { error });
|
||||
}
|
||||
}, [isCollapsed]);
|
||||
|
||||
|
||||
@@ -64,7 +64,6 @@ export function usePhotoSubmissionItems(
|
||||
setPhotos(data || []);
|
||||
} catch (error: unknown) {
|
||||
const errorMsg = getErrorMessage(error);
|
||||
console.error('Error fetching photo submission items:', errorMsg);
|
||||
setError(errorMsg);
|
||||
setPhotos([]);
|
||||
} finally {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { useAuth } from '@/hooks/useAuth';
|
||||
import { queryKeys } from '@/lib/queryKeys';
|
||||
import { logger } from '@/lib/logger';
|
||||
|
||||
export type UserRole = 'admin' | 'moderator' | 'user' | 'superuser';
|
||||
|
||||
@@ -29,7 +30,7 @@ export function useUserRole() {
|
||||
.eq('user_id', user.id);
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching user roles:', error);
|
||||
logger.error('Error fetching user roles', { error, userId: user.id });
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ export function useUserRole() {
|
||||
.rpc('get_user_management_permissions', { _user_id: user.id });
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching user permissions:', error);
|
||||
logger.error('Error fetching user permissions', { error, userId: user.id });
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import type { EntityType, VersionDiff } from '@/types/versioning';
|
||||
import { handleError } from '@/lib/errorHandler';
|
||||
|
||||
/**
|
||||
* Hook to compare two versions of an entity and get the diff
|
||||
@@ -37,7 +38,10 @@ export function useVersionComparison(
|
||||
|
||||
setDiff(data as VersionDiff);
|
||||
} catch (err) {
|
||||
console.error('Error fetching version diff:', err);
|
||||
handleError(err, {
|
||||
action: 'Compare Versions',
|
||||
metadata: { entityType, fromVersionId, toVersionId }
|
||||
});
|
||||
setError(err instanceof Error ? err.message : 'Failed to compare versions');
|
||||
setDiff(null);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user