Skip to content

update session details with latest course information before switchin… #3083

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

C-likethis123
Copy link

@C-likethis123 C-likethis123 commented Jan 30, 2025

…g courses

Description

Fixes the bug where switching courses redirects the user to the 'game' page, even when games are not enabled for the course.

The reason for this bug is because the loader function at src/pages/academy/academyRoutes checks for the enableGame flag in the Redux store before deciding whether to redirect, but the enableGame flag value belongs to the previous course and not the course it's about to switch to. The solution adopted in this MR is to update the latest viewed course to the course that the user is about to navigate to, before actually navigating to that course.

Screen.Recording.2025-01-31.at.12.30.06.AM.mov

Closes #3040.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

  1. Course configuration: create two courses - one with games enabled and one without games enabled.
  2. Switch to the other course using the 'My courses' dropdown - it should redirect to the games page if the course has games enabled, and to the missions page otherwise.

Checklist

  • I have tested this code
  • I have updated the documentation

@coveralls
Copy link

coveralls commented Jan 30, 2025

Pull Request Test Coverage Report for Build 14180292581

Details

  • 6 of 7 (85.71%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 31.116%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/commons/dropdown/DropdownCourses.tsx 6 7 85.71%
Files with Coverage Reduction New Missed Lines %
src/commons/dropdown/DropdownCourses.tsx 1 61.11%
Totals Coverage Status
Change from base Build 14178090272: 0.02%
Covered Lines: 4893
Relevant Lines: 14832

💛 - Coveralls

@C-likethis123 C-likethis123 force-pushed the fix-switching-courses-bug branch from 987e9ba to e4e3749 Compare February 9, 2025 13:56
@C-likethis123 C-likethis123 self-assigned this Feb 9, 2025
@C-likethis123
Copy link
Author

Hi @RichDom2185, can you review this again? Thank you!

const onChangeHandler = (e: React.ChangeEvent<HTMLSelectElement>) => {
navigate(`/courses/${e.currentTarget.value}`);
const onChangeHandler = async (e: React.ChangeEvent<HTMLSelectElement>) => {
await dispatch(SessionActions.updateLatestViewedCourse(Number(e.currentTarget.value)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I don't think you can await a dispatch call? We should be handling the async logic via sagas instead.

What was the idea behind this change?

Copy link
Author

@C-likethis123 C-likethis123 Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @RichDom2185, thank you for the feedback and sorry for the late reply.

I agree that the logic is odd - here's my reasoning behind the change:

  1. when switching between courses, the router uses enableGame from the state of the current course to decide whether to route to the game page, or to route to another page.
  2. this enableGame state is based on the current course, not the course that the user wants to navigate to.
  3. the state is only updated via an API call after the routing logic kicks in and the user finishes navigation to a page.
  4. the idea behind awaiting the dispatch call is to update the state of the latest viewed course to the course that I am trying to navigate to, before the routing logic kicks in

I can try to explore handling the async logic via sagas, but another suggestion from me is to enforce a navigation to a page that is common among all courses (eg the home page) so we don't have to use this conditional logic.

@RichDom2185 RichDom2185 enabled auto-merge (squash) March 31, 2025 20:01
@RichDom2185 RichDom2185 disabled auto-merge March 31, 2025 20:02
@RichDom2185 RichDom2185 requested a review from sayomaki March 31, 2025 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switching to course as an admin bring to game page, even when game is not enabled
3 participants