diff --git a/src/components/Icon/PeaceCircle.tsx b/src/components/Icon/PeaceCircle.tsx new file mode 100644 index 000000000..c51a0d41b --- /dev/null +++ b/src/components/Icon/PeaceCircle.tsx @@ -0,0 +1,13 @@ +function PeaceCircle() { + return ( + + + + + ) +} + +export default PeaceCircle diff --git a/src/components/NotificationFeed.css b/src/components/NotificationFeed.css index 92de13281..9ce243994 100644 --- a/src/components/NotificationFeed.css +++ b/src/components/NotificationFeed.css @@ -15,9 +15,13 @@ min-width: 346px; min-height: 370px; max-height: 385px; + height: 100; + padding-bottom: 16px; overflow-y: auto; pointer-events: none; opacity: 0; + display: flex; + flex-direction: column; position: absolute; top: 60px; right: -15px; @@ -58,13 +62,25 @@ cursor: pointer; } -.NotificationFeed__UnsubscribedView { - padding: 0 16px; - text-align: center; +.NotificationFeed__EmptyView { + gap: 16px; } -.NotificationFeed__Item { +.NotificationFeed__List { + display: flex; + flex-direction: column; + gap: 10px; +} + +.NotificationFeed__EmptyView, +.NotificationFeed__UnsubscribedView { + display: flex; + flex-direction: column; padding: 0 16px; + align-items: center; + justify-content: center; + text-align: center; + height: 100%; } .NotificationFeed__LoadMoreButtonContainer { diff --git a/src/components/NotificationFeed.tsx b/src/components/NotificationFeed.tsx index bcaa3af62..60d13abcd 100644 --- a/src/components/NotificationFeed.tsx +++ b/src/components/NotificationFeed.tsx @@ -1,4 +1,4 @@ -import React, { useMemo, useState } from 'react' +import { useEffect, useMemo, useState } from 'react' import { Web3Provider } from '@ethersproject/providers' import * as PushAPI from '@pushprotocol/restapi' @@ -9,21 +9,27 @@ import { Button } from 'decentraland-ui/dist/components/Button/Button' import { Loader } from 'decentraland-ui/dist/components/Loader/Loader' import { Governance } from '../clients/Governance' +import { isSameAddress } from '../entities/Snapshot/utils' import { DEFAULT_QUERY_STALE_TIME } from '../hooks/constants' import { useClickOutside } from '../hooks/useClickOutside' -import { CHAIN_ID, CHANNEL_ADDRESS, ENV, getCaipAddress } from '../utils/notifications' +import { CHAIN_ID, CHANNEL_ADDRESS, ENV, Notification, getCaipAddress } from '../utils/notifications' import FullWidthButton from './Common/FullWidthButton' import Heading from './Common/Typography/Heading' import Text from './Common/Typography/Text' import NotificationBellActive from './Icon/NotificationBellActive' import NotificationBellInactive from './Icon/NotificationBellInactive' +import PeaceCircle from './Icon/PeaceCircle' +import NotificationItem from './Notifications/NotificationItem' import './NotificationFeed.css' +const NOTIFICATIONS_PER_PAGE = 5 + export default function NotificationFeed() { const [isOpen, setOpen] = useState(false) const [user, userState] = useAuthContext() + const [filteredNotifications, setFilteredNotifications] = useState([]) useClickOutside('.NotificationFeed__Content', isOpen, () => setOpen(false)) @@ -40,9 +46,8 @@ export default function NotificationFeed() { staleTime: DEFAULT_QUERY_STALE_TIME, }) - // TODO: Type subscriptions query const isSubscribed = useMemo( - () => !!subscriptions?.find((item: any) => item.channel === CHANNEL_ADDRESS), + () => !!subscriptions?.find((item: { channel: string }) => isSameAddress(item.channel, CHANNEL_ADDRESS)), [subscriptions] ) const { @@ -90,6 +95,24 @@ export default function NotificationFeed() { }) } + const handleLoadMoreClick = () => { + const notifications = userNotifications?.slice( + 0, + filteredNotifications.length + NOTIFICATIONS_PER_PAGE + ) as unknown as Notification[] + setFilteredNotifications(notifications) + } + + useEffect(() => { + if (filteredNotifications.length === 0 && userNotifications && userNotifications?.length > 0) { + const notifications = userNotifications.slice(0, NOTIFICATIONS_PER_PAGE) as unknown as Notification[] + setFilteredNotifications(notifications) + } + }, [userNotifications, filteredNotifications.length]) + + const hasNotifications = filteredNotifications && filteredNotifications.length > 0 + const showLoadMoreButton = isSubscribed && !isLoadingNotifications && hasNotifications + return ( <>