diff --git a/src/components/marketing/LearningHub/MainVideos.js b/src/components/marketing/LearningHub/MainVideos.js index 18fac09a4..365e016e3 100644 --- a/src/components/marketing/LearningHub/MainVideos.js +++ b/src/components/marketing/LearningHub/MainVideos.js @@ -1,29 +1,71 @@ /** * MUI Imports */ -import { Box, Grid, Typography } from '@mui/material'; +import { + Box, + Grid, + Pagination, + Stack, + ThemeProvider, + Typography, +} from '@mui/material'; import { useTheme } from '@mui/material/styles'; import useMediaQuery from '@mui/material/useMediaQuery'; /** * Components Imports */ - +import VideoCard from './FeaturedCard'; +import { LearningHubVideosContext } from './context/LearningHubVideosContext'; /** * React Imports */ -import { useContext, memo } from 'react'; -import { LearningHubVideosContext } from './context/LearningHubVideosContext'; -import VideoCard from './FeaturedCard'; +import { useContext, memo, useState, useEffect } from 'react'; +import revampTheme from 'theme/revampTheme'; -const MainVideos = () => { +const MainVideos = ({ withPagination = false }) => { const { entities, searchKey } = useContext(LearningHubVideosContext); const theme = useTheme(); const isExtraSmall = useMediaQuery(theme.breakpoints.between('xs', 600)); + const scrollTo = (id) => { + setTimeout(() => { + const element = document.querySelector(`#${id}`); + if (!element) { + return; + } + + window.scrollTo({ + left: 0, + top: element.offsetTop, + behavior: 'smooth', + }); + }); + }; + + // Pagination + const [currentPage, setCurrentPage] = useState(1); + const [postPerPage] = useState(9); + const indexOfLast = currentPage * postPerPage; + const indexOfFirst = indexOfLast - postPerPage; + const pageNum = []; + const videoList = !withPagination + ? entities + : entities.slice(indexOfFirst, indexOfLast); + for (let i = 1; i <= Math.ceil(entities.length / postPerPage); i++) { + pageNum.push(i); + } + const handlePageChange = (_event, value) => { + setCurrentPage(value); + }; + + useEffect(() => { + if (videoList?.length <= postPerPage) setCurrentPage(1); + }, [entities]); return ( <> { {searchKey !== '' ? 'Results' : 'All Videos'} - {entities?.map((item, idx) => { + {videoList?.map((item, idx) => { return ( @@ -63,6 +105,32 @@ const MainVideos = () => { + + {withPagination && videoList?.length ? ( + ({ + [theme.breakpoints.up('xs')]: { + py: 3, + mx: 'auto', + maxWidth: theme.maxWidth, + alignItems: 'center', + }, + })} + > + revampTheme(theme.palette.mode)}> + scrollTo('scrollTop')} + count={pageNum?.length} + page={currentPage} + onChange={handlePageChange} + size={'large'} + color="primary" + /> + + + ) : ( + '' + )} ); }; diff --git a/src/views/zesty/LearningHub.js b/src/views/zesty/LearningHub.js index 20ff5298b..c5858ed63 100644 --- a/src/views/zesty/LearningHub.js +++ b/src/views/zesty/LearningHub.js @@ -56,7 +56,7 @@ function LearningHub({ content }) { - + );