Skip to content

Commit

Permalink
Merge branch 'main' into 1965-new-feature-monetization-payment
Browse files Browse the repository at this point in the history
  • Loading branch information
corlard3y authored Feb 17, 2025
2 parents 805c059 + 4c34357 commit 9664e87
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 11 deletions.
14 changes: 14 additions & 0 deletions src/common/Common.utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,17 @@ export function convertTimeStamp(timestamp: string) {
return date.format('hh:mm A');
}
}

export const updateNotifCount = (
setNavigationSetup: (value: any) => void,
listName: string,
itemId: string,
newCount: number
) => {
setNavigationSetup((prev: any) => ({
...prev,
[listName]: prev[listName].map((item: any) =>
item.id === itemId ? { ...item, data: { ...item.data, count: newCount } } : item
),
}));
};
10 changes: 8 additions & 2 deletions src/common/hooks/useInAppNotifications.tsx
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';
Expand All @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -43,7 +46,8 @@ export const useInAppNotifications = () => {
userPushSDKInstance?.stream?.uid,
userPushSDKInstance?.stream
);
if (data.source != 'PUSH_CHAT')
if (data.source != 'PUSH_CHAT') {
setNewNotifsCount((prev: number) => prev + 1);
notification.show({
overlay: <InAppChannelNotifications notificationDetails={data} />,
position: isMobile ? 'top-center' : 'bottom-right',
Expand All @@ -52,6 +56,7 @@ export const useInAppNotifications = () => {
notification.hide();
},
});
}
});
userPushSDKInstance?.stream?.on(CONSTANTS.STREAM.CHAT, (data: any) => {
console.debug(
Expand All @@ -75,6 +80,7 @@ export const useInAppNotifications = () => {
updatedMessages[data.chatId].push(data);
}
setNewMessages(updatedMessages);
setNewChatsCount((prev: number) => prev + 1);
notification.show(
{
overlay: (
Expand Down
19 changes: 19 additions & 0 deletions src/components/MobileNavButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ function MobileNavButton({ item, data, sectionID, active, bg = 'none', showNavBa
{data.name}
</Span>

{!!data?.count && <NewTag2>{data?.count}</NewTag2>}

{data?.showNewTag && <NewTag>New</NewTag>}

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

const NewTag2 = styled(SpanV2)`
display: flex;
max-width: 20px;
height: 16px;
padding: 0px 8px;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 7.778px;
flex-shrink: 0;
border-radius: 22px;
background: #E20880;
font-weight: 500;
line-height: 16px;
font-size: 12px;
`;

// Export Default
export default MobileNavButton;
16 changes: 16 additions & 0 deletions src/components/NavigationButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { GlobalContext } from 'contexts/GlobalContext';

// Assets
import { navigationIcons } from 'assets/navigation';
import { Text } from 'blocks';

// Interface

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

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

const NewTag2 = styled(SpanV2)`
display: flex;
max-width: 20px;
height: 16px;
padding: 1px 8px 0px 8px;
justify-content: center;
align-items: center;
border-radius: 22px;
background: #E20880;
font-weight: 500;
line-height: 1;
font-size: 12px;
`;

const ProtectedRoute = styled(SpanV2)``;

// Export Default
Expand Down
2 changes: 2 additions & 0 deletions src/config/NavigationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const NavigationList = {
hasMenuLogic: true,
loading: false,
hidden: false,
count: 0,
headerTag: {
title: 'Inbox',
light: {
Expand Down Expand Up @@ -103,6 +104,7 @@ const NavigationList = {
hasMenuLogic: true,
hidden: false,
// allowReadOnly: false,
count: 0,
headerTag: {
title: 'Chat',
light: {
Expand Down
6 changes: 6 additions & 0 deletions src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ const AppContextProvider = ({ children }: { children: ReactNode }) => {
title: null,
});
const [displayQR, setDisplayQR] = useState<boolean>(false);
const [newChatsCount, setNewChatsCount] = useState<number>(0);
const [newNotifsCount, setNewNotifsCount] = useState<number>(0);

const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
Expand Down Expand Up @@ -554,6 +556,10 @@ const AppContextProvider = ({ children }: { children: ReactNode }) => {
storePGPKeyForUser,
isUserProfileUnlocked,
setUserProfileUnlocked,
newChatsCount,
setNewChatsCount,
newNotifsCount,
setNewNotifsCount,
}}
>
{children}
Expand Down
8 changes: 7 additions & 1 deletion src/modules/inbox/InboxModule.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// React + Web3 Essentials
import { ethers } from 'ethers';
import React from 'react';
import React, { useContext, useEffect } from 'react';

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

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

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

useEffect(() => {
setNewNotifsCount(0);
}, [newNotifsCount]);

//clear toast variable after it is shown
React.useEffect(() => {
if (toast) {
Expand Down
1 change: 1 addition & 0 deletions src/queries/baseURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ export const getCustomDeliveryURL = () => {
};

export const analyticsBaseURL = 'https://backend.epns.io/apis/v1';
export const analyticsBaseURLV2 = 'https://backend.epns.io/apis/v2';
export const pushsupportBaseURL = 'https://tooling.push.org/apis';
4 changes: 2 additions & 2 deletions src/queries/services/analytics/getSentNotificationCount.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import axios from 'axios';
import { analyticsBaseURL } from 'queries/baseURL';
import { analyticsBaseURLV2 } from 'queries/baseURL';
import { getNotificationCountModelCreator } from 'queries/models/analytics';

export const getSentNotificationCount = () =>
axios({
method: 'GET',
url: `${analyticsBaseURL}/analytics/notification`,
url: `${analyticsBaseURLV2}/analytics/notification`,
params: {
startDate: new Date('2022-01-01'),
endDate: new Date(),
Expand Down
10 changes: 8 additions & 2 deletions src/sections/chat/ChatSection.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// React + Web3 Essentials
import React, { useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';

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

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

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

useEffect(() => {
setNewChatsCount(0);
}, [newChatsCount]);

// RENDER
return (
// If user is not logged in then show chat and unlock profile
Expand Down Expand Up @@ -138,7 +144,7 @@ const ChatViewContainer = styled(ItemVV2)`
overflow: hidden;
`;

const IntroContainer = styled(ItemVV2) <IntroContainerProps>`
const IntroContainer = styled(ItemVV2)<IntroContainerProps>`
flex: 1;
height: inherit;
background: ${(props) => props.bg || 'transparent'};
Expand Down
15 changes: 15 additions & 0 deletions src/structure/MobileNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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';
import { updateNotifCount } from 'common';

// Create Header
function MobileNavigation({ showNavBar, setShowNavBar }) {
Expand All @@ -35,6 +37,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();
Expand Down Expand Up @@ -640,6 +643,18 @@ function MobileNavigation({ showNavBar, setShowNavBar }) {
return rendered;
};

useEffect(() => {
if (navigationSetup) {
updateNotifCount(setNavigationSetup, 'notificationList', '2_inbox', newNotifsCount);
}
}, [newNotifsCount]);

useEffect(() => {
if (navigationSetup) {
updateNotifCount(setNavigationSetup, 'messagingList', '3_chat', newChatsCount);
}
}, [newChatsCount]);

return (
<Item
direction="column"
Expand Down
22 changes: 18 additions & 4 deletions src/structure/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import navigationList from 'config/NavigationList';
import { appConfig } from 'config/index.js';
import { GlobalContext } from 'contexts/GlobalContext';
import { Box, Link, PlusCircle, Text } from 'blocks';
import { LOGO_ALIAS_CHAIN } from 'common';
import { LOGO_ALIAS_CHAIN, updateNotifCount } from 'common';
import APP_PATHS from 'config/AppPaths';
import { ChannelDetails } from 'queries';
import useFetchChannelDetails from 'common/hooks/useFetchUsersChannelDetails';
import { convertAddressToAddrCaip } from 'helpers/CaipHelper';
import { UpgradePlanNavigationItem } from 'components/userPlanAndBillings/UpgradePlanNavigationItem';
import { AppContext } from 'contexts/AppContext';

type AddNewChainNavigationProps = {
channelDetails: ChannelDetails;
Expand Down Expand Up @@ -125,9 +126,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, isWalletConnected } = useAccount();
Expand Down Expand Up @@ -679,8 +681,8 @@ function Navigation() {
)}
</SectionInnerGroupContainer>

{/* {
section.hasItems
{/* {
section.hasItems
? renderChildItems(
data.drilldown,
section.opened,
Expand Down Expand Up @@ -771,6 +773,18 @@ function Navigation() {
return rendered;
};

useEffect(() => {
if (navigationSetup) {
updateNotifCount(setNavigationSetup, 'notificationList', '2_inbox', newNotifsCount);
}
}, [newNotifsCount]);

useEffect(() => {
if (navigationSetup) {
updateNotifCount(setNavigationSetup, 'messagingList', '3_chat', newChatsCount);
}
}, [newChatsCount]);

return (
<Container
direction="column"
Expand Down
4 changes: 4 additions & 0 deletions src/types/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ export interface AppContextType {
initializePushSdkReadMode: () => Promise<void>;
isUserProfileUnlocked: boolean;
setUserProfileUnlocked: (isUserProfileUnlocked: boolean) => void;
newChatsCount: number;
setNewChatsCount: React.Dispatch<React.SetStateAction<number>>;
newNotifsCount: number;
setNewNotifsCount: React.Dispatch<React.SetStateAction<number>>;
}

0 comments on commit 9664e87

Please sign in to comment.