Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: store session info in localstorage #86

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions apps/frontend/src/app/collaboration/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,19 @@ export default function CollaborationPage(props: CollaborationProps) {
};

const updateSubmissionResults = (data: SubmissionResults) => {
setSubmissionHiddenTestResultsAndStatus({
const submissionHiddenTestResultsAndStatus: SubmissionHiddenTestResultsAndStatus = {
hiddenTestResults: data.hiddenTestResults,
status: data.status,
});
}
setSubmissionHiddenTestResultsAndStatus(submissionHiddenTestResultsAndStatus);
localStorage.setItem("submissionHiddenTestResultsAndStatus", JSON.stringify(submissionHiddenTestResultsAndStatus));
setVisibleTestCases(data.visibleTestResults);
localStorage.setItem("visibleTestResults", JSON.stringify(data.visibleTestResults));
};

const updateExecutionResults = (data: ExecutionResults) => {
setVisibleTestCases(data.visibleTestResults);
localStorage.setItem("visibleTestResults", JSON.stringify(data.visibleTestResults));
};

const handleRunTestCases = async () => {
Expand All @@ -231,7 +235,7 @@ export default function CollaborationPage(props: CollaborationProps) {
language: selectedLanguage,
customTestCases: "",
});
setVisibleTestCases(data.visibleTestResults);
updateExecutionResults(data);
infoMessage("Test cases executed. Review the results below.");
sendExecutionResultsToMatchedUser(data);
setIsLoadingTestCase(false);
Expand All @@ -254,11 +258,11 @@ export default function CollaborationPage(props: CollaborationProps) {
questionDifficulty: complexity ?? "",
questionTopics: categories,
});
setVisibleTestCases(data.visibleTestResults);
setSubmissionHiddenTestResultsAndStatus({
hiddenTestResults: data.hiddenTestResults,
status: data.status,
updateExecutionResults({
visibleTestResults: data.visibleTestResults,
customTestResults: [],
});
updateSubmissionResults(data);
sendSubmissionResultsToMatchedUser(data);
successMessage("Code saved successfully!");
setIsLoadingSubmission(false);
Expand All @@ -283,13 +287,20 @@ export default function CollaborationPage(props: CollaborationProps) {
const currentUser: string = localStorage.getItem("user") ?? "";
const matchedTopics: string[] =
localStorage.getItem("matchedTopics")?.split(",") ?? [];
const submissionHiddenTestResultsAndStatus: SubmissionHiddenTestResultsAndStatus | undefined =
localStorage.getItem("submissionHiddenTestResultsAndStatus")
? JSON.parse(localStorage.getItem("submissionHiddenTestResultsAndStatus") as string)
: undefined;
const visibleTestCases: Test[] = JSON.parse(localStorage.getItem("visibleTestResults") ?? "[]") ?? [];

// Set states from localstorage
setCollaborationId(collabId);
setMatchedUser(matchedUser);
setCurrentUser(currentUser);
setMatchedTopics(matchedTopics);
setQuestionDocRefId(questionDocRefId);
setSubmissionHiddenTestResultsAndStatus(submissionHiddenTestResultsAndStatus);
setVisibleTestCases(visibleTestCases);

GetSingleQuestion(questionDocRefId).then((data: Question) => {
setQuestionTitle(`${data.id}. ${data.title}`);
Expand All @@ -298,9 +309,11 @@ export default function CollaborationPage(props: CollaborationProps) {
setDescription(data.description);
});

GetVisibleTests(questionDocRefId).then((data: Test[]) => {
setVisibleTestCases(data);
});
if (visibleTestCases.length == 0) {
GetVisibleTests(questionDocRefId).then((data: Test[]) => {
setVisibleTestCases(data);
});
}

// Start stopwatch
startStopwatch();
Expand Down Expand Up @@ -384,6 +397,8 @@ export default function CollaborationPage(props: CollaborationProps) {
localStorage.removeItem("collabId");
localStorage.removeItem("questionDocRefId");
localStorage.removeItem("matchedTopics");
localStorage.removeItem("submissionHiddenTestResultsAndStatus");
localStorage.removeItem("visibleTestResults");
};

return (
Expand Down
Loading