Skip to content

Commit

Permalink
chore: hide notifs on mobile web view (#1067)
Browse files Browse the repository at this point in the history
  • Loading branch information
moo-onthelawn authored Sep 27, 2024
1 parent 6a43b3e commit 934fbe3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
12 changes: 12 additions & 0 deletions src/hooks/useNotifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,15 @@ const useNotificationsContext = () => {
// Menu state
const [isMenuOpen, setIsMenuOpen] = useState(false);

// Unread
const hasUnreadNotifications = useMemo(
() =>
Object.values(notifications).some(
(notification) => notification.status < NotificationStatus.Seen
),
[notifications]
);

// Public
return {
notifications,
Expand Down Expand Up @@ -336,6 +345,9 @@ const useNotificationsContext = () => {
isMenuOpen,
setIsMenuOpen,

// Unread
hasUnreadNotifications,

// Notification Preferences
notificationPreferences,
setNotificationPreferences,
Expand Down
19 changes: 18 additions & 1 deletion src/layout/Footer/FooterMobile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { DEFAULT_MARKETID } from '@/constants/markets';
import { AppRoute } from '@/constants/routes';

import { useComplianceState } from '@/hooks/useComplianceState';
import { useNotifications } from '@/hooks/useNotifications';
import { useShouldShowFooter } from '@/hooks/useShouldShowFooter';
import { useStringGetter } from '@/hooks/useStringGetter';

Expand All @@ -31,6 +32,7 @@ export const FooterMobile = () => {
const marketId = useAppSelector(getCurrentMarketId);

const { disableConnectButton } = useComplianceState();
const { hasUnreadNotifications } = useNotifications();

if (!useShouldShowFooter()) return null;

Expand Down Expand Up @@ -78,7 +80,14 @@ export const FooterMobile = () => {
{
value: 'alerts',
label: stringGetter({ key: STRING_KEYS.ALERTS }),
slotBefore: <$Icon iconComponent={BellIcon as any} />,
slotBefore: (
<div tw="stack">
<$Icon iconComponent={BellIcon as any} />
{hasUnreadNotifications && (
<$UnreadIndicator tw="relative right-[-0.35rem] top-[-0.55rem] place-self-center" />
)}
</div>
),
href: AppRoute.Alerts,
},
{
Expand Down Expand Up @@ -188,3 +197,11 @@ const $StartIcon = styled.div<{ disabled?: boolean }>`
color: var(--color-text-0);
`}
`;

const $UnreadIndicator = styled.div`
width: 0.9rem;
height: 0.9rem;
border-radius: 50%;
background-color: var(--color-accent);
border: 2px solid var(--color-layer-2);
`;
3 changes: 1 addition & 2 deletions src/layout/NotificationsToastArea/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const StyledToastArea = styled.div`
pointer-events: none;
@media ${breakpoints.mobile} {
width: 100%;
position: fixed;
display: none; // hide notifications on mobile web view
}
`;
7 changes: 2 additions & 5 deletions src/views/menus/NotificationsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const NotificationsMenu = ({

isMenuOpen,
setIsMenuOpen,

hasUnreadNotifications,
} = useNotifications();

const notificationsByStatus: Partial<Record<NotificationStatus, Notification[]>> = useMemo(
Expand All @@ -58,11 +60,6 @@ export const NotificationsMenu = ({
[notifications, getDisplayData]
);

const hasUnreadNotifications = useMemo(
() => notificationsByStatus[NotificationStatus.Triggered]?.length! > 0,
[notificationsByStatus]
);

const items: Parameters<typeof ComboboxDialogMenu>[0]['items'] = useMemo(
() =>
(Object.entries(notificationsByStatus) as unknown as [NotificationStatus, Notification[]][])
Expand Down

0 comments on commit 934fbe3

Please sign in to comment.