// @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'; import useFetched from 'effects/use-fetched'; const RULE_LABELS = { [NOTIFICATIONS.NOTIFICATION_RULE_NONE]: 'All', [NOTIFICATIONS.NOTIFICATION_RULE_COMMENTS]: 'Comments', [NOTIFICATIONS.NOTIFICATION_RULE_REPLIES]: 'Replies', [NOTIFICATIONS.NOTIFICATION_RULE_FOLLOWERS]: 'Followers', [NOTIFICATIONS.NOTIFICATION_RULE_NEW_CONTENT]: 'New content', [NOTIFICATIONS.NOTIFICATION_RULE_OTHERS]: 'Others', }; type Props = { notifications: Array, notificationsFiltered: Array, fetching: boolean, unreadCount: number, unseenCount: number, doSeeAllNotifications: () => void, doReadNotifications: () => void, doNotificationList: (string) => void, }; export default function NotificationsPage(props: Props) { const { notifications, notificationsFiltered, fetching, unreadCount, unseenCount, doSeeAllNotifications, doReadNotifications, doNotificationList, } = props; const initialFetchDone = useFetched(fetching); const [rule, setRule] = usePersistedState('notifications--rule', NOTIFICATIONS.NOTIFICATION_RULE_NONE); const isFiltered = rule !== NOTIFICATIONS.NOTIFICATION_RULE_NONE; const list = isFiltered ? notificationsFiltered : notifications; React.useEffect(() => { if (unseenCount > 0 || unreadCount > 0) { // If there are unread notifications when entering the page, reset to All. setRule(NOTIFICATIONS.NOTIFICATION_RULE_NONE); } }, []); React.useEffect(() => { if (unseenCount > 0) { doSeeAllNotifications(); } }, [unseenCount, doSeeAllNotifications]); React.useEffect(() => { if (rule && rule !== '') { // Fetch filtered list when: // (1) 'rule' changed // (2) new "all" notifications received (e.g. from websocket). doNotificationList(rule); } }, [rule, notifications]); const notificationListElement = ( <>

{__('Notifications')}

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

} actions={
} /> )}
)} ); return ( {initialFetchDone ? ( notificationListElement ) : fetching ? (
) : ( notificationListElement )}
); }