Skip to content

Commit

Permalink
Merge pull request #90 from jolynloh/FE/collabPage
Browse files Browse the repository at this point in the history
Fix lint error and minor collab page bugs
  • Loading branch information
nicolelim02 authored Oct 29, 2024
2 parents c269044 + 9c704c2 commit 9aeead1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/CollabSessionControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CollabSessionControls: React.FC = () => {
const [time, setTime] = useState<number>(0);

useEffect(() => {
let intervalId = setInterval(
const intervalId = setInterval(
() => setTime((prevTime) => prevTime + 1),
1000
);
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/contexts/MatchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
const initMatchedListeners = () => {
matchSocket.on(MatchEvents.MATCH_SUCCESSFUL, (id: string) => {
setMatchPending(false);
appNavigate(MatchPaths.COLLAB);
setQuestionId(id);
appNavigate(MatchPaths.COLLAB);
});

matchSocket.on(MatchEvents.MATCH_UNSUCCESSFUL, () => {
Expand All @@ -302,6 +302,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
const initCollabListeners = () => {
matchSocket.on(MatchEvents.MATCH_ENDED, () => {
toast.error(MATCH_ENDED_MESSAGE);
setIsEndSessionModalOpen(false);
appNavigate(MatchPaths.HOME);
});
};
Expand Down Expand Up @@ -501,8 +502,8 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
};

const handleConfirmEndSession = () => {
stopMatch();
setIsEndSessionModalOpen(false);
stopMatch();
};

return (
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/pages/CollabSandbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import {
import classes from "./index.module.css";
import { useMatch } from "../../contexts/MatchContext";
import { USE_MATCH_ERROR_MESSAGE } from "../../utils/constants";
import { useEffect, useReducer } from "react";
import { useEffect, useReducer, useState } from "react";
import Loader from "../../components/Loader";
import ServerError from "../../components/ServerError";
import reducer, {
getQuestionById,
initialState,
} from "../../reducers/questionReducer";
import QuestionDetailComponent from "../../components/QuestionDetail";
import { Navigate } from "react-router-dom";

const CollabSandbox: React.FC = () => {
const [showErrorScreen, setShowErrorScreen] = useState<boolean>(false);

const match = useMatch();
if (!match) {
throw new Error(USE_MATCH_ERROR_MESSAGE);
Expand All @@ -40,6 +43,10 @@ const CollabSandbox: React.FC = () => {
const { selectedQuestion } = state;

useEffect(() => {
if (!partner) {
return;
}

verifyMatchStatus();

if (!questionId) {
Expand All @@ -54,11 +61,29 @@ const CollabSandbox: React.FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
let timeout: number | undefined;

if (!selectedQuestion) {
timeout = setTimeout(() => {
setShowErrorScreen(true);
}, 2000);
} else {
setShowErrorScreen(false);
}

return () => clearTimeout(timeout);
}, [selectedQuestion]);

if (loading) {
return <Loader />;
}

if (!partner || !questionId || !selectedQuestion) {
if (!partner) {
return <Navigate to="/home" replace />;
}

if (showErrorScreen) {
return (
<ServerError
title="Oops, match ended..."
Expand All @@ -67,6 +92,10 @@ const CollabSandbox: React.FC = () => {
);
}

if (!selectedQuestion) {
return <Loader />;
}

return (
<AppMargin classname={`${classes.fullheight} ${classes.flex}`}>
{/* <Stack spacing={2} alignItems={"center"}>
Expand Down

0 comments on commit 9aeead1

Please sign in to comment.