-
Notifications
You must be signed in to change notification settings - Fork 60
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: Add fetch courses-user endpoints #1303
base: develop
Are you sure you want to change the base?
Conversation
- Updated frontend to call the new GET /courses_user endpoint on the course page. - Added matchers in the coursesSlice to populate state with fetched data. - New getUsersCourses endpoint in API client. Purpose: These changes improve performance by reducing the payload size of the main user endpoint and provides more focused course progress data. To test: Run locally and verify /courses-user endpoint in Chrome devtools Network tab.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@kyleecodes this looks good. I will approve once StoryblokSessionPage and StoryblokCoursePage also have the endpoint called. |
@@ -71,6 +71,10 @@ export default function CoursesPage({ courseStories, conversations, shorts }: Pr | |||
imageAlt: 'alt.personSitting', | |||
}; | |||
|
|||
const { data: userCourses } = useGetUserCoursesQuery(undefined, { |
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.
I would put this query inside a useEffect otherwise it will run on component refresh. https://react.dev/reference/react/useEffect.
@@ -56,7 +57,6 @@ export default function CoursesPage({ courseStories, conversations, shorts }: Pr | |||
const entryPartnerReferral = useTypedSelector((state) => state.user.entryPartnerReferral); | |||
const partnerAccesses = useTypedSelector((state) => state.partnerAccesses); | |||
const partnerAdmin = useTypedSelector((state) => state.partnerAdmin); | |||
const courses = useTypedSelector((state) => state.courses); |
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.
I would continue using the state rather than using the result of the query useGetUserQuery below.
@@ -20,10 +20,10 @@ export const SessionProgressDisplay = (props: SessionProgressDisplayProps) => { | |||
PROGRESS_STATUS.NOT_STARTED, | |||
); | |||
|
|||
const courses = useTypedSelector((state) => state.courses); | |||
const { data: courses } = useGetUserCoursesQuery(undefined); |
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.
Same comment as above!
const isLoggedIn = useTypedSelector((state) => Boolean(state.user.id)); | ||
const [userAccess, setUserAccess] = useState<boolean>(); | ||
const [courseProgress, setCourseProgress] = useState<PROGRESS_STATUS>( | ||
PROGRESS_STATUS.NOT_STARTED, | ||
); | ||
const { data: courses } = useGetUserCoursesQuery(undefined, { |
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.
Same as above!
@@ -88,6 +88,9 @@ const slice = createSlice({ | |||
builder.addMatcher(api.endpoints.startSession.matchFulfilled, (state, { payload }) => { | |||
return mergeUpdatedCourse(state, payload); | |||
}); | |||
builder.addMatcher(api.endpoints.getUserCourses.matchFulfilled, (state, { payload }) => { |
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.
This matcher populates state when the api endpoint is called. This means you don't need ot use the return value of the api call above. Hope that makes sense!
Resolves #1223
What changes did you make and why did you make them?
(Delayed due to NextJS app router migration).
Previously, courses data was fetched as part of the larger
getUser
data payload on every page load viauseTypedSelector
. With this update, it's fetched separately only when needed on course and session pages, via newuseGetUserCoursesQuery
. This PR helps improve performance by reducing payload size of the main user endpoint, and provides a more focused course progress data function.Changelog:
api.tsx
: adds the GET request to the new endpoint courses-user, returns type Courses & generates a useGetUserCoursesQuery hook for components to use.CoursesPage.tsx
: fetches and courses-user data from useGetUserCoursesQuery, with skip condition for logged out users. Processes data the same as previous endpoint.coursesSlice.tsx
: adds new matcher that updates courses state when getUserCourses query is successful.SessioProgressDisplay.tsx
: migrated from useTypedSelector to useGetUserCoursesQuery to track session progress.StoryblokCoursePage.tsx
: similar updates as CoursesPage.tsxStoryblokSessionPage.tsx
: similar updates as CoursesPage.tsxTesting:
To-Do:
course-session-behavior
.Did you run tests? Share screenshot of results:
Unit & integration pass, implementing unit tests for this in a separate issue.
How did you find us? (GitHub, Google search, social media, etc.):
N/A