From a3b2dc1631dffbc65e3978923572ecd46830e925 Mon Sep 17 00:00:00 2001 From: shiva raj badu Date: Mon, 4 Aug 2025 13:29:08 +0545 Subject: [PATCH] fix(Nextjs): Get Presentation by ID stuck in loading --- servers/fastapi/chroma/chroma.sqlite3 | Bin 4329472 -> 4329472 bytes .../components/PresentationPage.tsx | 47 ++++++++---------- .../presentation/hooks/usePresentationData.ts | 9 +--- .../hooks/usePresentationStreaming.ts | 21 ++++---- 4 files changed, 32 insertions(+), 45 deletions(-) diff --git a/servers/fastapi/chroma/chroma.sqlite3 b/servers/fastapi/chroma/chroma.sqlite3 index d7ddd11b0cc497bab197c752272c05778e2ba3ff..9d870fdb0e626dbca6cec495f7875e4b9c74fc56 100644 GIT binary patch delta 317 zcmWm9Ia0!406<}qfEbn^qU<|FWM7m`wh*w*A-D;dp}b>UN1ic3|NWa}6^$B-aHfg2t? zz>7zy@WGD&f)EHH3=L0sMg&pB5Jv(@q>x4iS>%vM0Y#Lc;{|2BqJk=FsH1@7CGcmKoKRBQ9%_o)X_i_Ews@=7d`Ybzz`#hF~Jlw%(1`{EBxPU KXm6ozw9gNxFM3h{ diff --git a/servers/nextjs/app/(presentation-generator)/presentation/components/PresentationPage.tsx b/servers/nextjs/app/(presentation-generator)/presentation/components/PresentationPage.tsx index 052c7731..c0d412ff 100644 --- a/servers/nextjs/app/(presentation-generator)/presentation/components/PresentationPage.tsx +++ b/servers/nextjs/app/(presentation-generator)/presentation/components/PresentationPage.tsx @@ -14,13 +14,14 @@ import { usePresentationStreaming, usePresentationData, usePresentationNavigation, - useAutoSave + useAutoSave, } from "../hooks"; import { PresentationPageProps } from "../types"; import LoadingState from "./LoadingState"; -const PresentationPage: React.FC = ({ presentation_id }) => { - +const PresentationPage: React.FC = ({ + presentation_id, +}) => { // State management const [loading, setLoading] = useState(true); const [selectedSlide, setSelectedSlide] = useState(0); @@ -28,7 +29,6 @@ const PresentationPage: React.FC = ({ presentation_id }) const [error, setError] = useState(false); const [isMobilePanelOpen, setIsMobilePanelOpen] = useState(false); - const { presentationData, isStreaming } = useSelector( (state: RootState) => state.presentationGeneration ); @@ -37,7 +37,6 @@ const PresentationPage: React.FC = ({ presentation_id }) const { isSaving } = useAutoSave({ debounceMs: 2000, enabled: !!presentationData && !isStreaming, - }); // Custom hooks @@ -54,7 +53,12 @@ const PresentationPage: React.FC = ({ presentation_id }) toggleFullscreen, handlePresentExit, handleSlideChange, - } = usePresentationNavigation(presentation_id, selectedSlide, setSelectedSlide, setIsFullscreen); + } = usePresentationNavigation( + presentation_id, + selectedSlide, + setSelectedSlide, + setIsFullscreen + ); // Initialize streaming usePresentationStreaming( @@ -65,13 +69,10 @@ const PresentationPage: React.FC = ({ presentation_id }) fetchUserSlides ); - const onSlideChange = (newSlide: number) => { handleSlideChange(newSlide, presentationData); }; - - // Presentation Mode View if (isPresentMode) { return ( @@ -94,15 +95,11 @@ const PresentationPage: React.FC = ({ presentation_id }) role="alert" > -

- Something went wrong -

+

Something went wrong

We couldn't load your presentation. Please try again.

- + ); @@ -110,12 +107,8 @@ const PresentationPage: React.FC = ({ presentation_id }) return (
-
- {isSaving && ( - - )} - + {isSaving && }
@@ -123,7 +116,7 @@ const PresentationPage: React.FC = ({ presentation_id })
@@ -136,11 +129,14 @@ const PresentationPage: React.FC = ({ presentation_id }) />
-
+
{!presentationData || - loading || - !presentationData?.slides || - presentationData?.slides.length === 0 ? ( + loading || + !presentationData?.slides || + presentationData?.slides.length === 0 ? (
{Array.from({ length: 2 }).map((_, index) => ( @@ -163,7 +159,6 @@ const PresentationPage: React.FC = ({ presentation_id }) slide={slide} index={index} presentationId={presentation_id} - /> ))} diff --git a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationData.ts b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationData.ts index 73154fbe..577b6da3 100644 --- a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationData.ts +++ b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationData.ts @@ -1,4 +1,4 @@ -import { useCallback, useEffect } from 'react'; +import { useCallback, useEffect } from "react"; import { useDispatch } from "react-redux"; import { toast } from "sonner"; import { DashboardApi } from "@/app/dashboard/api/dashboard"; @@ -12,7 +12,6 @@ export const usePresentationData = ( const dispatch = useDispatch(); const fetchUserSlides = useCallback(async () => { - console.log("fetching user slides inside usePresentationData"); try { const data = await DashboardApi.getPresentation(presentationId); if (data) { @@ -27,11 +26,7 @@ export const usePresentationData = ( } }, [presentationId, dispatch, setLoading, setError]); - // useEffect(() => { - // fetchUserSlides(); - // }, [fetchUserSlides]); - return { fetchUserSlides, }; -}; \ No newline at end of file +}; diff --git a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts index ada9eeae..042ba11a 100644 --- a/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts +++ b/servers/nextjs/app/(presentation-generator)/presentation/hooks/usePresentationStreaming.ts @@ -1,6 +1,10 @@ import { useEffect, useRef } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { clearPresentationData, setPresentationData, setStreaming } from "@/store/slices/presentationGeneration"; +import { + clearPresentationData, + setPresentationData, + setStreaming, +} from "@/store/slices/presentationGeneration"; import { jsonrepair } from "jsonrepair"; import { RootState } from "@/store/store"; @@ -11,8 +15,6 @@ export const usePresentationStreaming = ( setError: (error: boolean) => void, fetchUserSlides: () => void ) => { - const { presentationData } = useSelector((state: RootState) => state.presentationGeneration); - const dispatch = useDispatch(); const previousSlidesLength = useRef(0); @@ -64,7 +66,7 @@ export const usePresentationStreaming = ( dispatch(setStreaming(false)); setLoading(false); eventSource.close(); - + // Remove stream parameter from URL const newUrl = new URL(window.location.href); newUrl.searchParams.delete("stream"); @@ -81,7 +83,7 @@ export const usePresentationStreaming = ( setLoading(false); dispatch(setStreaming(false)); eventSource.close(); - + // Remove stream parameter from URL const newUrl = new URL(window.location.href); newUrl.searchParams.delete("stream"); @@ -102,12 +104,7 @@ export const usePresentationStreaming = ( if (stream) { initializeStream(); } else { - console.log("stream is null", stream); - console.log("presentationData", presentationData); - if(!presentationData || presentationData.slides.length === 0){ - console.log("fetching user slides"); - fetchUserSlides(); - } + fetchUserSlides(); } return () => { @@ -116,4 +113,4 @@ export const usePresentationStreaming = ( } }; }, [presentationId, stream, dispatch, setLoading, setError, fetchUserSlides]); -}; \ No newline at end of file +};