Skip to content

Commit 559af68

Browse files
committed
fix multiple code saved messages and submission or test case running forever on error
1 parent e5642a7 commit 559af68

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

apps/frontend/src/app/collaboration/[id]/page.tsx

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,19 @@ export default function CollaborationPage(props: CollaborationProps) {
238238
}
239239
setIsLoadingTestCase(true);
240240
sendExecutingStateToMatchedUser(true);
241-
const data = await ExecuteVisibleAndCustomTests(questionDocRefId, {
242-
code: code,
243-
language: selectedLanguage,
244-
customTestCases: "",
245-
});
246-
updateExecutionResults(data);
247-
infoMessage("Test cases executed. Review the results below.");
248-
sendExecutionResultsToMatchedUser(data);
249-
setIsLoadingTestCase(false);
250-
sendExecutingStateToMatchedUser(false);
241+
try {
242+
const data = await ExecuteVisibleAndCustomTests(questionDocRefId, {
243+
code: code,
244+
language: selectedLanguage,
245+
customTestCases: "",
246+
});
247+
updateExecutionResults(data);
248+
successMessage("Test cases executed. Review the results below.");
249+
sendExecutionResultsToMatchedUser(data);
250+
} finally {
251+
setIsLoadingTestCase(false);
252+
sendExecutingStateToMatchedUser(false);
253+
}
251254
};
252255

253256
const handleSubmitCode = async () => {
@@ -256,25 +259,28 @@ export default function CollaborationPage(props: CollaborationProps) {
256259
}
257260
setIsLoadingSubmission(true);
258261
sendSubmittingStateToMatchedUser(true);
259-
const data = await ExecuteVisibleAndHiddenTestsAndSubmit(questionDocRefId, {
260-
code: code,
261-
language: selectedLanguage,
262-
user: currentUser ?? "",
263-
matchedUser: matchedUser ?? "",
264-
matchedTopics: matchedTopics ?? [],
265-
title: questionTitle ?? "",
266-
questionDifficulty: complexity ?? "",
267-
questionTopics: categories,
268-
});
269-
updateExecutionResults({
270-
visibleTestResults: data.visibleTestResults,
271-
customTestResults: [],
272-
});
273-
updateSubmissionResults(data);
274-
sendSubmissionResultsToMatchedUser(data);
275-
successMessage("Code saved successfully!");
276-
setIsLoadingSubmission(false);
277-
sendSubmittingStateToMatchedUser(false);
262+
try {
263+
const data = await ExecuteVisibleAndHiddenTestsAndSubmit(questionDocRefId, {
264+
code: code,
265+
language: selectedLanguage,
266+
user: currentUser ?? "",
267+
matchedUser: matchedUser ?? "",
268+
matchedTopics: matchedTopics ?? [],
269+
title: questionTitle ?? "",
270+
questionDifficulty: complexity ?? "",
271+
questionTopics: categories,
272+
});
273+
updateExecutionResults({
274+
visibleTestResults: data.visibleTestResults,
275+
customTestResults: [],
276+
});
277+
updateSubmissionResults(data);
278+
sendSubmissionResultsToMatchedUser(data);
279+
successMessage("Code saved successfully!");
280+
} finally {
281+
setIsLoadingSubmission(false);
282+
sendSubmittingStateToMatchedUser(false);
283+
}
278284
};
279285

280286
const handleCodeChange = (code: string) => {

apps/frontend/src/components/CollaborativeEditor/CollaborativeEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ const CollaborativeEditor = forwardRef(
303303
state.editorState &&
304304
state.editorState.id !== latestLanguageChangeId
305305
) {
306-
latestSubmissionId = state.editorState.id;
306+
latestLanguageChangeId = state.editorState.id;
307307
setSelectedLanguage(state.editorState.language);
308308
// if (props.user === state.user.name) {
309309
// console.log("ownself update ownself");

0 commit comments

Comments
 (0)