Skip to content

Commit

Permalink
implementation of finish question as non-answerer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielxue committed Mar 28, 2024
1 parent dc613a9 commit 21a77c5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Button, Modal } from "semantic-ui-react";

interface FinishConfirmModalProps {
onFinish: (forced?: boolean) => void;
onClose: () => void;
open: boolean;
}

const FinishConfirmModal = (props: FinishConfirmModalProps) => {
const { onFinish, onClose, open } = props;

return (
<Modal open={open}>
<Modal.Header>Finish Confirmation</Modal.Header>
<Modal.Content>
<Modal.Description>
You are about to finish a question that you did not start.
Is this intended?
</Modal.Description>
</Modal.Content>
<Modal.Actions>
<Button content="Cancel" onClick={onClose} />
<Button
content="Finish"
loading={false}
color="green"
onClick={() => onFinish(true)}
/>
</Modal.Actions>
</Modal>
);
};

export default FinishConfirmModal;
44 changes: 28 additions & 16 deletions frontend/components/Course/InstructorQueuePage/QuestionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import RejectQuestionModal from "./RejectQuestionModal";
import { AuthUserContext } from "../../../context/auth";
import { Question, QuestionStatus, User } from "../../../types";
import MessageQuestionModal from "./MessageQuestionModal";
import FinishConfirmModal from "./FinishConfirmModal";
import LinkedText from "../../common/ui/LinkedText";

export const fullName = (user: User) => `${user.firstName} ${user.lastName}`;
Expand All @@ -24,6 +25,7 @@ interface QuestionCardProps {
notifs: boolean;
setNotifs: (boolean) => void;
}

const QuestionCard = (props: QuestionCardProps) => {
const { question, mutate: mutateQuestion, notifs, setNotifs } = props;
const { id: questionId, askedBy } = question;
Expand All @@ -36,6 +38,7 @@ const QuestionCard = (props: QuestionCardProps) => {

const [open, setOpen] = useState(false);
const [messageModalOpen, setMessageModalOpen] = useState(false);
const [finishConfirmModalOpen, setFinishConfirmModalOpen] = useState(false);

// save notification preference for when an instructor answers a question
const [lastNotif, setLastNotif] = useState(notifs);
Expand All @@ -57,9 +60,15 @@ const QuestionCard = (props: QuestionCardProps) => {
await mutateQuestion(questionId, { status: QuestionStatus.ACTIVE });
};

const onFinish = async () => {
setNotifs(lastNotif); // resets notification preference when finished answering question
await mutateQuestion(questionId, { status: QuestionStatus.ANSWERED });
const onFinish = async (forced?: boolean) => {
if (question.respondedToBy?.username === user.username || forced) {
setNotifs(lastNotif); // resets notification preference when finished answering question
await mutateQuestion(questionId, {
status: QuestionStatus.ANSWERED,
});
} else {
setFinishConfirmModalOpen(true);
}
};

const onUndo = async () => {
Expand Down Expand Up @@ -94,6 +103,11 @@ const QuestionCard = (props: QuestionCardProps) => {
closeFunc={() => setMessageModalOpen(false)}
mutate={mutateQuestion}
/>
<FinishConfirmModal
open={finishConfirmModalOpen}
onFinish={onFinish}
onClose={() => setMessageModalOpen(false)}
/>
<Segment attached="top" color="blue" clearing>
<div
style={{
Expand Down Expand Up @@ -239,19 +253,17 @@ const QuestionCard = (props: QuestionCardProps) => {
/>
)}
{/* if response started, then some user responded */}
{question.timeResponseStarted &&
question.respondedToBy!.username ===
user.username && (
<Button
compact
size="mini"
color="green"
content="Finish"
disabled={isLoading()}
onClick={onFinish}
loading={false}
/>
)}
{question.timeResponseStarted && (
<Button
compact
size="mini"
color="green"
content="Finish"
disabled={isLoading()}
onClick={() => onFinish()}
loading={false}
/>
)}
{question.timeResponseStarted &&
question.videoChatUrl && (
<a
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/courses/[course]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const QueuePage = (props: QueuePageProps) => {
url="/api/ws/subscribe/"
findOrigin={
process.env.NODE_ENV === "development"
? () => "ws://localhost:8000"
? () => "ws://127.0.0.1:8000"
: undefined
}
>
Expand Down

0 comments on commit 21a77c5

Please sign in to comment.