-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(congregations): use pagination when navigating public talks
- Loading branch information
Showing
5 changed files
with
93 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import TablePagination from '@mui/material/TablePagination'; | ||
|
||
const PublicTalkPagination = ({ count, page, handleChangePage, noLabel }) => { | ||
return ( | ||
<TablePagination | ||
component="div" | ||
count={count} | ||
page={page} | ||
labelDisplayedRows={({ from, to, count }) => (noLabel ? '' : `${from}–${to} / ${count}`)} | ||
rowsPerPageOptions={[]} | ||
rowsPerPage={10} | ||
onPageChange={handleChangePage} | ||
showFirstButton={true} | ||
showLastButton={true} | ||
sx={{ '.MuiTablePagination-displayedRows': { fontWeight: 'bold', fontSize: '16px' } }} | ||
/> | ||
); | ||
}; | ||
|
||
export default PublicTalkPagination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as PublicTalkContainer } from './PublicTalkContainer'; | ||
export { default as PublicTalkImport } from './PublicTalkImport'; | ||
export { default as PublicTalkPagination } from './PublicTalkPagination'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,62 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import Box from '@mui/material/Box'; | ||
import Button from '@mui/material/Button'; | ||
import ImportExportIcon from '@mui/icons-material/ImportExport'; | ||
import Typography from '@mui/material/Typography'; | ||
import { publicTalkImportOpenState, publicTalksListState } from '../states/congregation'; | ||
import { PublicTalkContainer, PublicTalkImport } from '../features/publicTalks'; | ||
import { useEffect } from 'react'; | ||
import { PublicTalkContainer, PublicTalkImport, PublicTalkPagination } from '../features/publicTalks'; | ||
import { apiFetchPublicTalks } from '../api/congregation'; | ||
|
||
const PublicTalks = () => { | ||
const { isLoading, data } = useQuery({ | ||
queryKey: ['public_talks'], | ||
queryFn: apiFetchPublicTalks, | ||
staleTime: 60000, | ||
}); | ||
|
||
const [publicTalks, setPublicTalks] = useRecoilState(publicTalksListState); | ||
const [openImport, setOpenImport] = useRecoilState(publicTalkImportOpenState); | ||
|
||
const handleClickOpen = () => { | ||
setOpenImport(true); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!isLoading) setPublicTalks(data); | ||
}, [isLoading, data, setPublicTalks]); | ||
|
||
return ( | ||
<Box> | ||
<Typography variant='h6'>PUBLIC TALKS</Typography> | ||
<Button variant='outlined' startIcon={<ImportExportIcon />} sx={{ marginTop: '20px' }} onClick={handleClickOpen}> | ||
Import JSON | ||
</Button> | ||
|
||
{openImport && <PublicTalkImport />} | ||
|
||
<Box sx={{ margin: '20px 0', maxWidth: '900px', display: 'flex', flexDirection: 'column', gap: '25px' }}> | ||
{publicTalks.map((talk) => ( | ||
<PublicTalkContainer key={talk.talk_number} talk_number={talk.talk_number} /> | ||
))} | ||
<PublicTalkContainer isNew={true} /> | ||
</Box> | ||
</Box> | ||
); | ||
const { isLoading, data } = useQuery({ | ||
queryKey: ['public_talks'], | ||
queryFn: apiFetchPublicTalks, | ||
staleTime: 60000, | ||
}); | ||
|
||
const [publicTalks, setPublicTalks] = useRecoilState(publicTalksListState); | ||
const [openImport, setOpenImport] = useRecoilState(publicTalkImportOpenState); | ||
|
||
const [page, setPage] = useState(0); | ||
|
||
const handleChangePage = (event, newPage) => { | ||
setPage(newPage); | ||
}; | ||
|
||
const handleClickOpen = () => { | ||
setOpenImport(true); | ||
}; | ||
|
||
useEffect(() => { | ||
if (!isLoading) setPublicTalks(data); | ||
}, [isLoading, data, setPublicTalks]); | ||
|
||
return ( | ||
<Box> | ||
<Typography variant="h6">PUBLIC TALKS</Typography> | ||
<Button variant="outlined" startIcon={<ImportExportIcon />} sx={{ marginTop: '20px' }} onClick={handleClickOpen}> | ||
Import JSON | ||
</Button> | ||
|
||
{openImport && <PublicTalkImport />} | ||
|
||
<Box sx={{ margin: '20px 0', maxWidth: '900px', display: 'flex', flexDirection: 'column', gap: '25px' }}> | ||
{publicTalks.length > 0 && ( | ||
<PublicTalkPagination count={publicTalks.length} page={page} handleChangePage={handleChangePage} /> | ||
)} | ||
|
||
{publicTalks.slice(page * 10, page * 10 + 10).map((talk) => ( | ||
<PublicTalkContainer currentPage={page} key={talk.talk_number} talk_number={talk.talk_number} /> | ||
))} | ||
|
||
{publicTalks.length > 0 && ( | ||
<PublicTalkPagination count={publicTalks.length} page={page} handleChangePage={handleChangePage} /> | ||
)} | ||
</Box> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default PublicTalks; |