Skip to content

Commit c32dbdc

Browse files
committed
fix(notifications): reopen on click
1 parent 289ab47 commit c32dbdc

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

sim/app/w/[id]/components/control-bar/components/notification-dropdown-item/notification-dropdown-item.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface NotificationDropdownItemProps {
1313
message: string
1414
timestamp: number
1515
options?: NotificationOptions
16+
setDropdownOpen?: (open: boolean) => void
1617
}
1718

1819
const NotificationIcon = {
@@ -37,6 +38,7 @@ export function NotificationDropdownItem({
3738
message,
3839
timestamp,
3940
options,
41+
setDropdownOpen,
4042
}: NotificationDropdownItemProps) {
4143
const { showNotification } = useNotificationStore()
4244
const Icon = NotificationIcon[type]
@@ -48,15 +50,23 @@ export function NotificationDropdownItem({
4850
return () => clearInterval(interval)
4951
}, [])
5052

53+
// Handle click to show the notification
54+
const handleClick = (e: React.MouseEvent) => {
55+
e.preventDefault()
56+
e.stopPropagation()
57+
showNotification(id)
58+
// Close the dropdown after clicking
59+
if (setDropdownOpen) {
60+
setDropdownOpen(false)
61+
}
62+
}
63+
5164
// Format time and replace "less than a minute ago" with "<1 minute ago"
5265
const rawTimeAgo = formatDistanceToNow(timestamp, { addSuffix: true })
5366
const timeAgo = rawTimeAgo.replace('less than a minute ago', '<1 minute ago')
5467

5568
return (
56-
<DropdownMenuItem
57-
className="flex items-start gap-2 p-3 cursor-pointer"
58-
onClick={() => showNotification(id)}
59-
>
69+
<DropdownMenuItem className="flex items-start gap-2 p-3 cursor-pointer" onClick={handleClick}>
6070
<Icon className={cn('h-4 w-4', NotificationColors[type])} />
6171
<div className="flex flex-col gap-1">
6272
<div className="flex items-center gap-2">

sim/app/w/[id]/components/control-bar/control-bar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ export function ControlBar() {
559559
message={notification.message}
560560
timestamp={notification.timestamp}
561561
options={notification.options}
562+
setDropdownOpen={setNotificationsOpen}
562563
/>
563564
))}
564565
</DropdownMenuContent>

sim/app/w/[id]/components/notifications/notifications.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ export function NotificationList() {
148148
!removedIds.has(n.id)
149149
)
150150

151+
// Reset removedIds whenever a notification's visibility changes from false to true
152+
useEffect(() => {
153+
const newlyVisibleNotifications = notifications.filter(
154+
(n) => n.isVisible && removedIds.has(n.id)
155+
)
156+
157+
if (newlyVisibleNotifications.length > 0) {
158+
setRemovedIds((prev) => {
159+
const next = new Set(prev)
160+
newlyVisibleNotifications.forEach((n) => next.delete(n.id))
161+
return next
162+
})
163+
164+
// Also reset fading state for these notifications
165+
setFadingNotifications((prev) => {
166+
const next = new Set(prev)
167+
newlyVisibleNotifications.forEach((n) => next.delete(n.id))
168+
return next
169+
})
170+
}
171+
}, [notifications, removedIds])
172+
151173
// Handle auto-dismissal of non-persistent notifications
152174
useEffect(() => {
153175
// Setup timers for each notification

sim/stores/notifications/store.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,16 @@ export const useNotificationStore = create<NotificationStore>()(
6161

6262
showNotification: (id) =>
6363
set((state) => {
64-
const newNotifications = state.notifications.map((n) =>
65-
n.id === id ? { ...n, isVisible: true } : n
66-
)
64+
// Find the notification first to ensure it exists
65+
const notification = state.notifications.find(n => n.id === id)
66+
if (!notification) return { notifications: state.notifications }
67+
68+
// Bring the notification to the top and make it visible
69+
const filteredNotifications = state.notifications.filter(n => n.id !== id)
70+
const updatedNotification = { ...notification, isVisible: true, read: false }
71+
72+
// Put the notification at the top so it's easily visible in dropdowns
73+
const newNotifications = [updatedNotification, ...filteredNotifications]
6774
persistNotifications(newNotifications)
6875
return { notifications: newNotifications }
6976
}),

0 commit comments

Comments
 (0)