From 7fda54636d9cdf874339a592aecd0209d240a598 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Wed, 7 Dec 2022 15:47:43 +0300 Subject: [PATCH] subs-fix --- src/context/inbox.tsx | 16 ++++++++++++---- src/graphql/types.gen.ts | 23 ++++++++++++++--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/context/inbox.tsx b/src/context/inbox.tsx index a3d21ff0..49d05fa0 100644 --- a/src/context/inbox.tsx +++ b/src/context/inbox.tsx @@ -4,6 +4,8 @@ import { createChatClient } from '../graphql/privateGraphQLClient' import type { Chat } from '../graphql/types.gen' import { apiClient } from '../utils/apiClient' import newMessages from '../graphql/subs/new-messages' +import type { Client } from '@urql/core' +import { pipe, subscribe } from 'wonka' type InboxContextType = { chats: Accessor @@ -23,7 +25,7 @@ export function useInbox() { export const InboxProvider = (props: { children: JSX.Element }) => { const [chats, setChats] = createSignal([]) const [listener, setListener] = createSignal(console.debug) - const subclient = createMemo(() => createChatClient(listener())) + const subclient = createMemo(() => createChatClient(listener())) const loadChats = async () => { try { const newChats = await apiClient.getChats({ limit: 50, offset: 0 }) @@ -50,9 +52,15 @@ export const InboxProvider = (props: { children: JSX.Element }) => { loadChats, setListener // setting listening handler } - onMount(() => { - const resp = subclient().subscription(newMessages, {}) - console.debug(resp) + + onMount(async () => { + const { unsubscribe } = pipe( + subclient().subscription(newMessages, {}), + subscribe((result) => { + console.debug(result) // { data: ... } + // TODO: handle data result + }) + ) }) const value: InboxContextType = { chats, actions } return {props.children} diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 5dd514cf..a88c96b2 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -54,9 +54,9 @@ export type AuthorsBy = { } export type Chat = { - admins?: Maybe>> + admins?: Maybe>> createdAt: Scalars['Int'] - createdBy: Scalars['String'] + createdBy: Scalars['Int'] description?: Maybe id: Scalars['String'] members?: Maybe>> @@ -65,7 +65,7 @@ export type Chat = { title?: Maybe unread?: Maybe updatedAt: Scalars['Int'] - users?: Maybe>> + users?: Maybe>> } export type ChatInput = { @@ -78,6 +78,7 @@ export type ChatMember = { id: Scalars['Int'] lastSeen?: Maybe name: Scalars['String'] + online?: Maybe slug: Scalars['String'] userpic?: Maybe } @@ -139,12 +140,13 @@ export type LoadShoutsOptions = { } export type Message = { - author: Scalars['String'] + author: Scalars['Int'] body: Scalars['String'] chatId: Scalars['String'] createdAt: Scalars['Int'] id: Scalars['Int'] replyTo?: Maybe + seen?: Maybe updatedAt?: Maybe } @@ -353,6 +355,7 @@ export type Query = { loadShout?: Maybe loadShouts: Array> markdownBody: Scalars['String'] + searchMessages: Result searchRecipients: Result signIn: AuthResult signOut: AuthResult @@ -417,6 +420,12 @@ export type QueryMarkdownBodyArgs = { body: Scalars['String'] } +export type QuerySearchMessagesArgs = { + by: MessagesBy + limit?: InputMaybe + offset?: InputMaybe +} + export type QuerySearchRecipientsArgs = { limit?: InputMaybe offset?: InputMaybe @@ -620,17 +629,13 @@ export type Stat = { } export type Subscription = { - newMessage: Message + newMessages: Message onlineUpdated: Array reactionUpdated: ReactionUpdating shoutUpdated: Shout userUpdated: User } -export type SubscriptionNewMessageArgs = { - chats?: InputMaybe> -} - export type SubscriptionReactionUpdatedArgs = { shout: Scalars['String'] }