import { useCallback, useMemo } from 'react' import { Button, Col, Empty, Row, Typography } from 'antd' import NotificationItem from './notificationItem' import { RootDispatch, useRootDispatch } from 'store' import { getNotifications, getUnreadNotifications, } from 'store/notifications.reducer' import { useNotifications, useOffset, useUserNotification, } from 'hooks/useNotifications' export type NotificationDrawerProps = { unreadOnly?: boolean } const NotificationDrawer = ({ unreadOnly = false, }: NotificationDrawerProps) => { const dispatch = useRootDispatch() const offset = useOffset() const notifications = useNotifications() const { notificationMark } = useUserNotification() const disabled = useMemo( () => notifications.length < offset, [offset, notifications.length], ) const markNotificationIndex = useMemo(() => { return notifications.findIndex((val) => val._id === notificationMark) }, [notificationMark, notifications]) const onViewMore = useCallback(async () => { if (!unreadOnly) { return await dispatch( getNotifications({ offset, }), ) } return await dispatch( getUnreadNotifications({ offset, }), ) }, [dispatch, offset, unreadOnly]) return ( {!notifications.length ? ( You have no unread notifications } /> ) : ( {notifications.map((notification, index) => { const isBeforeMark = markNotificationIndex !== -1 && markNotificationIndex <= index return ( ) })} {!disabled && ( )} )} ) } export default NotificationDrawer