mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 07:31:12 -05:00
Implement type safety and JSONB elimination
This commit is contained in:
@@ -10,7 +10,7 @@ import { useQueryClient } from '@tanstack/react-query';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { logger } from '@/lib/logger';
|
||||
import { MODERATION_CONSTANTS } from '@/lib/moderation/constants';
|
||||
import type { RealtimeChannel } from '@supabase/supabase-js';
|
||||
import type { RealtimeChannel, RealtimePostgresChangesPayload } from '@supabase/supabase-js';
|
||||
import type { ModerationItem, EntityFilter, StatusFilter } from '@/types/moderation';
|
||||
import type { useEntityCache } from './useEntityCache';
|
||||
import type { useProfileCache } from './useProfileCache';
|
||||
@@ -21,6 +21,18 @@ import {
|
||||
buildModerationItem,
|
||||
} from '@/lib/moderation/realtime';
|
||||
|
||||
/**
|
||||
* Type-safe interface for submission content from realtime events
|
||||
*/
|
||||
interface SubmissionContent {
|
||||
action?: string;
|
||||
name?: string;
|
||||
entity_slug?: string;
|
||||
entity_name?: string;
|
||||
entity_id?: string;
|
||||
park_id?: string;
|
||||
}
|
||||
|
||||
type EntityCacheReturn = ReturnType<typeof useEntityCache>;
|
||||
type ProfileCacheReturn = ReturnType<typeof useProfileCache>;
|
||||
|
||||
@@ -164,7 +176,7 @@ export function useRealtimeSubscriptions(
|
||||
* Resolve entity names for a submission
|
||||
*/
|
||||
const resolveEntityNames = useCallback(async (submission: any) => {
|
||||
const content = submission.content as any;
|
||||
const content = submission.content as SubmissionContent;
|
||||
let entityName = content?.name || 'Unknown';
|
||||
let parkName: string | undefined;
|
||||
|
||||
@@ -242,8 +254,8 @@ export function useRealtimeSubscriptions(
|
||||
/**
|
||||
* Handle new submission INSERT event
|
||||
*/
|
||||
const handleInsert = useCallback(async (payload: any) => {
|
||||
const newSubmission = payload.new as any;
|
||||
const handleInsert = useCallback(async (payload: RealtimePostgresChangesPayload<any>) => {
|
||||
const newSubmission = payload.new;
|
||||
|
||||
logger.log('🆕 Realtime INSERT:', newSubmission.id);
|
||||
|
||||
@@ -314,9 +326,9 @@ export function useRealtimeSubscriptions(
|
||||
/**
|
||||
* Handle submission UPDATE event
|
||||
*/
|
||||
const handleUpdate = useCallback(async (payload: any) => {
|
||||
const updatedSubmission = payload.new as any;
|
||||
const oldSubmission = payload.old as any;
|
||||
const handleUpdate = useCallback(async (payload: RealtimePostgresChangesPayload<any>) => {
|
||||
const updatedSubmission = payload.new;
|
||||
const oldSubmission = payload.old;
|
||||
|
||||
logger.log('🔄 Realtime UPDATE:', updatedSubmission.id);
|
||||
|
||||
@@ -339,7 +351,8 @@ export function useRealtimeSubscriptions(
|
||||
}
|
||||
|
||||
// Skip debounce for status changes (critical updates)
|
||||
const isStatusChange = oldSubmission?.status !== updatedSubmission.status;
|
||||
const isStatusChange = oldSubmission && 'status' in oldSubmission
|
||||
&& oldSubmission.status !== updatedSubmission?.status;
|
||||
|
||||
if (isStatusChange) {
|
||||
logger.log('⚡ Status change detected, invalidating immediately');
|
||||
|
||||
Reference in New Issue
Block a user