// @flow import * as ICONS from 'constants/icons'; import React from 'react'; import Page from 'component/page'; import Card from 'component/common/card'; import Spinner from 'component/spinner'; import Notification from 'component/notification'; import Button from 'component/button'; import Yrbl from 'component/yrbl'; import usePrevious from 'effects/use-previous'; type Props = { notifications: Array, fetching: boolean, unreadCount: number, unseenCount: number, doSeeAllNotifications: () => void, doReadNotifications: () => void, }; export default function NotificationsPage(props: Props) { const { notifications, fetching, unreadCount, unseenCount, doSeeAllNotifications, doReadNotifications } = props; const [hasFetched, setHasFetched] = React.useState(false); const previousFetching = usePrevious(fetching); const hasNotifications = notifications.length > 0; React.useEffect(() => { if (unreadCount > 0) { doReadNotifications(); } }, [unreadCount, doReadNotifications]); React.useEffect(() => { if ((fetching === false && previousFetching === true) || hasNotifications) { setHasFetched(true); } }, [fetching, previousFetching, setHasFetched, hasNotifications]); return ( {fetching && !hasNotifications && (
)} {hasFetched && ( <> {notifications && notifications.length > 0 ? ( {__('Notifications')} {fetching && } } titleActions={ unseenCount > 0 && (