Skip to content

Commit 637437f

Browse files
RichDom2185leeyi45chownces
authored
Migrate to Redux Toolkit part 7 (#2971)
* Migrate `evalStory` handler to Stories Saga * Add Redux utils Originally done in f1cf593. Amended to fix some bugs with types. --------- Co-authored-by: Lee Yi <[email protected]> * Migrate some stories actions to use helper Type errors will be fixed later. * Migrate more stories actions to use helper * Fix old reducer/actions helper compatibility issues * Migrate new stories users handler to BackendSaga Done to align with where the action creator is located. * Migrate StoriesSaga to use helper Original implementation in bbf4f09. Adapted to match current state of codebase. --------- Co-authored-by: Lee Yi <[email protected]> * Fix tests * Fix compile errors Also added a TODO for a testing util. * Remove unnecessary rootReducer creator * Fix combineSagaHandlers * Migrate SessionActions to use helper Some are left unmigrated to preserve the readability of the diff. * Remove old session types * Update tests and non-related sagas Only updated sagas that require a simple fix of the imported action types. Remaining sagas will be done in a later commit. * Fix SessionActions compatibility with ActionsHelper * Comment out most of mock backend saga To minimise potentially unnecessary development effort while pending removal decision outcome. Only commented handlers that are incompatible with the type changes. * Fix SessionReducer tests * Use action creator in components Use the action creator instead of creating the action object manually to enforce abstraction. * Migrate BackendSaga to use new helpers Intentionally done in a very specific way, mixing new and old code styles, in order to keep the diff legible for such a large migration. Further refactoring will be done in the future. * Update backend saga tests * Remove duplicate action types * Migrate mock backend to RTK action types --------- Co-authored-by: Lee Yi <[email protected]> Co-authored-by: En Rong <[email protected]>
1 parent 8d77eb0 commit 637437f

26 files changed

+1273
-1630
lines changed

src/commons/achievement/AchievementOverview.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect } from 'react';
22
import { useDispatch } from 'react-redux';
33
import { AchievementUser } from 'src/features/achievement/AchievementTypes';
44

5-
import { FETCH_TOTAL_XP, FETCH_TOTAL_XP_ADMIN } from '../application/types/SessionTypes';
5+
import { fetchTotalXp, fetchTotalXpAdmin } from '../application/actions/SessionActions';
66
import { useTypedSelector } from '../utils/Hooks';
77
import AchievementLevel from './overview/AchievementLevel';
88

@@ -20,9 +20,9 @@ const AchievementOverview: React.FC<Props> = ({ name, userState }) => {
2020
useEffect(() => {
2121
// If user is student, fetch assessment details from assessment route instead, as seen below
2222
if (crid && crid !== userCrid) {
23-
dispatch({ type: FETCH_TOTAL_XP_ADMIN, payload: crid });
23+
dispatch(fetchTotalXpAdmin(crid));
2424
} else {
25-
dispatch({ type: FETCH_TOTAL_XP });
25+
dispatch(fetchTotalXp());
2626
}
2727
}, [crid, userCrid, dispatch]);
2828

src/commons/achievement/AchievementView.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import {
99
getAbilityGlow
1010
} from '../../features/achievement/AchievementConstants';
1111
import { AchievementStatus, AchievementUser } from '../../features/achievement/AchievementTypes';
12-
import { FETCH_ASSESSMENT, FETCH_ASSESSMENT_ADMIN } from '../application/types/SessionTypes';
13-
import { Assessment, FETCH_ASSESSMENT_OVERVIEWS } from '../assessment/AssessmentTypes';
12+
import {
13+
fetchAssessment,
14+
fetchAssessmentAdmin,
15+
fetchAssessmentOverviews
16+
} from '../application/actions/SessionActions';
17+
import { Assessment } from '../assessment/AssessmentTypes';
1418
import { useTypedSelector } from '../utils/Hooks';
1519
import AchievementCommentCard from './AchievementCommentCard';
1620
import { prettifyDate } from './utils/DateHelper';
@@ -36,16 +40,17 @@ const AchievementView: React.FC<Props> = ({ focusUuid, userState }) => {
3640

3741
const dispatch = useDispatch();
3842
useEffect(() => {
39-
dispatch({ type: FETCH_ASSESSMENT_OVERVIEWS });
43+
dispatch(fetchAssessmentOverviews());
4044
if (!assessmentId) {
4145
return;
4246
}
4347
if (isAdminView) {
4448
// Fetch selected user's assessment from admin route
45-
dispatch({ type: FETCH_ASSESSMENT_ADMIN, payload: { assessmentId, courseRegId } });
49+
// Safe to use non-null assertion (refer to `isAdminView` declaration above)
50+
dispatch(fetchAssessmentAdmin(assessmentId, courseRegId!));
4651
} else {
4752
// If user is student, fetch assessment details from assessment route instead, as seen below
48-
dispatch({ type: FETCH_ASSESSMENT, payload: { assessmentId } });
53+
dispatch(fetchAssessment(assessmentId));
4954
}
5055
}, [dispatch, assessmentId, courseRegId, isAdminView]);
5156

0 commit comments

Comments
 (0)