Skip to content

Commit 420d6f0

Browse files
fix: populate the learning module state after fetching
1 parent 96e991c commit 420d6f0

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/components/sections/learning-modules/InteractiveModule/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import { authCheck } from "@/store/feature/auth.slice";
1111
import { Course, InteractiveModule as InteractiveModuleType } from "@/types/course";
1212
import { hidePageNavigation, showPageNavigation } from "@/store/feature/communities/navigation.slice";
1313
import { checkAnswer } from "@/store/feature/learningModules.slice";
14-
import { IRootState } from "@/store";
1514
import { submitModuleAnswer } from "@/store/services/learningModules.service";
15+
import { IRootState } from "@/store";
1616

1717
/**
1818
* interface for InteractiveModule multiSelector

src/pages/communities/[slug]/challenges/[challenge_id]/learning-modules/[id].tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import PageNavigation from "@/components/sections/courses/PageNavigation";
2424
import ChallengeCard from "@/components/cards/challenge/Challenge";
2525
import { useTranslation } from "next-i18next";
2626

27-
2827
/**
2928
* Learning module page props interfae
3029
* @date 4/24/2023 - 8:36:15 PM

src/store/services/learningModules.service.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createApi } from "@reduxjs/toolkit/query/react";
22
import baseQuery from "@/config/baseQuery";
3+
import { setCurrentLearningModule, setLearningModuleList } from "../feature/learningModules.slice";
34

45
/**
56
* Learning module api service
@@ -19,6 +20,10 @@ export const learningModulesService = createApi({
1920
"accept-language": locale,
2021
},
2122
}),
23+
onQueryStarted: async (_, { dispatch, queryFulfilled }) => {
24+
const { data } = await queryFulfilled;
25+
dispatch(setCurrentLearningModule(data));
26+
},
2227
}),
2328

2429
getAllLearningModules: builder.query({
@@ -28,6 +33,10 @@ export const learningModulesService = createApi({
2833
"accept-language": locale,
2934
},
3035
}),
36+
onQueryStarted: async (_, { dispatch, queryFulfilled }) => {
37+
const { data } = await queryFulfilled;
38+
dispatch(setLearningModuleList(data));
39+
},
3140
}),
3241

3342
submitModuleAnswer: builder.query({

0 commit comments

Comments
 (0)