mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Don't display toast on own chat page
This commit is contained in:
1 file changed
+7
-6
@@ -1,7 +1,7 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
import { useSessionManager } from '@/hooks/useSessionManager';
|
import { useSessionManager } from '@/hooks/useSessionManager';
|
||||||
import { useToast } from '@/hooks/useToast';
|
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
|
* Global component that monitors AI sessions and shows notifications
|
||||||
@@ -11,7 +11,6 @@ export function SessionMonitor() {
|
|||||||
const sessionManager = useSessionManager();
|
const sessionManager = useSessionManager();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation();
|
|
||||||
const previousLoadingStates = useRef<Map<string, boolean>>(new Map());
|
const previousLoadingStates = useRef<Map<string, boolean>>(new Map());
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -25,18 +24,20 @@ export function SessionMonitor() {
|
|||||||
if (!session) return;
|
if (!session) return;
|
||||||
|
|
||||||
// Check if user is currently viewing this project or chat
|
// Check if user is currently viewing this project or chat
|
||||||
const pathParts = location.pathname.split('/');
|
// Use window.location.pathname to get the current path at the time the event fires
|
||||||
const currentId = pathParts[2]; // /project/{projectId} or /chat/{chatId}
|
const pathParts = window.location.pathname.split('/');
|
||||||
|
const currentId = pathParts[2] ? decodeURIComponent(pathParts[2]) : ''; // /project/{projectId} or /chat/{chatId}
|
||||||
const isCurrentView = session.projectId === currentId;
|
const isCurrentView = session.projectId === currentId;
|
||||||
|
|
||||||
// Only show notification if user is not currently viewing this project or chat
|
// Only show notification if user is not currently viewing this project or chat
|
||||||
if (!isCurrentView) {
|
if (!isCurrentView) {
|
||||||
|
const viewPath = session.isChat ? `/chat/${session.projectId}` : `/project/${session.projectId}`;
|
||||||
toast({
|
toast({
|
||||||
title: "AI Session Complete",
|
title: "AI Session Complete",
|
||||||
description: `Finished working on ${session.projectId}`,
|
description: `Finished working on ${session.projectId}`,
|
||||||
action: (
|
action: (
|
||||||
<button
|
<button
|
||||||
onClick={() => navigate(`/project/${session.projectId}`)}
|
onClick={() => navigate(viewPath)}
|
||||||
className="inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus-visible:ring-destructive"
|
className="inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus-visible:ring-destructive"
|
||||||
>
|
>
|
||||||
View
|
View
|
||||||
@@ -73,7 +74,7 @@ export function SessionMonitor() {
|
|||||||
sessionManager.off('sessionCreated', handleSessionCreated);
|
sessionManager.off('sessionCreated', handleSessionCreated);
|
||||||
sessionManager.off('sessionDeleted', handleSessionDeleted);
|
sessionManager.off('sessionDeleted', handleSessionDeleted);
|
||||||
};
|
};
|
||||||
}, [sessionManager, toast, navigate, location.pathname]);
|
}, [sessionManager, toast, navigate]);
|
||||||
|
|
||||||
// This component doesn't render anything
|
// This component doesn't render anything
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in new issue
Block a user