mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 06:31:13 -05:00
Fix broadcast function search path
This commit is contained in:
@@ -43,70 +43,57 @@ export const useRealtimeSubmissions = (options: UseRealtimeSubmissionsOptions =
|
||||
|
||||
useEffect(() => {
|
||||
if (!realtimeEnabled) {
|
||||
console.log('[Realtime:content-submissions-changes] Realtime disabled');
|
||||
console.log('[Realtime:content-submissions] Realtime disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[Realtime:content-submissions-changes] Creating new channel');
|
||||
console.log('[Realtime:content-submissions] Creating new broadcast channel');
|
||||
setConnectionState('connecting');
|
||||
|
||||
const newChannel = supabase
|
||||
.channel('content-submissions-changes')
|
||||
.on(
|
||||
'postgres_changes',
|
||||
{
|
||||
event: 'INSERT',
|
||||
schema: 'public',
|
||||
table: 'content_submissions',
|
||||
},
|
||||
(payload) => {
|
||||
const setupChannel = async () => {
|
||||
// Set auth token for private channel
|
||||
await supabase.realtime.setAuth();
|
||||
|
||||
const newChannel = supabase
|
||||
.channel('moderation:content_submissions', {
|
||||
config: { private: true },
|
||||
})
|
||||
.on('broadcast', { event: 'INSERT' }, (payload) => {
|
||||
console.log('Submission inserted:', payload);
|
||||
onInsertRef.current?.(payload);
|
||||
}
|
||||
)
|
||||
.on(
|
||||
'postgres_changes',
|
||||
{
|
||||
event: 'UPDATE',
|
||||
schema: 'public',
|
||||
table: 'content_submissions',
|
||||
},
|
||||
(payload) => {
|
||||
})
|
||||
.on('broadcast', { event: 'UPDATE' }, (payload) => {
|
||||
console.log('Submission updated:', payload);
|
||||
onUpdateRef.current?.(payload);
|
||||
}
|
||||
)
|
||||
.on(
|
||||
'postgres_changes',
|
||||
{
|
||||
event: 'DELETE',
|
||||
schema: 'public',
|
||||
table: 'content_submissions',
|
||||
},
|
||||
(payload) => {
|
||||
})
|
||||
.on('broadcast', { event: 'DELETE' }, (payload) => {
|
||||
console.log('Submission deleted:', payload);
|
||||
onDeleteRef.current?.(payload);
|
||||
}
|
||||
)
|
||||
.subscribe((status) => {
|
||||
console.log('[Realtime:content-submissions-changes] Subscription status:', status);
|
||||
|
||||
if (status === 'SUBSCRIBED') {
|
||||
setConnectionState('connected');
|
||||
} else if (status === 'CHANNEL_ERROR') {
|
||||
setConnectionState('error');
|
||||
} else if (status === 'TIMED_OUT') {
|
||||
setConnectionState('disconnected');
|
||||
} else if (status === 'CLOSED') {
|
||||
setConnectionState('disconnected');
|
||||
}
|
||||
});
|
||||
})
|
||||
.subscribe((status) => {
|
||||
console.log('[Realtime:content-submissions] Subscription status:', status);
|
||||
|
||||
if (status === 'SUBSCRIBED') {
|
||||
setConnectionState('connected');
|
||||
} else if (status === 'CHANNEL_ERROR') {
|
||||
setConnectionState('error');
|
||||
} else if (status === 'TIMED_OUT') {
|
||||
setConnectionState('disconnected');
|
||||
} else if (status === 'CLOSED') {
|
||||
setConnectionState('disconnected');
|
||||
}
|
||||
});
|
||||
|
||||
setChannel(newChannel);
|
||||
setChannel(newChannel);
|
||||
};
|
||||
|
||||
setupChannel();
|
||||
|
||||
return () => {
|
||||
console.log('[Realtime:content-submissions-changes] Cleaning up channel');
|
||||
supabase.removeChannel(newChannel);
|
||||
if (channel) {
|
||||
console.log('[Realtime:content-submissions] Cleaning up channel');
|
||||
supabase.removeChannel(channel);
|
||||
}
|
||||
};
|
||||
}, [realtimeEnabled]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user