-
Notifications
You must be signed in to change notification settings - Fork 42
Show count in bubble tag whenever a new notification is received #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||
| import { useEffect, useState } from 'react'; | ||||||
| import { useContext, useEffect, useState } from 'react'; | ||||||
|
|
||||||
| import { useSelector } from 'react-redux'; | ||||||
| import { CONSTANTS, NotificationEvent } from '@pushprotocol/restapi'; | ||||||
|
|
@@ -7,6 +7,7 @@ import { deviceSizes, notification } from 'blocks'; | |||||
| import { InAppChannelNotifications, InAppChatNotifications } from 'common'; | ||||||
|
|
||||||
| import { useDeviceWidthCheck } from 'hooks'; | ||||||
| import { AppContext } from 'contexts/AppContext'; | ||||||
|
|
||||||
| export const useInAppNotifications = () => { | ||||||
| const [isStreamConnected, setIsStreamConnected] = useState<boolean>(false); | ||||||
|
|
@@ -15,6 +16,8 @@ export const useInAppNotifications = () => { | |||||
| const { userPushSDKInstance } = useSelector((state: any) => { | ||||||
| return state.user; | ||||||
| }); | ||||||
| const { setNewChatsCount, setNewNotifsCount } = useContext(AppContext); | ||||||
|
|
||||||
| const attachListeners = async () => { | ||||||
| userPushSDKInstance?.stream?.on(CONSTANTS.STREAM.CONNECT, (err: Error) => { | ||||||
| console.debug( | ||||||
|
|
@@ -43,7 +46,8 @@ export const useInAppNotifications = () => { | |||||
| userPushSDKInstance?.stream?.uid, | ||||||
| userPushSDKInstance?.stream | ||||||
| ); | ||||||
| if (data.source != 'PUSH_CHAT') | ||||||
| if (data.source != 'PUSH_CHAT') { | ||||||
| setNewNotifsCount((prev: any) => prev + 1); | ||||||
| notification.show({ | ||||||
| overlay: <InAppChannelNotifications notificationDetails={data} />, | ||||||
| position: isMobile ? 'top-center' : 'bottom-right', | ||||||
|
|
@@ -52,6 +56,7 @@ export const useInAppNotifications = () => { | |||||
| notification.hide(); | ||||||
| }, | ||||||
| }); | ||||||
| } | ||||||
| }); | ||||||
| userPushSDKInstance?.stream?.on(CONSTANTS.STREAM.CHAT, (data: any) => { | ||||||
| console.debug( | ||||||
|
|
@@ -75,6 +80,7 @@ export const useInAppNotifications = () => { | |||||
| updatedMessages[data.chatId].push(data); | ||||||
| } | ||||||
| setNewMessages(updatedMessages); | ||||||
| setNewChatsCount((prev: any) => prev + 1); | ||||||
|
||||||
| setNewChatsCount((prev: any) => prev + 1); | |
| setNewChatsCount((prev: number) => prev + 1); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ import { appConfig } from 'config/index.js'; | |
| import useFetchChannelDetails from 'common/hooks/useFetchUsersChannelDetails'; | ||
| import { convertAddressToAddrCaip } from 'helpers/CaipHelper'; | ||
| import APP_PATHS from 'config/AppPaths'; | ||
| import { AppContext } from 'contexts/AppContext'; | ||
|
|
||
| // Create Header | ||
| function MobileNavigation({ showNavBar, setShowNavBar }) { | ||
|
|
@@ -35,6 +36,7 @@ function MobileNavigation({ showNavBar, setShowNavBar }) { | |
| const { processingState } = useSelector((state: any) => state.channelCreation); | ||
| const { run, stepIndex, isCommunicateOpen, isDeveloperOpen } = useSelector((state: any) => state.userJourney); | ||
| const { navigationSetup, setNavigationSetup } = useContext(NavigationContext); | ||
| const { newChatsCount, newNotifsCount } = useContext(AppContext); | ||
|
|
||
| const CORE_CHAIN_ID = appConfig.coreContractChain; | ||
| const { account, chainId } = useAccount(); | ||
|
|
@@ -640,6 +642,28 @@ function MobileNavigation({ showNavBar, setShowNavBar }) { | |
| return rendered; | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (navigationSetup) { | ||
| setNavigationSetup((prev: any) => ({ | ||
| ...prev, | ||
| notificationList: prev.notificationList.map((item: any) => | ||
| item.id === '2_inbox' ? { ...item, data: { ...item.data, count: newNotifsCount } } : item | ||
| ), | ||
|
||
| })); | ||
| } | ||
| }, [newNotifsCount]); | ||
|
|
||
| useEffect(() => { | ||
| if (navigationSetup) { | ||
| setNavigationSetup((prev: any) => ({ | ||
| ...prev, | ||
| messagingList: prev.messagingList.map((item: any) => | ||
| item.id === '3_chat' ? { ...item, data: { ...item.data, count: newChatsCount } } : item | ||
| ), | ||
| })); | ||
| } | ||
| }, [newChatsCount]); | ||
|
|
||
| return ( | ||
| <Item | ||
| direction="column" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ import APP_PATHS from 'config/AppPaths'; | |
| import { ChannelDetails } from 'queries'; | ||
| import useFetchChannelDetails from 'common/hooks/useFetchUsersChannelDetails'; | ||
| import { convertAddressToAddrCaip } from 'helpers/CaipHelper'; | ||
| import { AppContext } from 'contexts/AppContext'; | ||
|
|
||
| type AddNewChainNavigationProps = { | ||
| channelDetails: ChannelDetails; | ||
|
|
@@ -124,9 +125,10 @@ function Navigation() { | |
| const { delegatees } = useSelector((state: any) => state.admin); | ||
| const [refresh, setRefresh] = useState(false); | ||
| const { processingState } = useSelector((state: any) => state.channelCreation); | ||
| const { run, stepIndex, isCommunicateOpen, isDeveloperOpen } = useSelector((state: any) => state.userJourney); | ||
| const { run, stepIndex } = useSelector((state: any) => state.userJourney); | ||
| const { navigationSetup, setNavigationSetup } = useContext(NavigationContext); | ||
| const { sidebarCollapsed, setSidebarCollapsed } = useContext(GlobalContext); | ||
| const { newChatsCount, newNotifsCount } = useContext(AppContext); | ||
|
|
||
| const CORE_CHAIN_ID = appConfig.coreContractChain; | ||
| const { account, chainId } = useAccount(); | ||
|
|
@@ -677,7 +679,6 @@ function Navigation() { | |
| /> | ||
| )} | ||
| </SectionInnerGroupContainer> | ||
|
|
||
| {/* { | ||
| section.hasItems | ||
| ? renderChildItems( | ||
|
|
@@ -770,6 +771,28 @@ function Navigation() { | |
| return rendered; | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| if (navigationSetup) { | ||
| setNavigationSetup((prev: any) => ({ | ||
| ...prev, | ||
|
||
| notificationList: prev.notificationList.map((item: any) => | ||
| item.id === '2_inbox' ? { ...item, data: { ...item.data, count: newNotifsCount } } : item | ||
| ), | ||
| })); | ||
| } | ||
| }, [newNotifsCount]); | ||
|
|
||
| useEffect(() => { | ||
| if (navigationSetup) { | ||
| setNavigationSetup((prev: any) => ({ | ||
| ...prev, | ||
| messagingList: prev.messagingList.map((item: any) => | ||
| item.id === '3_chat' ? { ...item, data: { ...item.data, count: newChatsCount } } : item | ||
| ), | ||
| })); | ||
| } | ||
| }, [newChatsCount]); | ||
|
|
||
| return ( | ||
| <Container | ||
| direction="column" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.