-
Notifications
You must be signed in to change notification settings - Fork 0
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
Deploy efficient questions monitoring #890
base: release
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<RouteParams>(); | ||
|
||
const updateSessionProfile = useCallback( | ||
(virtualLocation: string) => { | ||
|
@@ -122,6 +116,41 @@ 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) => { | ||
snapshot.docChanges().forEach((change) => { | ||
const questionData = change.doc.data(); | ||
const questionId = change.doc.id; | ||
|
||
if (change.type === "modified" && questionData.status === "resolved") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is only removing the questions whose status are resolved and and has been modified, would it be better to first filter the array of docChanges to keep only those that are modified and whose status is resolved. This may be optimal in cases when docChanges is big, thus we can avoid iterating through each change. |
||
// eslint-disable-next-line no-console | ||
removeQuestionDisplayFeedback(questionId); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
return () => { | ||
if (unsubscribe) { | ||
unsubscribe(); | ||
} | ||
}; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
const dismissUndo = () => { | ||
if (timeoutId) { | ||
clearTimeout(timeoutId); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Richard! I really like your detailed comment on what the useEffect is, it was very helpful in understanding the useEffect! Overall it looks good to me, but I was wondering if it would be a good idea to handle any potential listening errors for onSnapshot?