// @flow import * as ICONS from 'constants/icons'; import React from 'react'; import Page from 'component/page'; import Spinner from 'component/spinner'; import { FormField } from 'component/common/form'; import Notification from 'component/notification'; import Button from 'component/button'; import usePersistedState from 'effects/use-persisted-state'; import Yrbl from 'component/yrbl'; import * as NOTIFICATIONS from 'constants/notifications'; type Props = { notifications: Array, fetching: boolean, unreadCount: number, unseenCount: number, doSeeAllNotifications: () => void, doReadNotifications: () => void, }; const ALL_NOTIFICATIONS = 'all'; export default function NotificationsPage(props: Props) { const { notifications, fetching, unreadCount, unseenCount, doSeeAllNotifications, doReadNotifications } = props; const hasNotifications = notifications.length > 0; const [filterBy, setFilterBy] = usePersistedState('notifications--filter-by', 'all'); const [filteredNotifications, setFilteredNotifications] = React.useState(notifications); const isFiltered = filterBy !== ALL_NOTIFICATIONS; const NOTIFICATION_FILTER_TYPES = [ ALL_NOTIFICATIONS, NOTIFICATIONS.NOTIFICATION_CREATOR_SUBSCRIBER, NOTIFICATIONS.NOTIFICATION_COMMENT, NOTIFICATIONS.NOTIFICATION_REPLY, NOTIFICATIONS.DAILY_WATCH_AVAILABLE, NOTIFICATIONS.DAILY_WATCH_REMIND, NOTIFICATIONS.NEW_CONTENT, ]; React.useEffect(() => { if (unseenCount > 0 || unreadCount > 0) { // If there are unread notifications when entering the page, reset to All. setFilterBy(ALL_NOTIFICATIONS); } }, []); React.useEffect(() => { if (notifications && filterBy !== ALL_NOTIFICATIONS) { setFilteredNotifications(notifications.filter((n) => n.notification_rule === filterBy)); } else { setFilteredNotifications(notifications); } }, [notifications, filterBy]); React.useEffect(() => { if (unseenCount > 0) { doSeeAllNotifications(); } }, [unseenCount, doSeeAllNotifications]); return ( {fetching && !hasNotifications && (
)} {!fetching && ( <>

{__('Notifications')}

{fetching && } {unreadCount > 0 && (
{filteredNotifications && filteredNotifications.length > 0 ? (
{filteredNotifications.map((notification, index) => { return ; })}
) : (
{isFiltered ? __('Try selecting another filter.') : __("You don't have any notifications yet, but they will be here when you do!")}

} actions={
} />
)} )}
); }