From 418fc11066fd96e641806f11a07af803df89fd63 Mon Sep 17 00:00:00 2001 From: Kwon Seo Jin <97675977+B0XERCAT@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:58:32 +0900 Subject: [PATCH] fix(fe): differentiate toast messages for save and submit actions (#2161) * fix(fe): differentiate toast messages for save and submit actions * fix(fe): fix failure routing to submission page after code submit --- apps/frontend/components/EditorHeader.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/frontend/components/EditorHeader.tsx b/apps/frontend/components/EditorHeader.tsx index cf600262b6..6a80c7a8fb 100644 --- a/apps/frontend/components/EditorHeader.tsx +++ b/apps/frontend/components/EditorHeader.tsx @@ -153,16 +153,16 @@ export default function Editor({ } }) if (res.ok) { - saveCode() + saveCode(true) const submission: Submission = await res.json() setSubmissionId(submission.id) } else { + setLoading(false) if (res.status === 401) { showSignIn() toast.error('Log in first to submit your code') } else toast.error('Please try again later.') } - setLoading(false) } const submitTest = async () => { @@ -242,14 +242,16 @@ export default function Editor({ poll() } - const saveCode = async () => { + const saveCode = async (isSubmitting?: boolean) => { const session = await auth() if (!session) { toast.error('Log in first to save your code') } else { - if (storeCodeToLocalstorage()) - toast.success('Successfully saved the code') - else toast.error('Failed to save the code') + if (storeCodeToLocalstorage()) { + toast.success( + `Successfully ${isSubmitting ? 'submitted' : 'saved'} the code` + ) + } else toast.error('Failed to save the code') } } @@ -314,7 +316,7 @@ export default function Editor({