diff --git a/servers/nextjs/app/(presentation-generator)/documents-preview/components/DocumentPreviewPage.tsx b/servers/nextjs/app/(presentation-generator)/documents-preview/components/DocumentPreviewPage.tsx index 9de1244c..f77e9017 100644 --- a/servers/nextjs/app/(presentation-generator)/documents-preview/components/DocumentPreviewPage.tsx +++ b/servers/nextjs/app/(presentation-generator)/documents-preview/components/DocumentPreviewPage.tsx @@ -148,7 +148,7 @@ const DocumentsPreviewPage: React.FC = () => { }); dispatch(setPresentationId(createResponse.id)); - router.push("/outline"); + router.replace("/outline"); } catch (error: any) { console.error("Error in radar presentation creation:", error); toast.error('Error', { diff --git a/servers/nextjs/app/(presentation-generator)/outline/hooks/useOutlineStreaming.ts b/servers/nextjs/app/(presentation-generator)/outline/hooks/useOutlineStreaming.ts index 3b29f113..f5db594e 100644 --- a/servers/nextjs/app/(presentation-generator)/outline/hooks/useOutlineStreaming.ts +++ b/servers/nextjs/app/(presentation-generator)/outline/hooks/useOutlineStreaming.ts @@ -85,11 +85,11 @@ export const useOutlineStreaming = (presentationId: string | null) => { } catch (error) { setStreamState({ isStreaming: false, isLoading: false }); toast.error("Failed to initialize connection"); + }finally{ + setStreamState({ isStreaming: false, isLoading: false }); } }; - - initializeStream(); - + initializeStream(); return () => { if (eventSource) { eventSource.close(); diff --git a/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts b/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts index 726056c9..d3e0604f 100644 --- a/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts +++ b/servers/nextjs/app/(presentation-generator)/outline/hooks/usePresentationGeneration.ts @@ -84,7 +84,7 @@ export const usePresentationGeneration = ( if (response) { dispatch(clearPresentationData()); - router.push(`/presentation?id=${presentationId}&stream=true`); + router.replace(`/presentation?id=${presentationId}&stream=true`); } } catch (error: any) { console.error('Error In Presentation Generation(prepare).', error); diff --git a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts index 042ba11a..b28fe3ca 100644 --- a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts +++ b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts @@ -6,7 +6,7 @@ import { setStreaming, } from "@/store/slices/presentationGeneration"; import { jsonrepair } from "jsonrepair"; -import { RootState } from "@/store/store"; +import { toast } from "sonner"; export const usePresentationStreaming = ( presentationId: string, @@ -89,6 +89,17 @@ export const usePresentationStreaming = ( newUrl.searchParams.delete("stream"); window.history.replaceState({}, "", newUrl.toString()); break; + case "error": + eventSource.close(); + toast.error("Error in outline streaming", { + description: + data.detail || + "Failed to connect to the server. Please try again.", + }); + setLoading(false); + dispatch(setStreaming(false)); + setError(true); + break; } }); diff --git a/servers/nextjs/app/(presentation-generator)/upload/components/UploadPage.tsx b/servers/nextjs/app/(presentation-generator)/upload/components/UploadPage.tsx index 0c16b25f..f8799d51 100644 --- a/servers/nextjs/app/(presentation-generator)/upload/components/UploadPage.tsx +++ b/servers/nextjs/app/(presentation-generator)/upload/components/UploadPage.tsx @@ -131,6 +131,7 @@ const UploadPage = () => { config, files: responses, })); + dispatch(clearOutlines()); router.push("/documents-preview"); };