Skip to content

Commit

Permalink
[Class statistics] Fix page crash when opening courses tab before dat…
Browse files Browse the repository at this point in the history
…a has finished loading
  • Loading branch information
joonas-a committed Feb 21, 2025
1 parent a632f37 commit 44a7f8b
Showing 1 changed file with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,41 @@ import { useGetStudyGuidanceGroupPopulationCoursesQuery } from '@/redux/studyGui
import { CoursesTable } from './CoursesTable'

export const CoursesTabContainer = ({ curriculum, includeSubstitutions, students, studyGuidanceGroup, variant }) => {
const { data: studyGuidanceGroupPopulationsCourses, isLoading: coursesAreLoading } =
useGetStudyGuidanceGroupPopulationCoursesQuery({
studentnumberlist: students.map(student => student.studentNumber).sort(),
year: studyGuidanceGroup?.tags?.year,
})
const { data: studyGuidanceGroupPopulationsCourses, isLoading } = useGetStudyGuidanceGroupPopulationCoursesQuery({
studentnumberlist: students.map(student => student.studentNumber).sort(),
year: studyGuidanceGroup?.tags?.year,
})

const { data: populationCourses, pending } = useSelector(state => state?.populationSelectedStudentCourses)
const { data: populationCourses } = useSelector(state => state?.populationSelectedStudentCourses)

const studyGuidanceGroupLoading = isLoading || !curriculum || !students
const loading = !curriculum || !students || !populationCourses

if (variant === 'studyGuidanceGroupPopulation') {
return (
<Tab.Pane loading={coursesAreLoading || !curriculum}>
<CoursesTable
curriculum={curriculum}
includeSubstitutions={includeSubstitutions}
populationCourses={studyGuidanceGroupPopulationsCourses}
students={students}
/>
<Tab.Pane loading={studyGuidanceGroupLoading}>
{!studyGuidanceGroupLoading && (
<CoursesTable
curriculum={curriculum}
includeSubstitutions={includeSubstitutions}
populationCourses={studyGuidanceGroupPopulationsCourses}
students={students}
/>
)}
</Tab.Pane>
)
}

return (
<Tab.Pane loading={pending || !curriculum}>
<CoursesTable
curriculum={curriculum}
includeSubstitutions={includeSubstitutions}
populationCourses={populationCourses}
students={students}
/>
<Tab.Pane loading={loading}>
{!loading && (
<CoursesTable
curriculum={curriculum}
includeSubstitutions={includeSubstitutions}
populationCourses={populationCourses}
students={students}
/>
)}
</Tab.Pane>
)
}

0 comments on commit 44a7f8b

Please sign in to comment.