From 1fa691a0543bd86f8b71d08bf970c75f4f7af0ac Mon Sep 17 00:00:00 2001 From: rgu0114 Date: Thu, 7 Nov 2024 14:21:21 -0500 Subject: [PATCH 1/3] limit the number reads for questions monitoring --- src/components/includes/SessionView.tsx | 43 +++++++++++++++++++++---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/components/includes/SessionView.tsx b/src/components/includes/SessionView.tsx index ce896a8a..ddc96b05 100644 --- a/src/components/includes/SessionView.tsx +++ b/src/components/includes/SessionView.tsx @@ -3,7 +3,6 @@ import React, { useState, useEffect, useCallback } from "react"; import { Icon } from "semantic-ui-react"; import { connect } from "react-redux"; -import { useParams } from "react-router-dom"; import SessionInformationHeader from "./SessionInformationHeader"; import SessionQuestionsContainer from "./SessionQuestionsContainer"; @@ -52,10 +51,6 @@ type AbsentState = { lastAskedQuestion: FireQuestion | null; }; -type RouteParams = { - courseId: string; -}; - const SessionView = ({ course, session, @@ -87,7 +82,6 @@ const SessionView = ({ }); const sessionProfile = useSessionProfile(isTa ? user.userId : undefined, isTa ? session.sessionId : undefined); - const { courseId } = useParams(); const updateSessionProfile = useCallback( (virtualLocation: string) => { @@ -122,6 +116,43 @@ const SessionView = ({ // setPrevQuestSet(new Set(questions.map(q => q.questionId))); }, [questions, user.userId, course.courseId, user.roles, user, session.sessionId]); + /** This useEffect dictates when the TA feedback popup is displayed by monitoring the + * state of the current question. Firebase's [onSnapshot] method is used to monitor any + * changes to the questions collection, and [docChanges] filters this down to the document + * changes since the last snapshot. Then, we call [removeQuestionDisplayFeedback] iff a question was + * both modified and resolved, indicating that the TA has answered a question. !isTa and + * !isProf ensures that this useEffect only runs for students. + */ + // TODO (richardgu): use a Firebase Cloud Function for a server-side trigger in the future + useEffect(() => { + let unsubscribe: () => void; + + if (!isTa && !isProf) { + const questionsRef = firestore.collection("questions").where("sessionId", "==", session.sessionId); + + unsubscribe = questionsRef.onSnapshot((snapshot) => { + // eslint-disable-next-line no-console + console.log("onSnapshot called"); + snapshot.docChanges().forEach((change) => { + const questionData = change.doc.data(); + const questionId = change.doc.id; + + if (change.type === "modified" && questionData.status === "resolved") { + // eslint-disable-next-line no-console + console.log("questionid: ", questionId); + removeQuestionDisplayFeedback(questionId); + } + }); + }); + } + + return () => { + if (unsubscribe) { + unsubscribe(); + } + }; + }, []); + const dismissUndo = () => { if (timeoutId) { clearTimeout(timeoutId); From 07012aca665682edaaebb4277a7ebcb621ebdb33 Mon Sep 17 00:00:00 2001 From: rgu0114 Date: Thu, 7 Nov 2024 14:26:57 -0500 Subject: [PATCH 2/3] remove console logs --- src/components/includes/SessionView.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/includes/SessionView.tsx b/src/components/includes/SessionView.tsx index ddc96b05..1777aa79 100644 --- a/src/components/includes/SessionView.tsx +++ b/src/components/includes/SessionView.tsx @@ -132,14 +132,12 @@ const SessionView = ({ unsubscribe = questionsRef.onSnapshot((snapshot) => { // eslint-disable-next-line no-console - console.log("onSnapshot called"); snapshot.docChanges().forEach((change) => { const questionData = change.doc.data(); const questionId = change.doc.id; if (change.type === "modified" && questionData.status === "resolved") { // eslint-disable-next-line no-console - console.log("questionid: ", questionId); removeQuestionDisplayFeedback(questionId); } }); From 0772b68df8aca083476b27746c0b6c0c15391a2d Mon Sep 17 00:00:00 2001 From: rgu0114 Date: Fri, 8 Nov 2024 17:28:22 -0500 Subject: [PATCH 3/3] fix build issue --- src/components/includes/SessionView.tsx | 2 +- src/components/pages/SplitView.tsx | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/components/includes/SessionView.tsx b/src/components/includes/SessionView.tsx index 1777aa79..3dbca545 100644 --- a/src/components/includes/SessionView.tsx +++ b/src/components/includes/SessionView.tsx @@ -131,7 +131,6 @@ const SessionView = ({ const questionsRef = firestore.collection("questions").where("sessionId", "==", session.sessionId); unsubscribe = questionsRef.onSnapshot((snapshot) => { - // eslint-disable-next-line no-console snapshot.docChanges().forEach((change) => { const questionData = change.doc.data(); const questionId = change.doc.id; @@ -149,6 +148,7 @@ const SessionView = ({ unsubscribe(); } }; + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const dismissUndo = () => { diff --git a/src/components/pages/SplitView.tsx b/src/components/pages/SplitView.tsx index 838a3648..e47418fa 100644 --- a/src/components/pages/SplitView.tsx +++ b/src/components/pages/SplitView.tsx @@ -144,12 +144,10 @@ const SplitView = ({ removeQuestionbyID(firestore, removeQuestionId); }; - // used when a student removes their own question, don't want to dispaly feedback + // used when a student removes their own question, don't want to display feedback const setRemoveQuestionWrapper = (questionId: string | undefined) => { setRemoveQuestionId(questionId); setRemovedQuestionId(questionId); - // eslint-disable-next-line no-console - console.log("split view questionId: ", questionId); }; // used to display feedback to user once question is removed @@ -157,8 +155,6 @@ const SplitView = ({ setRemoveQuestionId(questionId); setDisplayFeedbackPrompt(true); setRemovedQuestionId(questionId); - // eslint-disable-next-line no-console - console.log("split view questionId: ", questionId); }; useEffect(() => {