11import 'vite/modulepreload-polyfill'
22import { useState , useEffect } from 'react'
3- import { Grid , Box , Link , Button , IconButton , Dialog , Paper , Switch , TableContainer , Table , TableHead , TableRow , TableBody , TableCell } from '@mui/material'
3+ import Grid from '@mui/material/Grid' ;
4+ import Box from '@mui/material/Box' ;
5+ import Link from '@mui/material/Link' ;
6+ import Button from '@mui/material/Button' ;
7+ import IconButton from '@mui/material/IconButton' ;
8+ import Dialog from '@mui/material/Dialog' ;
9+ import LinearProgress from '@mui/material/LinearProgress' ;
10+ import Paper from '@mui/material/Paper' ;
11+ import Switch from '@mui/material/Switch' ;
12+ import TableContainer from '@mui/material/TableContainer' ;
13+ import Table from '@mui/material/Table' ;
14+ import TableHead from '@mui/material/TableHead' ;
15+ import TableRow from '@mui/material/TableRow' ;
16+ import TableBody from '@mui/material/TableBody' ;
17+ import TableCell from '@mui/material/TableCell' ;
418import Base from '../../src/components/Base.jsx'
5- import CourseForm from './components/CourseForm.jsx' ;
619import FilterListIcon from '@mui/icons-material/FilterList' ;
720import SchoolIcon from '@mui/icons-material/School' ;
821import DeleteIcon from '@mui/icons-material/Delete' ;
922import EditIcon from '@mui/icons-material/Edit' ;
1023import render from '../../src/render.jsx' ;
1124import { getCookie } from '../../src/utils.js' ;
12- import EnableCourseSwitchPopup from './components/EnableCourseSwitchPopup.jsx' ;
13- import DeleteCoursePopup from './components/DeleteCoursePopup.jsx' ;
1425import FilterForm from './components/FilterForm.jsx' ;
26+ import { lazy , Suspense } from "react" ;
27+
28+ const CourseForm = lazy ( ( ) => import ( "./components/CourseForm.jsx" ) ) ;
29+ const EnableCourseSwitchPopup = lazy ( ( ) => import ( "./components/EnableCourseSwitchPopup.jsx" ) ) ;
30+ const DeleteCoursePopup = lazy ( ( ) => import ( "./components/DeleteCoursePopup.jsx" ) ) ;
31+
1532
1633
1734function Courses ( ) {
@@ -62,7 +79,7 @@ function Courses() {
6279 console . log ( `${ action } course with ID:` , courseId ) ;
6380 console . log ( 'Event:' , event . target . checked ) ;
6481 setDialogContent ( < Grid sx = { { p : 2 } } >
65- < EnableCourseSwitchPopup courseId = { courseId } action = { action } courseTitle = { courseTitle } handleClose = { ( ) => setDialogOpen ( false ) } handleSuccess = { updateCourseState } />
82+ < Suspense fallback = { < Box sx = { { p : 2 } } > < LinearProgress /> </ Box > } > < EnableCourseSwitchPopup courseId = { courseId } action = { action } courseTitle = { courseTitle } handleClose = { ( ) => setDialogOpen ( false ) } handleSuccess = { updateCourseState } /> </ Suspense >
6683 </ Grid > ) ;
6784 setDialogOpen ( true ) ;
6885 }
@@ -78,7 +95,7 @@ function Courses() {
7895 } ;
7996
8097 const showEditCourseDialog = ( course ) => {
81- setDialogContent ( < CourseForm
98+ setDialogContent ( < Suspense fallback = { < Box sx = { { p : 2 } } > < LinearProgress /> </ Box > } > < CourseForm
8299 successCallback = { ( data ) => {
83100 const index = courses . findIndex ( item => item . id === course . id ) ;
84101 courses [ index ] = data ;
@@ -92,7 +109,7 @@ function Courses() {
92109 activeOrganizationId = { organizationId }
93110 createMode = { false }
94111 courseId = { course . id }
95- /> ) ;
112+ /> </ Suspense > ) ;
96113 setDialogOpen ( true ) ;
97114 }
98115
@@ -108,13 +125,13 @@ function Courses() {
108125 < Grid size = { { xs : 12 , md : 9 } } py = { 2 } pl = { 2 } >
109126 < Box p = { 2 } sx = { { border : '1px solid' , borderColor : 'border.main' , backgroundColor : 'background.main' , borderRadius : 1 , minHeight : 300 } } >
110127 { userRole !== 'viewer' && < Button variant = "contained" startIcon = { < SchoolIcon sx = { { marginLeft : direction === 'rtl' ? 1 : 0 } } /> } sx = { { marginBottom : 2 } } onClick = { ( ) => {
111- setDialogContent ( < CourseForm
128+ setDialogContent ( < Suspense fallback = { < Box sx = { { p : 2 } } > < LinearProgress /> </ Box > } > < CourseForm
112129 successCallback = { handleCourseCreated }
113130 failureCallback = { handleCourseCreationFailed }
114131 cancelCallback = { ( ) => setDialogOpen ( false ) }
115132 activeOrganizationId = { organizationId }
116133 createMode = { true }
117- /> ) ;
134+ /> </ Suspense > ) ;
118135 setDialogOpen ( true ) ; } } > { localeMessages [ "add_course" ] } </ Button > }
119136 < TableContainer component = { Paper } >
120137 < Table sx = { { width : "100%" } } aria-label = { localeMessages [ "courses" ] } >
@@ -148,10 +165,10 @@ function Courses() {
148165 < IconButton onClick = { ( ) => {
149166 showEditCourseDialog ( course ) ; } } > < EditIcon fontSize = "small" /> </ IconButton >
150167 < IconButton aria-label = { `Delete ${ course . title } ` } onClick = { ( ) => {
151- setDialogContent ( < DeleteCoursePopup courseId = { course . id } courseTitle = { course . title } handleClose = { ( ) => setDialogOpen ( false ) } handleSuccess = { ( ) => {
168+ setDialogContent ( < Suspense fallback = { < Box sx = { { p : 2 } } > < LinearProgress /> </ Box > } > < DeleteCoursePopup courseId = { course . id } courseTitle = { course . title } handleClose = { ( ) => setDialogOpen ( false ) } handleSuccess = { ( ) => {
152169 const index = courses . findIndex ( item => item . id === course . id ) ;
153170 setCourses ( courses . filter ( ( _ , i ) => i !== index ) ) ;
154- } } /> ) ;
171+ } } /> </ Suspense > ) ;
155172 setDialogOpen ( true ) ;
156173 } } > < DeleteIcon fontSize = "small" /> </ IconButton >
157174 </ TableCell > }
@@ -163,7 +180,7 @@ function Courses() {
163180 </ Box >
164181 </ Grid >
165182 < Grid display = { { xs : "none" , md : "block" } } size = { { md : 3 } } p = { 2 } >
166- < Box p = { 2 } sx = { { border : '1px solid' , borderColor : 'border.main' , borderRadius : 1 , minHeight : 300 , position : 'sticky' , top : 80 , backgroundColor : 'background.main' } } >
183+ < Box p = { 2 } sx = { { border : '1px solid' , borderColor : 'border.main' , borderRadius : 1 , minHeight : 300 , position : 'sticky' , top : 85 , backgroundColor : 'background.main' } } >
167184 < FilterForm onStatusChange = { ( params ) => setQueryParameters ( params ) } />
168185 </ Box >
169186 </ Grid >
0 commit comments