From 105546f5448964f8c978d9c17dc39eb01b26b61b Mon Sep 17 00:00:00 2001 From: Richard Dominick <34370238+RichDom2185@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:20:46 +0800 Subject: [PATCH] fix: achievements loading and assessment workspace 404 (#3073) * Fix achievement inferencer memoization It was previously not reupdating properly when new data is fetched from the backend. * Fix errorneous 404 on individual assessments --- src/commons/assessmentWorkspace/AssessmentWorkspace.tsx | 7 ++++--- src/pages/achievement/control/AchievementControl.tsx | 7 +------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/commons/assessmentWorkspace/AssessmentWorkspace.tsx b/src/commons/assessmentWorkspace/AssessmentWorkspace.tsx index bb5b9b79a8..adbe92f7de 100644 --- a/src/commons/assessmentWorkspace/AssessmentWorkspace.tsx +++ b/src/commons/assessmentWorkspace/AssessmentWorkspace.tsx @@ -191,9 +191,10 @@ const AssessmentWorkspace: React.FC = props => { }, []); useEffect(() => { - handleTeamOverviewFetch(props.assessmentId); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + if (assessmentOverview && assessmentOverview.maxTeamSize > 1) { + handleTeamOverviewFetch(props.assessmentId); + } + }, [assessmentOverview, handleTeamOverviewFetch, props.assessmentId]); /** * After mounting (either an older copy of the assessment diff --git a/src/pages/achievement/control/AchievementControl.tsx b/src/pages/achievement/control/AchievementControl.tsx index caf60cfa54..581d9974a4 100644 --- a/src/pages/achievement/control/AchievementControl.tsx +++ b/src/pages/achievement/control/AchievementControl.tsx @@ -35,18 +35,13 @@ const AchievementControl: React.FC = () => { [dispatch] ); - // TODO: This is a hacky fix. By right, we shouldn't need to use an - // inferencer instance since we can encapsulate the logic using hooks - // and component state. const [initialAchievements, initialGoals] = useTypedSelector(state => [ state.achievement.achievements, state.achievement.goals ]); const inferencer = useMemo( () => new AchievementInferencer(initialAchievements, initialGoals), - // We only want to create the inferencer once - // eslint-disable-next-line react-hooks/exhaustive-deps - [] + [initialAchievements, initialGoals] ); /**