-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add trending section and page (#36)
- Loading branch information
Showing
22 changed files
with
341 additions
and
81 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
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
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 was deleted.
Oops, something went wrong.
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
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
46 changes: 46 additions & 0 deletions
46
src/features/shows/features/trending/components/page/TrendingContent.tsx
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,46 @@ | ||
import { useCallback, useContext, useEffect, useRef } from 'react'; | ||
import { Box } from '@mui/material'; | ||
import TrendingUpIcon from '@mui/icons-material/TrendingUp'; | ||
import { TrendingContext } from '../../contexts/TrendingContext'; | ||
import Section from '../../../../../../components/Section'; | ||
import ShowsCollection from '../../../../components/ShowsCollection'; | ||
|
||
const TrendingContent = () => { | ||
const { shows, loading, fetchNextPage } = useContext(TrendingContext); | ||
const loader = useRef(null); | ||
|
||
const handleObserver = useCallback( | ||
([target]) => { | ||
if (target.isIntersecting && !loading) { | ||
fetchNextPage(); | ||
} | ||
}, | ||
[fetchNextPage, loading], | ||
); | ||
|
||
useEffect(() => { | ||
const observer = new IntersectionObserver(handleObserver, { | ||
root: null, | ||
rootMargin: '1px', | ||
threshold: 0, | ||
}); | ||
|
||
if (loader.current) observer.observe(loader.current); | ||
}, [handleObserver]); | ||
|
||
return ( | ||
<Box> | ||
<Section title="Trending" icon={<TrendingUpIcon />}> | ||
<ShowsCollection | ||
shows={shows} | ||
loading={false} | ||
scroll={false} | ||
loadingIndicator={loading} | ||
/> | ||
</Section> | ||
<div ref={loader} /> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default TrendingContent; |
13 changes: 13 additions & 0 deletions
13
src/features/shows/features/trending/components/page/TrendingPage.tsx
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,13 @@ | ||
import TrendingProvider from '../../contexts/TrendingContext'; | ||
import PageWrapper from '../../../../../../components/PageWrapper'; | ||
import TrendingContent from './TrendingContent'; | ||
|
||
const TrendingPage = () => ( | ||
<PageWrapper> | ||
<TrendingProvider> | ||
<TrendingContent /> | ||
</TrendingProvider> | ||
</PageWrapper> | ||
); | ||
|
||
export default TrendingPage; |
10 changes: 10 additions & 0 deletions
10
src/features/shows/features/trending/components/section/Trending.tsx
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,10 @@ | ||
import TrendingProvider from '../../contexts/TrendingContext'; | ||
import TrendingSection from './TrendingSection'; | ||
|
||
const Trending = () => ( | ||
<TrendingProvider> | ||
<TrendingSection /> | ||
</TrendingProvider> | ||
); | ||
|
||
export default Trending; |
17 changes: 17 additions & 0 deletions
17
src/features/shows/features/trending/components/section/TrendingSection.tsx
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,17 @@ | ||
import { useContext } from 'react'; | ||
import TrendingUpIcon from '@mui/icons-material/TrendingUp'; | ||
import { TrendingContext } from '../../contexts/TrendingContext'; | ||
import Section from '../../../../../../components/Section'; | ||
import ShowsCollection from '../../../../components/ShowsCollection'; | ||
|
||
const TrendingSection = () => { | ||
const { shows, loading } = useContext(TrendingContext); | ||
|
||
return ( | ||
<Section title="Trending" icon={<TrendingUpIcon />}> | ||
<ShowsCollection shows={shows} loading={loading} scroll /> | ||
</Section> | ||
); | ||
}; | ||
|
||
export default TrendingSection; |
Oops, something went wrong.