Skip to content

Commit

Permalink
fix(fe): differentiate toast messages for save and submit actions (#2161
Browse files Browse the repository at this point in the history
)

* fix(fe): differentiate toast messages for save and submit actions

* fix(fe): fix failure routing to submission page after code submit
  • Loading branch information
B0XERCAT authored Oct 13, 2024
1 parent 00a44b2 commit 418fc11
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions apps/frontend/components/EditorHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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')
}
}

Expand Down Expand Up @@ -314,7 +316,7 @@ export default function Editor({
<Button
size="icon"
className="size-7 h-8 w-[77px] shrink-0 gap-[5px] rounded-[4px] bg-[#D7E5FE] font-medium text-[#484C4D] hover:bg-[#c6d3ea]"
onClick={saveCode}
onClick={() => saveCode()}
>
<Save className="stroke-1" size={22} />
Save
Expand Down

0 comments on commit 418fc11

Please sign in to comment.