From bcb44302e164675e8a53ae83a7cd358def1cf4c7 Mon Sep 17 00:00:00 2001 From: Untone Date: Tue, 17 Oct 2023 09:37:11 +0300 Subject: [PATCH] message-handler-fix --- src/context/inbox.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/context/inbox.tsx b/src/context/inbox.tsx index 865f2a36..a09b4329 100644 --- a/src/context/inbox.tsx +++ b/src/context/inbox.tsx @@ -1,5 +1,5 @@ import type { Accessor, JSX } from 'solid-js' -import { createContext, createSignal, useContext } from 'solid-js' +import { createContext, createSignal, onMount, useContext } from 'solid-js' import type { Chat, Message, MutationCreateMessageArgs } from '../graphql/types.gen' import { inboxClient } from '../utils/apiClient' import { loadMessages } from '../stores/inbox' @@ -29,9 +29,16 @@ export const InboxProvider = (props: { children: JSX.Element }) => { actions: { setMessageHandler } } = useNotifications() - setMessageHandler((n: ServerNotification) => { - console.debug(n) - // TODO: handle new message + const handleMessage = (n: ServerNotification) => { + // TODO: handle notification types here: new_message edit_message del_message + const msg = n.payload as Message + console.log(msg) + } + + onMount(() => { + setMessageHandler((_) => { + return handleMessage + }) }) const loadChats = async () => {