Skip to content

Commit c5b39bc

Browse files
committed
feat: add pagination on studio pages
1 parent dfb4055 commit c5b39bc

File tree

9 files changed

+83
-19
lines changed

9 files changed

+83
-19
lines changed

apps/polyflix/public/locales/en/studio.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"global": "Something went wrong, please try again later"
3131
},
3232
"informations": {
33-
"publish": "published by"
33+
"publish": "published by",
34+
"rowsPerPage": "Rows per page"
3435
}
3536
},
3637
"quizzes": {

apps/polyflix/public/locales/fr/studio.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"global": "Quelque chose a mal tourné, veuillez réessayer plus tard"
3131
},
3232
"informations": {
33-
"publish": "publié par"
33+
"publish": "publié par",
34+
"rowsPerPage": "Élements par page"
3435
}
3536
},
3637
"quizzes": {

apps/polyflix/src/modules/studio/components/ghost-list.component.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import {
1212
Stack,
1313
} from '@mui/material'
1414

15-
export const GhostList = () => {
16-
const skeletons = buildSkeletons(5)
15+
export const GhostList = ({
16+
skeletonsNumber = 5,
17+
}: {
18+
skeletonsNumber?: number
19+
}) => {
20+
const skeletons = buildSkeletons(skeletonsNumber)
1721
return (
1822
<List component={Stack} direction="column" gap={1}>
1923
{skeletons.map((_, i: number) => (

apps/polyflix/src/modules/studio/pages/courses/courses-list.page.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ListItemText,
1212
Paper,
1313
Stack,
14+
TablePagination,
1415
} from '@mui/material'
1516
import { Header } from '../../components/header.component'
1617
import { GhostList } from '../../components/ghost-list.component'
@@ -20,11 +21,14 @@ import { Icon } from '@core/components/Icon/Icon.component'
2021
import { useGetCoursesQuery } from '@courses/services/course.service'
2122
import { polyflixRouter } from '@core/utils/routes'
2223
import { useTranslation } from 'react-i18next'
24+
import { useState } from 'react'
2325

2426
export const CoursesListPage = () => {
27+
const [page, setPage] = useState(1)
28+
const [pageSize, setPageSize] = useState(5)
2529
const { data, isLoading, isFetching, isError } = useGetCoursesQuery({
26-
page: 1,
27-
pageSize: 5,
30+
page,
31+
pageSize,
2832
})
2933

3034
const { PopOver, onClick, handleClose, outputData } = usePopOverModal()
@@ -33,7 +37,7 @@ export const CoursesListPage = () => {
3337

3438
const content = () => {
3539
if (isLoading || isFetching) {
36-
return <GhostList />
40+
return <GhostList skeletonsNumber={pageSize} />
3741
}
3842

3943
if (isError) {
@@ -125,6 +129,16 @@ export const CoursesListPage = () => {
125129
description={t('courses.description')}
126130
/>
127131
{content()}
132+
<TablePagination
133+
component="div"
134+
count={data?.total || 0}
135+
page={page - 1}
136+
onPageChange={(e, newPage) => setPage(newPage + 1)}
137+
rowsPerPage={pageSize}
138+
onRowsPerPageChange={(e) => setPageSize(Number(e.target.value))}
139+
rowsPerPageOptions={[5, 10, 25, 50, 100]}
140+
labelRowsPerPage={t('common.informations.rowsPerPage')}
141+
/>
128142
</Box>
129143
)
130144
}

apps/polyflix/src/modules/studio/pages/quizzes/quizzes-list.page.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ListItemText,
1212
Paper,
1313
Stack,
14+
TablePagination,
1415
} from '@mui/material'
1516
import { Header } from '../../components/header.component'
1617
import { GhostList } from '../../components/ghost-list.component'
@@ -20,11 +21,14 @@ import { Icon } from '@core/components/Icon/Icon.component'
2021
import { useGetQuizzesQuery } from '@quizzes/services/quizz.service'
2122
import { polyflixRouter } from '@core/utils/routes'
2223
import { useTranslation } from 'react-i18next'
24+
import { useState } from 'react'
2325

2426
export const QuizzesListPage = () => {
27+
const [page, setPage] = useState(1)
28+
const [pageSize, setPageSize] = useState(5)
2529
const { data, isLoading, isFetching, isError } = useGetQuizzesQuery({
26-
page: 1,
27-
pageSize: 5,
30+
page,
31+
pageSize,
2832
})
2933

3034
const { PopOver, onClick, handleClose, outputData } = usePopOverModal()
@@ -33,7 +37,7 @@ export const QuizzesListPage = () => {
3337

3438
const content = () => {
3539
if (isLoading || isFetching) {
36-
return <GhostList />
40+
return <GhostList skeletonsNumber={pageSize} />
3741
}
3842

3943
if (isError) {
@@ -125,6 +129,16 @@ export const QuizzesListPage = () => {
125129
description={t('videos.description')}
126130
/>
127131
{content()}
132+
<TablePagination
133+
component="div"
134+
count={data?.total || 0}
135+
page={page - 1}
136+
onPageChange={(e, newPage) => setPage(newPage + 1)}
137+
rowsPerPage={pageSize}
138+
onRowsPerPageChange={(e) => setPageSize(Number(e.target.value))}
139+
rowsPerPageOptions={[5, 10, 25, 50, 100]}
140+
labelRowsPerPage={t('common.informations.rowsPerPage')}
141+
/>
128142
</Box>
129143
)
130144
}

apps/polyflix/src/modules/studio/pages/users/users-list.page.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ListItemText,
1111
Paper,
1212
Stack,
13+
TablePagination,
1314
Tooltip,
1415
Typography,
1516
} from '@mui/material'
@@ -23,11 +24,14 @@ import { useTranslation } from 'react-i18next'
2324
import { useGetUsersQuery } from '@users/services/user.service'
2425
import { User } from '@users/models/user.model'
2526
import { UserAvatar } from '@users/components/UserAvatar/UserAvatar.component'
27+
import { useState } from 'react'
2628

2729
export const UsersListPage = () => {
30+
const [page, setPage] = useState(1)
31+
const [pageSize, setPageSize] = useState(5)
2832
const { data, isLoading, isFetching, isError } = useGetUsersQuery({
29-
page: 1,
30-
pageSize: 5,
33+
page,
34+
pageSize,
3135
})
3236

3337
const { PopOver, onClick, handleClose, outputData } = usePopOverModal()
@@ -36,7 +40,7 @@ export const UsersListPage = () => {
3640

3741
const content = () => {
3842
if (isLoading || isFetching) {
39-
return <GhostList />
43+
return <GhostList skeletonsNumber={pageSize} />
4044
}
4145

4246
if (isError) {
@@ -156,6 +160,16 @@ export const UsersListPage = () => {
156160
createAvailable={false}
157161
/>
158162
{content()}
163+
<TablePagination
164+
component="div"
165+
count={data?.totalElements || 0}
166+
page={page - 1}
167+
onPageChange={(e, newPage) => setPage(newPage + 1)}
168+
rowsPerPage={pageSize}
169+
onRowsPerPageChange={(e) => setPageSize(Number(e.target.value))}
170+
rowsPerPageOptions={[5, 10, 25, 50, 100]}
171+
labelRowsPerPage={t('common.informations.rowsPerPage')}
172+
/>
159173
</Box>
160174
)
161175
}

apps/polyflix/src/modules/studio/pages/videos/videos-list.page.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ListItemText,
1212
Paper,
1313
Stack,
14+
TablePagination,
1415
Tooltip,
1516
Typography,
1617
} from '@mui/material'
@@ -25,11 +26,14 @@ import { useTranslation } from 'react-i18next'
2526
import { ImageCover } from '@core/components/ImageCover/image-cover.component'
2627
import { Video } from '@videos/models/video.model'
2728
import { abbreviateNumber } from 'js-abbreviation-number'
29+
import { useState } from 'react'
2830

2931
export const VideosListPage = () => {
32+
const [page, setPage] = useState(1)
33+
const [pageSize, setPageSize] = useState(5)
3034
const { data, isLoading, isFetching, isError } = useGetVideosQuery({
31-
page: 1,
32-
pageSize: 5,
35+
page,
36+
pageSize,
3337
})
3438

3539
const { PopOver, onClick, handleClose, outputData } = usePopOverModal()
@@ -38,7 +42,7 @@ export const VideosListPage = () => {
3842

3943
const content = () => {
4044
if (isLoading || isFetching) {
41-
return <GhostList />
45+
return <GhostList skeletonsNumber={pageSize} />
4246
}
4347

4448
if (isError) {
@@ -173,6 +177,16 @@ export const VideosListPage = () => {
173177
>
174178
<Header title={t('videos.title')} description={t('videos.description')} />
175179
{content()}
180+
<TablePagination
181+
component="div"
182+
count={data?.totalCount || 0}
183+
page={page - 1}
184+
onPageChange={(e, newPage) => setPage(newPage + 1)}
185+
rowsPerPage={pageSize}
186+
onRowsPerPageChange={(e) => setPageSize(Number(e.target.value))}
187+
rowsPerPageOptions={[5, 10, 25, 50, 100]}
188+
labelRowsPerPage={t('common.informations.rowsPerPage')}
189+
/>
176190
</Box>
177191
)
178192
}

packages/mock-server/fixtures/course.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CourseMock implements Mock {
4343
const { models } = (schema as any).courses.all();
4444
return {
4545
data: models.slice(0, pageSize ?? 100),
46-
totalCount: models.length,
46+
total: models.length,
4747
};
4848
});
4949

packages/mock-server/fixtures/user.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ export class UserMock implements Mock {
2929
}
3030

3131
routes(server: Server<AnyRegistry>): void {
32-
server.get("users", (schema) => {
32+
server.get("users", (schema, request) => {
33+
const { size: pageSize } = request.queryParams;
34+
3335
const { models } = (schema as any).users.all();
3436
return {
3537
currentPage: 0,
36-
data: models,
38+
data: models.slice(0, pageSize ?? 100),
3739
totalElements: models.length,
3840
totalPages: 1,
3941
};

0 commit comments

Comments
 (0)