Skip to content

Commit

Permalink
Better loading state for the ThesesPage
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksTeresh committed Sep 3, 2024
1 parent 6b07f0e commit 8577cd1
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/client/components/ThesisPage/ThesesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ const ThesesPage = () => {
const [newThesis, setNewThesis] = useState<Thesis | null>(null)
const [showOnlyOwnTheses, setShowOnlyOwnTheses] = useState(true)

const { theses } = useTheses({ onlySupervised: showOnlyOwnTheses })
const { programs } = usePrograms({ includeNotManaged: true })
const { theses, isLoading: isThesesLoading } = useTheses({
onlySupervised: showOnlyOwnTheses,
})
const { programs, isLoading: isProgramLoading } = usePrograms({
includeNotManaged: true,
})
const { mutateAsync: editThesis } = useEditThesisMutation()
const { mutateAsync: deleteThesis } = useDeleteThesisMutation()
const { mutateAsync: createThesis } = useCreateThesisMutation()

if (!programs || !theses || loggedInUserLoading) return null

const columns: GridColDef<Thesis>[] = [
{
field: 'programId',
Expand Down Expand Up @@ -100,6 +102,17 @@ const ThesesPage = () => {
valueGetter: (_, row) => dayjs(row.targetDate).format('YYYY-MM-DD'),
},
]
const skeletonRows: Thesis[] = Array.from({ length: 7 }).map((_, index) => ({
programId: '',
topic: '',
authors: [],
status: 'PLANNING',
startDate: '',
targetDate: '',
supervisions: [],
graders: [],
id: index.toString(),
}))

const initializeNewThesis = () => {
const favoritePrograms = programs.filter((program) => program.isFavorite)
Expand Down Expand Up @@ -157,11 +170,13 @@ const ThesesPage = () => {
setRowSelectionModel([])
}

const isLoading = loggedInUserLoading || isThesesLoading || isProgramLoading
return (
<Stack spacing={3} sx={{ p: '1rem', width: '100%', maxWidth: '1920px' }}>
<Box>
<DataGrid
rows={theses}
loading={isLoading}
rows={isLoading ? skeletonRows : theses}
columns={columns}
initialState={{
pagination: {
Expand Down Expand Up @@ -195,6 +210,10 @@ const ThesesPage = () => {
handleEditThesis: initializeThesisEdit,
handleDeleteThesis: initializeThesisDelete,
},
loadingOverlay: {
variant: 'skeleton',
noRowsVariant: 'skeleton',
},
}}
sx={{
border: 'none',
Expand Down

0 comments on commit 8577cd1

Please sign in to comment.