From 0c65246703924052f09387f94fb537fcdbaf9e2b Mon Sep 17 00:00:00 2001 From: Joep31 Date: Wed, 6 May 2026 10:09:13 +0200 Subject: [PATCH] fix: set overlay state to idle when comment actions error --- .../features/comments/_components/toolbar.tsx | 15 +++++++++++++-- playground/features/comments/server.ts | 4 ++++ src/contexts/comment-context.tsx | 4 +++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/playground/features/comments/_components/toolbar.tsx b/playground/features/comments/_components/toolbar.tsx index 974d376..fc38d41 100644 --- a/playground/features/comments/_components/toolbar.tsx +++ b/playground/features/comments/_components/toolbar.tsx @@ -18,12 +18,23 @@ export const CommentToolbar = () => { {draftComments?.length ? ( - Confirm comments + + {overlayState === "saving" + ? "Confirming comments..." + : "Confirm comments"} + ) : null} {resolvingComments?.length ? ( - Resolve comments + + {overlayState === "resolving" + ? "Resolving comments..." + : "Resolve comments"} + ) : null} diff --git a/playground/features/comments/server.ts b/playground/features/comments/server.ts index 90903cc..048bcef 100644 --- a/playground/features/comments/server.ts +++ b/playground/features/comments/server.ts @@ -5,10 +5,14 @@ export async function sendCommentsToDataBase( comments: ConfirmedComment[], projectId?: string, ) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + console.info("Project ID:", projectId); console.info("Adding comments:", comments); } export async function resolveCommentsInDataBase(comments: ConfirmedComment[]) { + await new Promise((resolve) => setTimeout(resolve, 1000)); + console.info("Resolving comments:", comments); } diff --git a/src/contexts/comment-context.tsx b/src/contexts/comment-context.tsx index e4656ea..919df1c 100644 --- a/src/contexts/comment-context.tsx +++ b/src/contexts/comment-context.tsx @@ -289,6 +289,7 @@ export const CommentContextProvider = ({ if (onError) { onError(new ConfirmError(error.message)); } + dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" }); return { error: new ConfirmError(error.message) }; } @@ -313,11 +314,12 @@ export const CommentContextProvider = ({ if (onError) { onError(new ResolveError(error.message)); } + dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" }); return { error: new ResolveError(error.message) }; } - dispatch({ type: "RESET_RESOLVING_COMMENTS" }); dispatch({ type: "CHANGE_OVERLAYSTATE", to: "idle" }); + dispatch({ type: "RESET_RESOLVING_COMMENTS" }); return { error: null }; };