From 1aad822fc248632e21268ff1c031a3fbb1611f08 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Fri, 3 Nov 2023 20:13:46 +0700 Subject: [PATCH 1/5] Use setConfig instead of init every single grill chat instance --- package.json | 2 +- src/components/chat/ChatIframe.tsx | 38 ++++++++++++++++++++++++------ yarn.lock | 8 +++---- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index e2072e6e..372659d8 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@polkawallet/bridge": "0.1.3", "@reduxjs/toolkit": "^1.6.2", "@subsocial/api": "0.8.13", - "@subsocial/grill-widget": "0.0.11", + "@subsocial/grill-widget": "^0.0.12", "@subsocial/resource-discussions": "0.0.4", "@subsocial/utils": "0.8.13", "@zeit/next-css": "^1.0.1", diff --git a/src/components/chat/ChatIframe.tsx b/src/components/chat/ChatIframe.tsx index 350dfdf3..38f6f609 100644 --- a/src/components/chat/ChatIframe.tsx +++ b/src/components/chat/ChatIframe.tsx @@ -1,6 +1,6 @@ import clsx from 'clsx' -import { ComponentProps, useEffect } from 'react' -import grill, { GrillConfig } from '@subsocial/grill-widget' +import { ComponentProps, useEffect, useState } from 'react' +import grill, { Grill, GrillConfig } from '@subsocial/grill-widget' import { useSendEvent } from '../providers/AnalyticContext' import useWrapInRef from '../../hooks/useWrapInRef' import { Resource } from '@subsocial/resource-discussions' @@ -73,6 +73,7 @@ export default function ChatIframe ({ const sendEvent = useSendEvent() const sendEventRef = useWrapInRef(sendEvent) const { spaceId, metadata } = useChatContext() + const [ isLoading, setIsLoading ] = useState(false) useEffect(() => { const config = generateGrillConfig({ spaceId, metadata }) @@ -92,15 +93,38 @@ export default function ChatIframe ({ onUnreadCountChange(count) } : undefined - if (listener) { - grill.addUnreadCountListener(listener) + const eventListener: Grill['eventListeners'][number] = (eventName, value) => { + if (eventName === 'unread' && parseInt(value)) listener?.(parseInt(value)) + if (eventName === 'isUpdatingConfig') { + if (value === 'true') { + setIsLoading(true) + } else if (value === 'false') { + setIsLoading(false) + } + } + } + grill.addUnreadCountListener(eventListener) + + if (grill.instances['grill']) { + grill.setConfig(config) + } else { + grill.init(config) } - grill.init(config) return () => { - if (listener) grill.removeUnreadCountListener(listener) + if (listener) grill.removeUnreadCountListener(eventListener) } }, [ spaceId ]) - return
+ return ( +
+ ) } diff --git a/yarn.lock b/yarn.lock index 9cdddf20..26ce2e5a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5290,10 +5290,10 @@ "@polkadot/api" latest lodash.camelcase "^4.3.0" -"@subsocial/grill-widget@0.0.11": - version "0.0.11" - resolved "https://registry.yarnpkg.com/@subsocial/grill-widget/-/grill-widget-0.0.11.tgz#c77267b1c1344b5535fadfc5c1d7b062862f331f" - integrity sha512-2XOUbd467AeRtPkv2W3oYYfHGJCXAWEDMx6NpXdYs4AMOm1ZtHPjknrQ88/dcZCxDl26XcCRCSysu9n/6qPu2w== +"@subsocial/grill-widget@^0.0.12": + version "0.0.12" + resolved "https://registry.yarnpkg.com/@subsocial/grill-widget/-/grill-widget-0.0.12.tgz#57384850a3adb5342a5505a3f0d67c258d7e3b0e" + integrity sha512-Xed+wN/NEZ+mQlKA1olVVcBviVIQOTyqaCYcl9pGsg8yDdIBsKVjqJUKty1vvBL7gY0A+1osdwBgX2xUsbHOBA== "@subsocial/resource-discussions@0.0.4": version "0.0.4" From 7f295182904d389498ac2409d542608e1c8137e9 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Fri, 3 Nov 2023 20:15:39 +0700 Subject: [PATCH 2/5] Update type --- src/components/chat/ChatIframe.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/chat/ChatIframe.tsx b/src/components/chat/ChatIframe.tsx index 38f6f609..21202c75 100644 --- a/src/components/chat/ChatIframe.tsx +++ b/src/components/chat/ChatIframe.tsx @@ -1,6 +1,6 @@ import clsx from 'clsx' import { ComponentProps, useEffect, useState } from 'react' -import grill, { Grill, GrillConfig } from '@subsocial/grill-widget' +import grill, { Grill, GrillConfig, GrillEventListener } from '@subsocial/grill-widget' import { useSendEvent } from '../providers/AnalyticContext' import useWrapInRef from '../../hooks/useWrapInRef' import { Resource } from '@subsocial/resource-discussions' @@ -93,7 +93,7 @@ export default function ChatIframe ({ onUnreadCountChange(count) } : undefined - const eventListener: Grill['eventListeners'][number] = (eventName, value) => { + const eventListener: GrillEventListener = (eventName, value) => { if (eventName === 'unread' && parseInt(value)) listener?.(parseInt(value)) if (eventName === 'isUpdatingConfig') { if (value === 'true') { From c18b94dddf130e12f1bf606e0089aafa6cc4e550 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Fri, 3 Nov 2023 20:20:51 +0700 Subject: [PATCH 3/5] Fix type error --- src/components/chat/ChatIframe.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/chat/ChatIframe.tsx b/src/components/chat/ChatIframe.tsx index 21202c75..11350eca 100644 --- a/src/components/chat/ChatIframe.tsx +++ b/src/components/chat/ChatIframe.tsx @@ -1,6 +1,6 @@ import clsx from 'clsx' import { ComponentProps, useEffect, useState } from 'react' -import grill, { Grill, GrillConfig, GrillEventListener } from '@subsocial/grill-widget' +import grill, { GrillConfig, GrillEventListener } from '@subsocial/grill-widget' import { useSendEvent } from '../providers/AnalyticContext' import useWrapInRef from '../../hooks/useWrapInRef' import { Resource } from '@subsocial/resource-discussions' From ce2c55bd43f223a4b13b9174917ae3067740d8a4 Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Fri, 3 Nov 2023 22:28:40 +0700 Subject: [PATCH 4/5] Update tooltip --- src/components/creatorsStaking/Banner/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/creatorsStaking/Banner/index.tsx b/src/components/creatorsStaking/Banner/index.tsx index d20f59e8..aa817a65 100644 --- a/src/components/creatorsStaking/Banner/index.tsx +++ b/src/components/creatorsStaking/Banner/index.tsx @@ -43,7 +43,7 @@ const StatsCards = () => { ), infoTitle: - 'An estimate of how much your token balance will increase after a year of staking', + 'An estimate of how much your token balance will increase after a year of staking, regardless of which creator you stake to', }, { title: 'Next Rewards', From 49d03d8ecafdb7c8b1fa94b0e1ba48b25d809cec Mon Sep 17 00:00:00 2001 From: teodorus-nathaniel Date: Fri, 3 Nov 2023 22:37:04 +0700 Subject: [PATCH 5/5] Change takeLatest to takeLeading to speed up and reduce unnecessary api call --- .../creatorStaking/generalEraInfo/generalEraInfoSaga.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rtk/features/creatorStaking/generalEraInfo/generalEraInfoSaga.ts b/src/rtk/features/creatorStaking/generalEraInfo/generalEraInfoSaga.ts index e4b8554e..c35818d3 100644 --- a/src/rtk/features/creatorStaking/generalEraInfo/generalEraInfoSaga.ts +++ b/src/rtk/features/creatorStaking/generalEraInfo/generalEraInfoSaga.ts @@ -1,4 +1,4 @@ -import { call, put, takeLatest, select } from '@redux-saga/core/effects' +import { call, put, takeLeading, select } from '@redux-saga/core/effects' import { log } from '../../../app/util' import { GeneralEraInfo, @@ -16,6 +16,7 @@ export function* fetchGeneeralEraInfoWorker (action: PayloadAction