Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 76 additions & 47 deletions src/components/ViewChannelItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import styled, { css, useTheme } from 'styled-components';
// Internal Compoonents
import * as PushAPI from '@pushprotocol/restapi';
import { Device } from 'assets/Device';
import AllowNotificationModal from './channel/AllowNotificationModal';
import MetaInfoDisplayer from 'components/MetaInfoDisplayer';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { ButtonV2 } from 'components/reusables/SharedStylingV2';
Expand All @@ -43,6 +44,8 @@ import VerifiedTooltipContent from './VerifiedTooltipContent';
import APP_PATHS from 'config/AppPaths';
import { addresses, appConfig, CHAIN_DETAILS } from 'config/index.js';
import { IPFSGateway } from 'helpers/IpfsHelper';
import { checkPermission } from 'helpers/channel/allowNotification';
import { NOTIF_PERMISSION_STATUS } from 'helpers/channel/types';

// Create Header
function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, profileType }) {
Expand Down Expand Up @@ -85,6 +88,9 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
const [channelObjectFromHash, setChannelObjectFromHash] = React.useState({});
const [channelObjectStartBlock, setChannelObjectStartBlock] = React.useState({});
const [showChannelChangedWarning, setShowChannelChangedWarning] = React.useState(false);
const [showAllowNotification, setShowAllowNotification] = useState(false);


const isVerified = channelObject.verified_status;
const isBlocked = channelObject.blocked;
const isMobile = useDeviceWidthCheck(600);
Expand All @@ -103,6 +109,13 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
setSubscribed(subscriptionStatus[channelObject.channel]);
}, [subscriptionStatus]);

useEffect(() => {
if (showAllowNotification)
setTimeout(() => {
setShowAllowNotification(false);
}, 10000);
}, [showAllowNotification]);

useEffect(() => {
setIsPushAdmin(pushAdminAddress == account);
}, [pushAdminAddress, account]);
Expand Down Expand Up @@ -399,6 +412,20 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
setToolTipheight(containerHeight?.top);
};

const onAllowModalOpen = () => {
if (checkPermission() === NOTIF_PERMISSION_STATUS.PENDING) {
const lastTime = localStorage.getItem('allow_notif_modal');
let today = new Date().getTime() + (1 * 24 * 60 * 60 * 1000);
if (lastTime && lastTime >= today) {
setShowAllowNotification(true);
}
else {
localStorage.setItem('allow_notif_modal', today);
}
}

}

// render
return (
<Container
Expand Down Expand Up @@ -447,19 +474,19 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
placementProps={
tooltTipHeight < 250
? {
background: 'none',
// bottom: "25px",
top: '20px',
// right: "-175px",
left: mobileToolTip ? '-100px' : '5px',
}
background: 'none',
// bottom: "25px",
top: '20px',
// right: "-175px",
left: mobileToolTip ? '-100px' : '5px',
}
: {
background: 'none',
bottom: '25px',
// top: "20px",
// right: "-175px",
left: mobileToolTip ? '-100px' : '5px',
}
background: 'none',
bottom: '25px',
// top: "20px",
// right: "-175px",
left: mobileToolTip ? '-100px' : '5px',
}
}
tooltipContent={
<UpdateChannelTooltipContent
Expand Down Expand Up @@ -505,15 +532,15 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
placementProps={
tooltTipHeight < 160
? {
background: 'none',
top: '20px', // for lower displaying
left: '7px',
}
background: 'none',
top: '20px', // for lower displaying
left: '7px',
}
: {
background: 'none',
bottom: '28px', // above display
left: '7px',
}
background: 'none',
bottom: '28px', // above display
left: '7px',
}
}
tooltipContent={
<VerifiedTooltipContent
Expand Down Expand Up @@ -554,9 +581,8 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
!MaskedAliasChannels[+channelObject?.alias_blockchain_id][channelObject?.channel] && (
<Span padding="0 0 0 5px">
<Image
src={`./svg/${
CHAIN_DETAILS[+channelObject.alias_blockchain_id]?.label?.split(' ')[0]
}.svg`}
src={`./svg/${CHAIN_DETAILS[+channelObject.alias_blockchain_id]?.label?.split(' ')[0]
}.svg`}
alt="Polygon"
width="20px"
height="20px"
Expand Down Expand Up @@ -621,19 +647,19 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
placementProps={
tooltTipHeight < 250
? {
background: 'none',
// bottom: "25px",
top: '20px',
// right: "-175px",
left: '5px',
}
background: 'none',
// bottom: "25px",
top: '20px',
// right: "-175px",
left: '5px',
}
: {
background: 'none',
bottom: '25px',
// top: "20px",
// right: "-175px",
left: '5px',
}
background: 'none',
bottom: '25px',
// top: "20px",
// right: "-175px",
left: '5px',
}
}
tooltipContent={
<UpdateChannelTooltipContent
Expand Down Expand Up @@ -677,15 +703,15 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
placementProps={
tooltTipHeight < 160
? {
background: 'none',
top: '20px', // for lower displaying
left: '7px',
}
background: 'none',
top: '20px', // for lower displaying
left: '7px',
}
: {
background: 'none',
bottom: '28px', // above display
left: '7px',
}
background: 'none',
bottom: '28px', // above display
left: '7px',
}
}
tooltipContent={
<VerifiedTooltipContent
Expand Down Expand Up @@ -938,12 +964,11 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
channelDetail={channelObject}
setLoading={setTxInProgress}
onSuccessOptin={() => {
setSubscribed(true);
setSubscriberCount((prevSubscriberCount) => prevSubscriberCount + 1);
onAllowModalOpen();
}}
>
<SubscribeButton
onClick={() => {}}
onClick={() => { }}
disabled={txInProgress}
className="optin"
>
Expand Down Expand Up @@ -988,7 +1013,7 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
}}
>
<UnsubscribeButton
onClick={() => {}}
onClick={() => { }}
disabled={txInProgress}
>
{txInProgress && (
Expand Down Expand Up @@ -1021,6 +1046,10 @@ function ViewChannelItem({ channelObjectProp, loadTeaser, playTeaser, minimal, p
clearToast={clearToast}
/>
)}
{/* modal to allow notification */}
{showAllowNotification &&
<AllowNotificationModal onModalClose={() => setShowAllowNotification(false)} />
}
</Container>
);
}
Expand Down
96 changes: 96 additions & 0 deletions src/components/channel/AllowNotificationModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// External Packages
import styled, { useTheme } from 'styled-components';

// Internal Components
import { ButtonV2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';

// Internal Configs
import { device } from 'config/Globals';
import { handleBrowserNotification } from 'helpers/channel/allowNotification';

interface AllowNotificationModalProps {
onModalClose: () => {};
}

const AllowNotificationModal: React.FC<AllowNotificationModalProps> = ({
onModalClose,
}: AllowNotificationModalProps) => {
const theme = useTheme();

return (
<ModalContainer theme={theme}>
<ItemVV2 gap="16px">
<ItemVV2
gap="10px"
alignItems="start"
>
<SpanV2
fontSize="20px"
fontWeight="500"
color={theme.default.color}
>
Allow Notifications
</SpanV2>
<SpanV2
fontSize="14px"
fontWeigth="400"
maxWidth="264px"
textAlign="left"
color={theme.default.descriptionTextColor}
>
We recommend enabling notifications for receiving updates from subscribed channels for a seamless
experience.
</SpanV2>
</ItemVV2>
<ItemHV2
width="100%"
justifyContent="space-between"
>
<ButtonV2
padding="14px 0px"
background="#D53A94"
maxWidth="110px"
color="#fff"
borderRadius="8px"
onClick={() => {
handleBrowserNotification(onModalClose);
}}
>
Allow
</ButtonV2>
<ButtonV2
padding="14px 0px"
background={theme.modalContentBackground}
color={theme.default.descriptionTextColor}
borderRadius="8px"
maxWidth="110px"
hoverBackground="none"
onClick={() => onModalClose()}
>
Skip
</ButtonV2>
</ItemHV2>
</ItemVV2>
</ModalContainer>
);
};

export default AllowNotificationModal;

const ModalContainer = styled.div`
display: flex;
flex-direction: column;
right: 20px;
bottom: 20px;
position: fixed;
z-index: 99999999999;
width: 340px;
border-radius: 12px;
border: 1px solid rgba(0, 0, 0, 0.1);
background: ${(props) => props.theme.modalContentBackground};
padding: 16px 20px;

@media (${device.mobileL}) {
width: calc(100% - 80px);
}
`;
1 change: 1 addition & 0 deletions src/components/dropdowns/OptinNotifSettingDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const OptinNotifSettingDropdown: React.FC<OptinNotifSettingDropdownProps> = (opt
settings: userSettingsFromDefaultChannelSetting({ channelSetting: channelSettings }),
})
);
onSuccessOptin();

subscribeToast.showMessageToast({
toastTitle: 'Success',
Expand Down
2 changes: 2 additions & 0 deletions src/config/Themization.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const themeLight = {
border: '#E5E8F6',
color: '#000',
secondaryColor: '#657795',
descriptionTextColor: '#000',
hover: '#F3F3FF',
borderColor: '#dfdee9',
primaryPushThemeTextColor: '#cf1c84',
Expand Down Expand Up @@ -313,6 +314,7 @@ const themeDark = {
color: '#FFF',
secondaryColor: '#B6BCD6',
hover: '#00000033',
descriptionTextColor: '#B6BCD6',
borderColor: '#4A4F67',
primaryPushThemeTextColor: '#cf1c84',
},
Expand Down
22 changes: 22 additions & 0 deletions src/helpers/channel/allowNotification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { NOTIF_PERMISSION_STATUS } from './types';

export const handleBrowserNotification = (onSuccess?: () => void) => {
if (!('Notification' in window)) {
alert('This browser does not support desktop notification');
} else if (checkPermission() === NOTIF_PERMISSION_STATUS.PENDING) {
Notification.requestPermission().then(() => {
onSuccess ? onSuccess() : null;
});
}
};

export const checkPermission = () => {
if (!('Notification' in window)) {
alert('This browser does not support desktop notification');
} else if (Notification.permission === 'granted') {
return NOTIF_PERMISSION_STATUS.GRANTED;
} else if (Notification.permission !== 'denied') {
return NOTIF_PERMISSION_STATUS.PENDING;
}
return NOTIF_PERMISSION_STATUS.DENIED;
};
Loading