// Copyright 2024, Command Line Inc. // SPDX-License-Identifier: Apache-2.0 import { atoms } from "@/store/global"; import { FloatingPortal, useFloating, useInteractions } from "@floating-ui/react"; import clsx from "clsx"; import { useAtomValue } from "jotai"; import { useEffect, useState } from "react"; import "./notificationbubbles.scss"; import { NotificationItem } from "./notificationitem"; import { useNotification } from "./usenotification"; const NotificationBubbles = () => { const { notifications, hoveredId, hideNotification, copyNotification, handleActionClick, formatTimestamp, setHoveredId, } = useNotification(); const [isOpen, setIsOpen] = useState(notifications.length > 0); const notificationPopoverMode = useAtomValue(atoms.notificationPopoverMode); useEffect(() => { setIsOpen(notifications.length > 0); }, [notifications.length]); const { refs, strategy } = useFloating({ open: isOpen, onOpenChange: setIsOpen, strategy: "fixed", }); const { getFloatingProps } = useInteractions(); const floatingStyles = { position: strategy, right: "58px", bottom: "10px", top: "auto", left: "auto", }; if (!isOpen || notificationPopoverMode) { return null; } return (
e.stopPropagation(), })} > {notifications.map((notif) => { if (notif.hidden) return null; return ( setHoveredId(notif.id)} onMouseLeave={() => setHoveredId(null)} isBubble={true} /> ); })}
); }; export { NotificationBubbles };