Skip to content

Commit

Permalink
feat: update redux state
Browse files Browse the repository at this point in the history
  • Loading branch information
varshamenon4 committed Jul 6, 2023
1 parent 27be673 commit d7d864b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/pages/ExamsPage/components/ExamSelection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import {
} from '@edx/paragon';
import PropTypes from 'prop-types';

// todo: implement substring search
// const searchByExamName = (exams, examName) => {
// const isMatchingExam = (exam) => exam === examName;
// const match = exams.filter(isMatchingExam);
// console.log('log');
// };

const updateCurrentExamIndex = (exam) => 'hello';

const ExamSelection = ({ exams }) => (
<div data-testid="exam_selection">
<SelectMenu defaultMessage="Select an exam...">
<MenuItem as={SearchField} />
{exams.map(exam => (
<MenuItem>{exam.name}</MenuItem>
// todo: update redux state
<MenuItem onClick={() => console.log(exam.id)}>{exam.name}</MenuItem>
))}
</SelectMenu>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/pages/ExamsPage/data/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ const slice = createSlice({
}
)),
}),
// todo: setCurrentExam
loadCurrentExamIndex: (state, { payload }) => ({
...state,
currentExamIndex: 1,
}),
},
});

export const {
loadExams,
loadExamAttempts,
loadCurrentExamIndex,
} = slice.actions;

export const {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/ExamsPage/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ export const useInitializeExamsPage = (courseId) => {
export const useExamsData = () => {
const [exampleValue, setExampleValue] = state.exampleValue(0);
const examsList = useSelector(selectors.courseExamsList);
const currentExam = useSelector(selectors.currentExam);
// todo: add setter here
const [currentExam, setCurrentExam] = useSelector(selectors.currentExam);
const isLoading = reduxHooks.useRequestIsPending(RequestKeys.fetchCourseExams);

return {
currentExam,
setCurrentExam,
examsList,
isLoading,
exampleValue,
Expand Down

0 comments on commit d7d864b

Please sign in to comment.