source-academy / frontend

Frontend of Source Academy, an online experiential environment for computational thinking (React, Redux, Saga, Blueprint)
https://sourceacademy.org
Apache License 2.0
103 stars 167 forks source link

Refactor Academy router #2978

Closed RichDom2185 closed 6 months ago

RichDom2185 commented 6 months ago

Description

Please refer to commit history for details.

See #2507 See #2484

TODO:

Type of change

How to test

Everything should still work.

Checklist

coveralls commented 6 months ago

Pull Request Test Coverage Report for Build 8971102719

Details


Changes Missing Coverage Covered Lines Changed/Added Lines %
src/commons/assessment/Assessment.tsx 3 4 75.0%
src/pages/academy/Academy.tsx 0 1 0.0%
src/pages/academy/adminPanel/AdminPanel.tsx 0 2 0.0%
src/pages/academy/dashboard/Dashboard.tsx 0 2 0.0%
src/pages/academy/gameSimulator/GameSimulator.tsx 0 2 0.0%
src/pages/academy/grading/Grading.tsx 0 2 0.0%
src/pages/academy/groundControl/GroundControlContainer.ts 0 2 0.0%
src/pages/academy/notiPreference/NotiPreference.tsx 0 2 0.0%
src/pages/academy/sourcereel/Sourcereel.tsx 0 2 0.0%
src/pages/academy/teamFormation/TeamFormation.tsx 0 2 0.0%
<!-- Total: 22 116 18.97% -->
Files with Coverage Reduction New Missed Lines %
src/pages/academy/Academy.tsx 1 0.0%
src/commons/application/ApplicationWrapper.tsx 2 0.0%
<!-- Total: 3 -->
Totals Coverage Status
Change from base Build 8960018753: -0.08%
Covered Lines: 5004
Relevant Lines: 14643

💛 - Coveralls
RichDom2185 commented 6 months ago

@chownces I've fixed the infinite rerender issue, and also refactored ensureUserAndRole to use GuardedRoute, thereby eliminating the dependency on role. I think in the future we should move towards a static router (thereby removing the need for UPDATE_REACT_ROUTER action) to decrease complexity – just access the store directly via store.getState() within loader functions whenever we need to have dynamic routing logic.

This will reduce the complexity of the implementation.

RichDom2185 commented 6 months ago

There's currently a bug in the academy routes when the route is non-existent. Instead of 404-ing, the page hangs (likely in an infinite loop).

Try something like http://localhost:8000/courses/11/sourcecastt

Somehow the new 404 behaviour seems to be causing the infinite loop. I've restored the original behaviour of rendering <NotFound /> as a catch-all, instead of redirecting first to a /not_found path, then rendering the component there. This fixes the issue.