From 237f9776308289e88faa3097292cf44321dc25c4 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sat, 1 Mar 2025 11:11:52 -0600 Subject: [PATCH] Improve router/upload state coordination --- src/photo/PhotoUploadWithStatus.tsx | 16 +++++++++++----- src/state/AppStateProvider.tsx | 2 -- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/photo/PhotoUploadWithStatus.tsx b/src/photo/PhotoUploadWithStatus.tsx index 4702d0de..1fd8ff38 100644 --- a/src/photo/PhotoUploadWithStatus.tsx +++ b/src/photo/PhotoUploadWithStatus.tsx @@ -56,17 +56,22 @@ export default function PhotoUploadWithStatus({ const shouldResetUploadStateAfterPending = useRef(false); const [isPending, startTransition] = useTransition(); + // Only reset upload state after route transition completes useEffect(() => { if (!isPending && shouldResetUploadStateAfterPending.current) { resetUploadState?.(); shouldResetUploadStateAfterPending.current = false; } + }, [isPending, resetUploadState]); + // Reset upload state when component unmounts + // when not reset during route transition + useEffect(() => { return () => { if (shouldResetUploadStateAfterPending.current) { resetUploadState?.(); } }; - }, [isPending, resetUploadState]); + }, [resetUploadState]); const isFinishing = isPending && shouldResetUploadStateAfterPending.current; const uploadNumberText = `${fileUploadIndex + 1} of ${filesLength}`; @@ -147,14 +152,15 @@ export default function PhotoUploadWithStatus({ {isUploading ? isFinishing ? <> - Finishing + Finishing ... : <> - {!showButton && + {!showButton && <> Uploading {uploadNumberText} - } - {': '} + + {': '} + } {fileUploadName} : !showButton && <>Initializing} diff --git a/src/state/AppStateProvider.tsx b/src/state/AppStateProvider.tsx index ed7ceb17..2bb492dc 100644 --- a/src/state/AppStateProvider.tsx +++ b/src/state/AppStateProvider.tsx @@ -134,8 +134,6 @@ export default function AppStateProvider({ }, ); - console.log('adminData', adminData); - useEffect(() => { if (userEmail) { storeAuthEmailCookie(userEmail);