Timothy Jaeryang Baek 4 months ago
parent
commit
cce8f37ada
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/lib/components/channel/Thread.svelte

+ 6 - 1
src/lib/components/channel/Thread.svelte

@@ -8,7 +8,7 @@
 	import XMark from '$lib/components/icons/XMark.svelte';
 	import MessageInput from './MessageInput.svelte';
 	import Messages from './Messages.svelte';
-	import { onMount, tick } from 'svelte';
+	import { onDestroy, onMount, tick } from 'svelte';
 	import { toast } from 'svelte-sonner';
 
 	export let threadId = null;
@@ -54,6 +54,7 @@
 	};
 
 	const channelEventHandler = async (event) => {
+		console.log(event);
 		if (event.channel_id === channel.id) {
 			const type = event?.data?.type ?? null;
 			const data = event?.data?.data ?? null;
@@ -148,6 +149,10 @@
 	onMount(() => {
 		$socket?.on('channel-events', channelEventHandler);
 	});
+
+	onDestroy(() => {
+		$socket?.off('channel-events', channelEventHandler);
+	});
 </script>
 
 {#if channel}