-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat: refactor non instruction components #132
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
/* eslint-disable react-hooks/exhaustive-deps */ | ||
import React, { useContext, useEffect, useState } from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import { injectIntl, intlShape, FormattedMessage } from '@edx/frontend-platform/i18n'; | ||
import { Alert, Spinner } from '@edx/paragon'; | ||
import { Info } from '@edx/paragon/icons'; | ||
import { ExamTimerBlock } from '../timer'; | ||
import Instructions from '../instructions'; | ||
import ExamStateContext from '../context'; | ||
import ExamAPIError from './ExamAPIError'; | ||
import { ExamStatus, ExamType } from '../constants'; | ||
import { ExamStatus, ExamType, IS_STARTED_STATUS } from '../constants'; | ||
import messages from './messages'; | ||
import { getProctoringSettings } from '../data'; | ||
|
||
/** | ||
* Exam component is intended to render exam instructions before and after exam. | ||
|
@@ -23,10 +23,12 @@ import messages from './messages'; | |
const Exam = ({ | ||
isGated, isTimeLimited, originalUserIsStaff, canAccessProctoredExams, children, intl, | ||
}) => { | ||
const state = useContext(ExamStateContext); | ||
const { | ||
isLoading, showTimer, exam, apiErrorMsg, getProctoringSettings, | ||
} = state; | ||
isLoading, activeAttempt, exam, apiErrorMsg, | ||
} = useSelector(state => state.specialExams); | ||
const dispatch = useDispatch(); | ||
|
||
const showTimer = !!(activeAttempt && IS_STARTED_STATUS(activeAttempt.attempt_status)); | ||
|
||
const { | ||
attempt, | ||
|
@@ -59,7 +61,7 @@ const Exam = ({ | |
if (proctoredExamTypes.includes(examType)) { | ||
// only fetch proctoring settings for a proctored exam | ||
if (examId) { | ||
getProctoringSettings(); | ||
dispatch(getProctoringSettings()); | ||
} | ||
|
||
// Only exclude Timed Exam when restricting access to exams | ||
|
@@ -68,7 +70,8 @@ const Exam = ({ | |
// this makes sure useEffect gets called only one time after the exam has been fetched | ||
// we can't leave this empty since initially exam is just an empty object, so | ||
// API calls above would not get triggered | ||
}, [examId]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [examId, dispatch]); | ||
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. [question] I noticed this in a couple of places. Could you clarify the need for this / if this will eventually be unnecessary? 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. This lint rule is meant to try and prevent developers from forgetting dependencies in the use effect. Because I didn't change anything within the use effect, I'm planning to leave this as is for now! 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. Should it be removed? I'm wondering if it's complaining because you're using 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. Oh, fair point! I will try adding that in and see what happens. |
||
|
||
if (isLoading) { | ||
return ( | ||
|
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.
Nit. If you wanted to reduce some of the duplication in the definition of
showTimer
, you could put it in a custom hook.