fix(my-classes): add selectedInstituteId to fetch dependency, silence unhandled rejection
Re-fetch classes when NeoInstitute context changes. Catch fetchMyClasses rejection with logger.warn so unhandled promise rejections don't break the component boundary silently. Use CircularProgress (MUI) for loading skeleton. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ee7d7f7cac
commit
313ab724b8
@ -3,9 +3,19 @@ import { Link } from 'react-router-dom';
|
||||
import { AccessTime, KeyboardArrowRight, MenuBook, People, School } from '@mui/icons-material';
|
||||
import useTimetableStore from '../../stores/timetableStore';
|
||||
import { useUser } from '../../contexts/UserContext';
|
||||
import { useNeoInstitute } from '../../contexts/NeoInstituteContext';
|
||||
import { CircularProgress } from '@mui/material';
|
||||
import { logger } from '../../debugConfig';
|
||||
|
||||
const MyClassesSkeleton = () => (
|
||||
<div className="flex justify-center items-center h-64">
|
||||
<CircularProgress />
|
||||
</div>
|
||||
);
|
||||
|
||||
const MyClassesPage: React.FC = () => {
|
||||
const { profile } = useUser();
|
||||
const { selectedInstituteId } = useNeoInstitute();
|
||||
const {
|
||||
myClasses,
|
||||
classesLoading: myClassesLoading,
|
||||
@ -14,8 +24,16 @@ const MyClassesPage: React.FC = () => {
|
||||
} = useTimetableStore();
|
||||
|
||||
useEffect(() => {
|
||||
fetchMyClasses();
|
||||
}, [fetchMyClasses]);
|
||||
fetchMyClasses().catch((error) =>
|
||||
logger.warn('my-classes', 'Fetch my classes failed', {
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
})
|
||||
);
|
||||
}, [fetchMyClasses, selectedInstituteId]);
|
||||
|
||||
if (myClassesLoading) {
|
||||
return <MyClassesSkeleton />;
|
||||
}
|
||||
|
||||
const getRoleLabel = (role: string) => {
|
||||
switch (role) {
|
||||
@ -36,14 +54,6 @@ const MyClassesPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
if (myClassesLoading) {
|
||||
return (
|
||||
<div className="flex justify-center items-center h-64">
|
||||
<div className="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (myClassesError) {
|
||||
return (
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user