From 559af685a0256c2cf2d87ef4ec12c09126c7a7f5 Mon Sep 17 00:00:00 2001 From: solomonng2001 Date: Thu, 14 Nov 2024 09:39:32 +0800 Subject: [PATCH 1/2] fix multiple code saved messages and submission or test case running forever on error --- .../src/app/collaboration/[id]/page.tsx | 64 ++++++++++--------- .../CollaborativeEditor.tsx | 2 +- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/apps/frontend/src/app/collaboration/[id]/page.tsx b/apps/frontend/src/app/collaboration/[id]/page.tsx index b5df554935..4def83a20a 100644 --- a/apps/frontend/src/app/collaboration/[id]/page.tsx +++ b/apps/frontend/src/app/collaboration/[id]/page.tsx @@ -238,16 +238,19 @@ export default function CollaborationPage(props: CollaborationProps) { } setIsLoadingTestCase(true); sendExecutingStateToMatchedUser(true); - const data = await ExecuteVisibleAndCustomTests(questionDocRefId, { - code: code, - language: selectedLanguage, - customTestCases: "", - }); - updateExecutionResults(data); - infoMessage("Test cases executed. Review the results below."); - sendExecutionResultsToMatchedUser(data); - setIsLoadingTestCase(false); - sendExecutingStateToMatchedUser(false); + try { + const data = await ExecuteVisibleAndCustomTests(questionDocRefId, { + code: code, + language: selectedLanguage, + customTestCases: "", + }); + updateExecutionResults(data); + successMessage("Test cases executed. Review the results below."); + sendExecutionResultsToMatchedUser(data); + } finally { + setIsLoadingTestCase(false); + sendExecutingStateToMatchedUser(false); + } }; const handleSubmitCode = async () => { @@ -256,25 +259,28 @@ export default function CollaborationPage(props: CollaborationProps) { } setIsLoadingSubmission(true); sendSubmittingStateToMatchedUser(true); - const data = await ExecuteVisibleAndHiddenTestsAndSubmit(questionDocRefId, { - code: code, - language: selectedLanguage, - user: currentUser ?? "", - matchedUser: matchedUser ?? "", - matchedTopics: matchedTopics ?? [], - title: questionTitle ?? "", - questionDifficulty: complexity ?? "", - questionTopics: categories, - }); - updateExecutionResults({ - visibleTestResults: data.visibleTestResults, - customTestResults: [], - }); - updateSubmissionResults(data); - sendSubmissionResultsToMatchedUser(data); - successMessage("Code saved successfully!"); - setIsLoadingSubmission(false); - sendSubmittingStateToMatchedUser(false); + try { + const data = await ExecuteVisibleAndHiddenTestsAndSubmit(questionDocRefId, { + code: code, + language: selectedLanguage, + user: currentUser ?? "", + matchedUser: matchedUser ?? "", + matchedTopics: matchedTopics ?? [], + title: questionTitle ?? "", + questionDifficulty: complexity ?? "", + questionTopics: categories, + }); + updateExecutionResults({ + visibleTestResults: data.visibleTestResults, + customTestResults: [], + }); + updateSubmissionResults(data); + sendSubmissionResultsToMatchedUser(data); + successMessage("Code saved successfully!"); + } finally { + setIsLoadingSubmission(false); + sendSubmittingStateToMatchedUser(false); + } }; const handleCodeChange = (code: string) => { diff --git a/apps/frontend/src/components/CollaborativeEditor/CollaborativeEditor.tsx b/apps/frontend/src/components/CollaborativeEditor/CollaborativeEditor.tsx index fab13f68ac..d07591a666 100644 --- a/apps/frontend/src/components/CollaborativeEditor/CollaborativeEditor.tsx +++ b/apps/frontend/src/components/CollaborativeEditor/CollaborativeEditor.tsx @@ -303,7 +303,7 @@ const CollaborativeEditor = forwardRef( state.editorState && state.editorState.id !== latestLanguageChangeId ) { - latestSubmissionId = state.editorState.id; + latestLanguageChangeId = state.editorState.id; setSelectedLanguage(state.editorState.language); // if (props.user === state.user.name) { // console.log("ownself update ownself"); From 28871f9fb34b21245999bbdf8ee59d028c423b44 Mon Sep 17 00:00:00 2001 From: solomonng2001 Date: Thu, 14 Nov 2024 09:56:28 +0800 Subject: [PATCH 2/2] Add info tool tip to clarify running test cases and submitting code --- apps/frontend/src/app/collaboration/[id]/page.tsx | 3 +++ .../components/question/TestcaseDetail/TestcaseDetail.tsx | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/frontend/src/app/collaboration/[id]/page.tsx b/apps/frontend/src/app/collaboration/[id]/page.tsx index 1ed32103aa..1d5cb76987 100644 --- a/apps/frontend/src/app/collaboration/[id]/page.tsx +++ b/apps/frontend/src/app/collaboration/[id]/page.tsx @@ -500,6 +500,9 @@ export default function CollaborationPage(props: CollaborationProps) {
{isLoadingSubmission && }
+ + +