Skip to content

Commit 9664e87

Browse files
authored
Merge branch 'main' into 1965-new-feature-monetization-payment
2 parents 805c059 + 4c34357 commit 9664e87

File tree

13 files changed

+120
-11
lines changed

13 files changed

+120
-11
lines changed

src/common/Common.utils.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,17 @@ export function convertTimeStamp(timestamp: string) {
7070
return date.format('hh:mm A');
7171
}
7272
}
73+
74+
export const updateNotifCount = (
75+
setNavigationSetup: (value: any) => void,
76+
listName: string,
77+
itemId: string,
78+
newCount: number
79+
) => {
80+
setNavigationSetup((prev: any) => ({
81+
...prev,
82+
[listName]: prev[listName].map((item: any) =>
83+
item.id === itemId ? { ...item, data: { ...item.data, count: newCount } } : item
84+
),
85+
}));
86+
};

src/common/hooks/useInAppNotifications.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useContext, useEffect, useState } from 'react';
22

33
import { useSelector } from 'react-redux';
44
import { CONSTANTS, NotificationEvent } from '@pushprotocol/restapi';
@@ -7,6 +7,7 @@ import { deviceSizes, notification } from 'blocks';
77
import { InAppChannelNotifications, InAppChatNotifications } from 'common';
88

99
import { useDeviceWidthCheck } from 'hooks';
10+
import { AppContext } from 'contexts/AppContext';
1011

1112
export const useInAppNotifications = () => {
1213
const [isStreamConnected, setIsStreamConnected] = useState<boolean>(false);
@@ -15,6 +16,8 @@ export const useInAppNotifications = () => {
1516
const { userPushSDKInstance } = useSelector((state: any) => {
1617
return state.user;
1718
});
19+
const { setNewChatsCount, setNewNotifsCount } = useContext(AppContext);
20+
1821
const attachListeners = async () => {
1922
userPushSDKInstance?.stream?.on(CONSTANTS.STREAM.CONNECT, (err: Error) => {
2023
console.debug(
@@ -43,7 +46,8 @@ export const useInAppNotifications = () => {
4346
userPushSDKInstance?.stream?.uid,
4447
userPushSDKInstance?.stream
4548
);
46-
if (data.source != 'PUSH_CHAT')
49+
if (data.source != 'PUSH_CHAT') {
50+
setNewNotifsCount((prev: number) => prev + 1);
4751
notification.show({
4852
overlay: <InAppChannelNotifications notificationDetails={data} />,
4953
position: isMobile ? 'top-center' : 'bottom-right',
@@ -52,6 +56,7 @@ export const useInAppNotifications = () => {
5256
notification.hide();
5357
},
5458
});
59+
}
5560
});
5661
userPushSDKInstance?.stream?.on(CONSTANTS.STREAM.CHAT, (data: any) => {
5762
console.debug(
@@ -75,6 +80,7 @@ export const useInAppNotifications = () => {
7580
updatedMessages[data.chatId].push(data);
7681
}
7782
setNewMessages(updatedMessages);
83+
setNewChatsCount((prev: number) => prev + 1);
7884
notification.show(
7985
{
8086
overlay: (

src/components/MobileNavButton.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ function MobileNavButton({ item, data, sectionID, active, bg = 'none', showNavBa
153153
{data.name}
154154
</Span>
155155

156+
{!!data?.count && <NewTag2>{data?.count}</NewTag2>}
157+
156158
{data?.showNewTag && <NewTag>New</NewTag>}
157159

158160
{item.hasItems && !item.opened && <BiChevronDown color={theme.nav.color} />}
@@ -226,5 +228,22 @@ const NewTag = styled(SpanV2)`
226228
width: fit-content;
227229
`;
228230

231+
const NewTag2 = styled(SpanV2)`
232+
display: flex;
233+
max-width: 20px;
234+
height: 16px;
235+
padding: 0px 8px;
236+
flex-direction: column;
237+
justify-content: center;
238+
align-items: center;
239+
gap: 7.778px;
240+
flex-shrink: 0;
241+
border-radius: 22px;
242+
background: #E20880;
243+
font-weight: 500;
244+
line-height: 16px;
245+
font-size: 12px;
246+
`;
247+
229248
// Export Default
230249
export default MobileNavButton;

src/components/NavigationButton.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { GlobalContext } from 'contexts/GlobalContext';
1919

2020
// Assets
2121
import { navigationIcons } from 'assets/navigation';
22+
import { Text } from 'blocks';
2223

2324
// Interface
2425

@@ -158,6 +159,7 @@ function NavigationButton({ item, data, sectionID, active, bg = 'none' }) {
158159
{data.name}
159160
</Span>
160161
)}
162+
{!!data?.count && <NewTag2>{data?.count}</NewTag2>}
161163

162164
{data?.showNewTag && !sidebarCollapsed && <NewTag>New</NewTag>}
163165
</ItemH>
@@ -252,6 +254,20 @@ const NewTag = styled(SpanV2)`
252254
width: fit-content;
253255
`;
254256

257+
const NewTag2 = styled(SpanV2)`
258+
display: flex;
259+
max-width: 20px;
260+
height: 16px;
261+
padding: 1px 8px 0px 8px;
262+
justify-content: center;
263+
align-items: center;
264+
border-radius: 22px;
265+
background: #E20880;
266+
font-weight: 500;
267+
line-height: 1;
268+
font-size: 12px;
269+
`;
270+
255271
const ProtectedRoute = styled(SpanV2)``;
256272

257273
// Export Default

src/config/NavigationList.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const NavigationList = {
4949
hasMenuLogic: true,
5050
loading: false,
5151
hidden: false,
52+
count: 0,
5253
headerTag: {
5354
title: 'Inbox',
5455
light: {
@@ -103,6 +104,7 @@ const NavigationList = {
103104
hasMenuLogic: true,
104105
hidden: false,
105106
// allowReadOnly: false,
107+
count: 0,
106108
headerTag: {
107109
title: 'Chat',
108110
light: {

src/contexts/AppContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const AppContextProvider = ({ children }: { children: ReactNode }) => {
5656
title: null,
5757
});
5858
const [displayQR, setDisplayQR] = useState<boolean>(false);
59+
const [newChatsCount, setNewChatsCount] = useState<number>(0);
60+
const [newNotifsCount, setNewNotifsCount] = useState<number>(0);
5961

6062
const { userPushSDKInstance } = useSelector((state: any) => {
6163
return state.user;
@@ -554,6 +556,10 @@ const AppContextProvider = ({ children }: { children: ReactNode }) => {
554556
storePGPKeyForUser,
555557
isUserProfileUnlocked,
556558
setUserProfileUnlocked,
559+
newChatsCount,
560+
setNewChatsCount,
561+
newNotifsCount,
562+
setNewNotifsCount,
557563
}}
558564
>
559565
{children}

src/modules/inbox/InboxModule.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// React + Web3 Essentials
22
import { ethers } from 'ethers';
3-
import React from 'react';
3+
import React, { useContext, useEffect } from 'react';
44

55
// External Packages
66
import ReactGA from 'react-ga';
@@ -22,6 +22,7 @@ import UsersDataStore from 'singletons/UsersDataStore';
2222
import APP_PATHS from 'config/AppPaths';
2323
import GLOBALS, { device, globalsMargin } from 'config/Globals';
2424
import { CHAIN_DETAILS, abis, addresses, appConfig } from 'config/index.js';
25+
import { AppContext } from 'contexts/AppContext';
2526

2627
// Constants
2728
export const ALLOWED_CORE_NETWORK = appConfig.coreContractChain;
@@ -34,6 +35,7 @@ const InboxModule = ({ isSpam }) => {
3435
const dispatch = useDispatch();
3536
const { account, chainId, provider } = useAccount();
3637
const { epnsReadProvider, epnsCommReadProvider } = useSelector((state) => state.contracts);
38+
const { setNewNotifsCount, newNotifsCount } = useContext(AppContext);
3739

3840
// toast related section
3941
const [toast, showToast] = React.useState(null);
@@ -44,6 +46,10 @@ const InboxModule = ({ isSpam }) => {
4446
const themes = useTheme();
4547
const onCoreNetwork = ALLOWED_CORE_NETWORK === chainId;
4648

49+
useEffect(() => {
50+
setNewNotifsCount(0);
51+
}, [newNotifsCount]);
52+
4753
//clear toast variable after it is shown
4854
React.useEffect(() => {
4955
if (toast) {

src/queries/baseURL.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ export const getCustomDeliveryURL = () => {
3434
};
3535

3636
export const analyticsBaseURL = 'https://backend.epns.io/apis/v1';
37+
export const analyticsBaseURLV2 = 'https://backend.epns.io/apis/v2';
3738
export const pushsupportBaseURL = 'https://tooling.push.org/apis';

src/queries/services/analytics/getSentNotificationCount.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import axios from 'axios';
2-
import { analyticsBaseURL } from 'queries/baseURL';
2+
import { analyticsBaseURLV2 } from 'queries/baseURL';
33
import { getNotificationCountModelCreator } from 'queries/models/analytics';
44

55
export const getSentNotificationCount = () =>
66
axios({
77
method: 'GET',
8-
url: `${analyticsBaseURL}/analytics/notification`,
8+
url: `${analyticsBaseURLV2}/analytics/notification`,
99
params: {
1010
startDate: new Date('2022-01-01'),
1111
endDate: new Date(),

src/sections/chat/ChatSection.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// React + Web3 Essentials
2-
import React, { useState } from 'react';
2+
import React, { useContext, useEffect, useState } from 'react';
33
import { useNavigate } from 'react-router-dom';
44

55
// External Packages
@@ -20,6 +20,7 @@ import { device } from 'config/Globals';
2020
import Back from 'assets/chat/backchat.svg?react';
2121
import UnlockProfileWrapper from 'components/chat/unlockProfile/UnlockProfileWrapper';
2222
import { MODAL_POSITION } from 'hooks/useModalBlur';
23+
import { AppContext } from 'contexts/AppContext';
2324

2425
// Interface
2526
interface IntroContainerProps {
@@ -38,6 +39,7 @@ const ChatSection = ({ chatId, setChatId, loggedIn }) => {
3839
const { userPushSDKInstance } = useSelector((state: any) => {
3940
return state.user;
4041
});
42+
const { setNewChatsCount, newChatsCount } = useContext(AppContext);
4143

4244
// Get Theme
4345
const theme = useTheme();
@@ -48,6 +50,10 @@ const ChatSection = ({ chatId, setChatId, loggedIn }) => {
4850
// State to control the visibility of the unlock profile modal
4951
const [visible, setVisible] = useState(true);
5052

53+
useEffect(() => {
54+
setNewChatsCount(0);
55+
}, [newChatsCount]);
56+
5157
// RENDER
5258
return (
5359
// If user is not logged in then show chat and unlock profile
@@ -138,7 +144,7 @@ const ChatViewContainer = styled(ItemVV2)`
138144
overflow: hidden;
139145
`;
140146

141-
const IntroContainer = styled(ItemVV2) <IntroContainerProps>`
147+
const IntroContainer = styled(ItemVV2)<IntroContainerProps>`
142148
flex: 1;
143149
height: inherit;
144150
background: ${(props) => props.bg || 'transparent'};

src/structure/MobileNavigation.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { appConfig } from 'config/index.js';
2424
import useFetchChannelDetails from 'common/hooks/useFetchUsersChannelDetails';
2525
import { convertAddressToAddrCaip } from 'helpers/CaipHelper';
2626
import APP_PATHS from 'config/AppPaths';
27+
import { AppContext } from 'contexts/AppContext';
28+
import { updateNotifCount } from 'common';
2729

2830
// Create Header
2931
function MobileNavigation({ showNavBar, setShowNavBar }) {
@@ -35,6 +37,7 @@ function MobileNavigation({ showNavBar, setShowNavBar }) {
3537
const { processingState } = useSelector((state: any) => state.channelCreation);
3638
const { run, stepIndex, isCommunicateOpen, isDeveloperOpen } = useSelector((state: any) => state.userJourney);
3739
const { navigationSetup, setNavigationSetup } = useContext(NavigationContext);
40+
const { newChatsCount, newNotifsCount } = useContext(AppContext);
3841

3942
const CORE_CHAIN_ID = appConfig.coreContractChain;
4043
const { account, chainId } = useAccount();
@@ -640,6 +643,18 @@ function MobileNavigation({ showNavBar, setShowNavBar }) {
640643
return rendered;
641644
};
642645

646+
useEffect(() => {
647+
if (navigationSetup) {
648+
updateNotifCount(setNavigationSetup, 'notificationList', '2_inbox', newNotifsCount);
649+
}
650+
}, [newNotifsCount]);
651+
652+
useEffect(() => {
653+
if (navigationSetup) {
654+
updateNotifCount(setNavigationSetup, 'messagingList', '3_chat', newChatsCount);
655+
}
656+
}, [newChatsCount]);
657+
643658
return (
644659
<Item
645660
direction="column"

src/structure/Navigation.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import navigationList from 'config/NavigationList';
2424
import { appConfig } from 'config/index.js';
2525
import { GlobalContext } from 'contexts/GlobalContext';
2626
import { Box, Link, PlusCircle, Text } from 'blocks';
27-
import { LOGO_ALIAS_CHAIN } from 'common';
27+
import { LOGO_ALIAS_CHAIN, updateNotifCount } from 'common';
2828
import APP_PATHS from 'config/AppPaths';
2929
import { ChannelDetails } from 'queries';
3030
import useFetchChannelDetails from 'common/hooks/useFetchUsersChannelDetails';
3131
import { convertAddressToAddrCaip } from 'helpers/CaipHelper';
3232
import { UpgradePlanNavigationItem } from 'components/userPlanAndBillings/UpgradePlanNavigationItem';
33+
import { AppContext } from 'contexts/AppContext';
3334

3435
type AddNewChainNavigationProps = {
3536
channelDetails: ChannelDetails;
@@ -125,9 +126,10 @@ function Navigation() {
125126
const { delegatees } = useSelector((state: any) => state.admin);
126127
const [refresh, setRefresh] = useState(false);
127128
const { processingState } = useSelector((state: any) => state.channelCreation);
128-
const { run, stepIndex, isCommunicateOpen, isDeveloperOpen } = useSelector((state: any) => state.userJourney);
129+
const { run, stepIndex } = useSelector((state: any) => state.userJourney);
129130
const { navigationSetup, setNavigationSetup } = useContext(NavigationContext);
130131
const { sidebarCollapsed, setSidebarCollapsed } = useContext(GlobalContext);
132+
const { newChatsCount, newNotifsCount } = useContext(AppContext);
131133

132134
const CORE_CHAIN_ID = appConfig.coreContractChain;
133135
const { account, chainId, isWalletConnected } = useAccount();
@@ -679,8 +681,8 @@ function Navigation() {
679681
)}
680682
</SectionInnerGroupContainer>
681683

682-
{/* {
683-
section.hasItems
684+
{/* {
685+
section.hasItems
684686
? renderChildItems(
685687
data.drilldown,
686688
section.opened,
@@ -771,6 +773,18 @@ function Navigation() {
771773
return rendered;
772774
};
773775

776+
useEffect(() => {
777+
if (navigationSetup) {
778+
updateNotifCount(setNavigationSetup, 'notificationList', '2_inbox', newNotifsCount);
779+
}
780+
}, [newNotifsCount]);
781+
782+
useEffect(() => {
783+
if (navigationSetup) {
784+
updateNotifCount(setNavigationSetup, 'messagingList', '3_chat', newChatsCount);
785+
}
786+
}, [newChatsCount]);
787+
774788
return (
775789
<Container
776790
direction="column"

src/types/context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,8 @@ export interface AppContextType {
7070
initializePushSdkReadMode: () => Promise<void>;
7171
isUserProfileUnlocked: boolean;
7272
setUserProfileUnlocked: (isUserProfileUnlocked: boolean) => void;
73+
newChatsCount: number;
74+
setNewChatsCount: React.Dispatch<React.SetStateAction<number>>;
75+
newNotifsCount: number;
76+
setNewNotifsCount: React.Dispatch<React.SetStateAction<number>>;
7377
}

0 commit comments

Comments
 (0)