diff --git a/sim/app/w/[id]/components/control-bar/components/notification-dropdown-item/notification-dropdown-item.tsx b/sim/app/w/[id]/components/control-bar/components/notification-dropdown-item/notification-dropdown-item.tsx index 7fe56c91c9..271d2dfaff 100644 --- a/sim/app/w/[id]/components/control-bar/components/notification-dropdown-item/notification-dropdown-item.tsx +++ b/sim/app/w/[id]/components/control-bar/components/notification-dropdown-item/notification-dropdown-item.tsx @@ -13,6 +13,7 @@ interface NotificationDropdownItemProps { message: string timestamp: number options?: NotificationOptions + setDropdownOpen?: (open: boolean) => void } const NotificationIcon = { @@ -37,6 +38,7 @@ export function NotificationDropdownItem({ message, timestamp, options, + setDropdownOpen, }: NotificationDropdownItemProps) { const { showNotification } = useNotificationStore() const Icon = NotificationIcon[type] @@ -48,15 +50,23 @@ export function NotificationDropdownItem({ return () => clearInterval(interval) }, []) + // Handle click to show the notification + const handleClick = (e: React.MouseEvent) => { + e.preventDefault() + e.stopPropagation() + showNotification(id) + // Close the dropdown after clicking + if (setDropdownOpen) { + setDropdownOpen(false) + } + } + // Format time and replace "less than a minute ago" with "<1 minute ago" const rawTimeAgo = formatDistanceToNow(timestamp, { addSuffix: true }) const timeAgo = rawTimeAgo.replace('less than a minute ago', '<1 minute ago') return ( - showNotification(id)} - > +
diff --git a/sim/app/w/[id]/components/control-bar/control-bar.tsx b/sim/app/w/[id]/components/control-bar/control-bar.tsx index 46b35b3680..d2ec180223 100644 --- a/sim/app/w/[id]/components/control-bar/control-bar.tsx +++ b/sim/app/w/[id]/components/control-bar/control-bar.tsx @@ -559,6 +559,7 @@ export function ControlBar() { message={notification.message} timestamp={notification.timestamp} options={notification.options} + setDropdownOpen={setNotificationsOpen} /> ))} diff --git a/sim/app/w/[id]/components/notifications/notifications.tsx b/sim/app/w/[id]/components/notifications/notifications.tsx index ab6f5b2e7b..c97e49f2cc 100644 --- a/sim/app/w/[id]/components/notifications/notifications.tsx +++ b/sim/app/w/[id]/components/notifications/notifications.tsx @@ -148,6 +148,28 @@ export function NotificationList() { !removedIds.has(n.id) ) + // Reset removedIds whenever a notification's visibility changes from false to true + useEffect(() => { + const newlyVisibleNotifications = notifications.filter( + (n) => n.isVisible && removedIds.has(n.id) + ) + + if (newlyVisibleNotifications.length > 0) { + setRemovedIds((prev) => { + const next = new Set(prev) + newlyVisibleNotifications.forEach((n) => next.delete(n.id)) + return next + }) + + // Also reset fading state for these notifications + setFadingNotifications((prev) => { + const next = new Set(prev) + newlyVisibleNotifications.forEach((n) => next.delete(n.id)) + return next + }) + } + }, [notifications, removedIds]) + // Handle auto-dismissal of non-persistent notifications useEffect(() => { // Setup timers for each notification diff --git a/sim/stores/notifications/store.ts b/sim/stores/notifications/store.ts index 578ef6a6a7..508fbd7c15 100644 --- a/sim/stores/notifications/store.ts +++ b/sim/stores/notifications/store.ts @@ -61,9 +61,16 @@ export const useNotificationStore = create()( showNotification: (id) => set((state) => { - const newNotifications = state.notifications.map((n) => - n.id === id ? { ...n, isVisible: true } : n - ) + // Find the notification first to ensure it exists + const notification = state.notifications.find(n => n.id === id) + if (!notification) return { notifications: state.notifications } + + // Bring the notification to the top and make it visible + const filteredNotifications = state.notifications.filter(n => n.id !== id) + const updatedNotification = { ...notification, isVisible: true, read: false } + + // Put the notification at the top so it's easily visible in dropdowns + const newNotifications = [updatedNotification, ...filteredNotifications] persistNotifications(newNotifications) return { notifications: newNotifications } }),