Fixed duplicate realtime channels
X-Lovable-Edit-ID: edt-0895b82f-303a-4c3c-9b6c-f8ff455e9892 Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
@@ -71,7 +71,7 @@ export function AppShell({ children }: { children: ReactNode }) {
|
||||
if (data) setProfile({ full_name: data.full_name || "", avatar_url: (data as any).avatar_url ?? null });
|
||||
});
|
||||
const ch = supabase
|
||||
.channel(`profile-self-${user.id}`)
|
||||
.channel(`profile-self-${user.id}-${Math.random().toString(36).slice(2)}`)
|
||||
.on(
|
||||
"postgres_changes",
|
||||
{ event: "UPDATE", schema: "public", table: "profiles", filter: `id=eq.${user.id}` },
|
||||
|
||||
@@ -72,7 +72,7 @@ export function CaseTasksTab({ caseId }: { caseId: string }) {
|
||||
useEffect(() => {
|
||||
load();
|
||||
const ch = supabase
|
||||
.channel(`case-tasks-${caseId}`)
|
||||
.channel(`case-tasks-${caseId}-${Math.random().toString(36).slice(2)}`)
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "tasks", filter: `case_id=eq.${caseId}` }, () => load())
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "task_assignees" }, () => load())
|
||||
.subscribe();
|
||||
|
||||
@@ -72,7 +72,7 @@ export function CommentThread({
|
||||
useEffect(() => {
|
||||
load();
|
||||
const ch = supabase
|
||||
.channel(`comments-${entityType}-${entityId}`)
|
||||
.channel(`comments-${entityType}-${entityId}-${Math.random().toString(36).slice(2)}`)
|
||||
.on(
|
||||
"postgres_changes",
|
||||
{ event: "*", schema: "public", table: "comments", filter: `entity_id=eq.${entityId}` },
|
||||
|
||||
@@ -48,7 +48,7 @@ export function NotificationBell() {
|
||||
if (!user) return;
|
||||
load();
|
||||
const ch = supabase
|
||||
.channel(`notif-${user.id}`)
|
||||
.channel(`notif-${user.id}-${Math.random().toString(36).slice(2)}`)
|
||||
.on(
|
||||
"postgres_changes",
|
||||
{ event: "*", schema: "public", table: "notifications", filter: `user_id=eq.${user.id}` },
|
||||
|
||||
@@ -153,7 +153,7 @@ export function TaskDetailPanel({
|
||||
useEffect(() => {
|
||||
if (!open || !taskId) return;
|
||||
const ch = supabase
|
||||
.channel(`task-${taskId}`)
|
||||
.channel(`task-${taskId}-${Math.random().toString(36).slice(2)}`)
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "task_comments", filter: `task_id=eq.${taskId}` }, () => load())
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "task_assignees", filter: `task_id=eq.${taskId}` }, () => load())
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "tasks", filter: `id=eq.${taskId}` }, () => load())
|
||||
|
||||
@@ -63,7 +63,7 @@ export function useBubbleCounts(): Counts {
|
||||
if (!user) return;
|
||||
load();
|
||||
const ch = supabase
|
||||
.channel(`bubbles-${user.id}`)
|
||||
.channel(`bubbles-${user.id}-${Math.random().toString(36).slice(2)}`)
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "messages" }, () => load())
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "task_assignees" }, () => load())
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "tasks" }, () => load())
|
||||
|
||||
@@ -147,7 +147,7 @@ function MessagesPage() {
|
||||
useEffect(() => {
|
||||
if (!uid) return;
|
||||
const ch = supabase
|
||||
.channel("messages-global")
|
||||
.channel(`messages-global-${Math.random().toString(36).slice(2)}`)
|
||||
.on("postgres_changes", { event: "INSERT", schema: "public", table: "messages" }, () => {
|
||||
loadAll();
|
||||
refreshUnread();
|
||||
@@ -477,7 +477,7 @@ function ChatPanel({
|
||||
// Realtime subscription scoped to this conversation
|
||||
useEffect(() => {
|
||||
const ch = supabase
|
||||
.channel(`conv-${conversationId}`)
|
||||
.channel(`conv-${conversationId}-${Math.random().toString(36).slice(2)}`)
|
||||
.on(
|
||||
"postgres_changes",
|
||||
{ event: "*", schema: "public", table: "messages", filter: `conversation_id=eq.${conversationId}` },
|
||||
|
||||
@@ -105,7 +105,7 @@ function TasksPage() {
|
||||
useEffect(() => {
|
||||
load();
|
||||
const ch = supabase
|
||||
.channel("tasks-list")
|
||||
.channel(`tasks-list-${Math.random().toString(36).slice(2)}`)
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "tasks" }, () => load())
|
||||
.on("postgres_changes", { event: "*", schema: "public", table: "task_assignees" }, () => load())
|
||||
.subscribe();
|
||||
|
||||
Reference in New Issue
Block a user