1- import { memo , useCallback } from 'react'
1+ import { memo , useCallback , useMemo } from 'react'
22import clsx from 'clsx'
33import { X } from 'lucide-react'
4- import { useParams } from 'next/navigation'
54import { Button } from '@/components/emcn'
65import { createLogger } from '@/lib/logs/console/logger'
76import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
@@ -13,6 +12,7 @@ import {
1312 useNotificationStore ,
1413} from '@/stores/notifications'
1514import { useTerminalStore } from '@/stores/terminal'
15+ import { useWorkflowRegistry } from '@/stores/workflows/registry/store'
1616
1717const logger = createLogger ( 'Notifications' )
1818const MAX_VISIBLE_NOTIFICATIONS = 4
@@ -23,15 +23,18 @@ const MAX_VISIBLE_NOTIFICATIONS = 4
2323 * Shows both global notifications and workflow-specific notifications
2424 */
2525export const Notifications = memo ( function Notifications ( ) {
26- const params = useParams ( )
27- const workflowId = params . workflowId as string
26+ const activeWorkflowId = useWorkflowRegistry ( ( state ) => state . activeWorkflowId )
2827
29- const notifications = useNotificationStore ( ( state ) =>
30- state . notifications . filter ( ( n ) => ! n . workflowId || n . workflowId === workflowId )
31- )
28+ const allNotifications = useNotificationStore ( ( state ) => state . notifications )
3229 const removeNotification = useNotificationStore ( ( state ) => state . removeNotification )
3330 const clearNotifications = useNotificationStore ( ( state ) => state . clearNotifications )
34- const visibleNotifications = notifications . slice ( 0 , MAX_VISIBLE_NOTIFICATIONS )
31+
32+ const visibleNotifications = useMemo ( ( ) => {
33+ if ( ! activeWorkflowId ) return [ ]
34+ return allNotifications
35+ . filter ( ( n ) => ! n . workflowId || n . workflowId === activeWorkflowId )
36+ . slice ( 0 , MAX_VISIBLE_NOTIFICATIONS )
37+ } , [ allNotifications , activeWorkflowId ] )
3538 const isTerminalResizing = useTerminalStore ( ( state ) => state . isResizing )
3639
3740 /**
@@ -85,7 +88,7 @@ export const Notifications = memo(function Notifications() {
8588 {
8689 id : 'clear-notifications' ,
8790 handler : ( ) => {
88- clearNotifications ( workflowId )
91+ clearNotifications ( activeWorkflowId ?? undefined )
8992 } ,
9093 overrides : {
9194 allowInEditable : false ,
0 commit comments