diff --git a/src/components/SessionMonitor.tsx b/src/components/SessionMonitor.tsx index f3db0bf9..2d663ec7 100644 --- a/src/components/SessionMonitor.tsx +++ b/src/components/SessionMonitor.tsx @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; import { useSessionManager } from '@/hooks/useSessionManager'; import { useToast } from '@/hooks/useToast'; -import { useNavigate, useLocation } from 'react-router-dom'; +import { useNavigate } from 'react-router-dom'; /** * Global component that monitors AI sessions and shows notifications @@ -11,7 +11,6 @@ export function SessionMonitor() { const sessionManager = useSessionManager(); const { toast } = useToast(); const navigate = useNavigate(); - const location = useLocation(); const previousLoadingStates = useRef>(new Map()); useEffect(() => { @@ -25,18 +24,20 @@ export function SessionMonitor() { if (!session) return; // Check if user is currently viewing this project or chat - const pathParts = location.pathname.split('/'); - const currentId = pathParts[2]; // /project/{projectId} or /chat/{chatId} + // Use window.location.pathname to get the current path at the time the event fires + const pathParts = window.location.pathname.split('/'); + const currentId = pathParts[2] ? decodeURIComponent(pathParts[2]) : ''; // /project/{projectId} or /chat/{chatId} const isCurrentView = session.projectId === currentId; // Only show notification if user is not currently viewing this project or chat if (!isCurrentView) { + const viewPath = session.isChat ? `/chat/${session.projectId}` : `/project/${session.projectId}`; toast({ title: "AI Session Complete", description: `Finished working on ${session.projectId}`, action: (