import { useLocation, useMatches, useRevalidator } from "@remix-run/react"; import clsx from "clsx"; import * as React from "react"; import { Button } from "react-aria-components"; import { useTranslation } from "react-i18next"; import { NotificationItem, NotificationItemDivider, NotificationsList, } from "~/features/notifications/components/NotificationList"; import { NOTIFICATIONS } from "~/features/notifications/notifications-contants"; import type { RootLoaderData } from "~/root"; import { NOTIFICATIONS_URL } from "~/utils/urls"; import { useMarkNotificationsAsSeen } from "../../features/notifications/notifications-hooks"; import { LinkButton, SendouButton } from "../elements/Button"; import { SendouPopover } from "../elements/Popover"; import { BellIcon } from "../icons/Bell"; import { RefreshIcon } from "../icons/Refresh"; import styles from "./NotificationPopover.module.css"; export type LoaderNotification = NonNullable< RootLoaderData["notifications"] >[number]; export function NotificationPopover() { const location = useLocation(); const [root] = useMatches(); const notifications = (root.data as RootLoaderData | undefined) ?.notifications; const unseenIds = React.useMemo( () => notifications ?.filter((notification) => !notification.seen) .map((notification) => notification.id) ?? [], [notifications], ); if (!notifications) { return null; } return (
{unseenIds.length > 0 ?
: null} } popoverClassName={clsx(styles.popoverContainer, { [styles.noNotificationsContainer]: !notifications || notifications.length === 0, })} >
); } function NotificationContent({ notifications, unseenIds, }: { notifications: LoaderNotification[]; unseenIds: number[]; }) { const { t } = useTranslation(["common"]); const { revalidate, state } = useRevalidator(); useMarkNotificationsAsSeen(unseenIds); return ( <>

{t("common:notifications.title")}

} variant="minimal" className={styles.refreshButton} onPress={revalidate} isDisabled={state !== "idle"} />

{notifications.length === 0 ? (
{t("common:notifications.empty")}
) : ( {notifications.map((notification, i) => ( {i !== notifications.length - 1 && } ))} )} {notifications.length === NOTIFICATIONS.PEEK_COUNT ? ( ) : null} ); } function NotificationsFooter() { const { t } = useTranslation(["common"]); return (

{t("common:notifications.seeAll")}
); }