-
-
Notifications
You must be signed in to change notification settings - Fork 407
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upcoming/trending list views and larger title cards
- Loading branch information
Showing
17 changed files
with
456 additions
and
218 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
|
||
interface HeaderProps { | ||
extraMargin?: number; | ||
} | ||
|
||
const Header: React.FC<HeaderProps> = ({ children, extraMargin = 0 }) => { | ||
return ( | ||
<div className="md:flex md:items-center md:justify-between mt-8 mb-8"> | ||
<div className={`flex-1 min-w-0 mx-${extraMargin}`}> | ||
<h2 className="text-2xl font-bold leading-7 text-cool-gray-100 sm:text-4xl sm:leading-9 truncate sm:overflow-visible"> | ||
<span className="bg-clip-text text-transparent bg-gradient-to-br from-indigo-400 to-purple-400"> | ||
{children} | ||
</span> | ||
</h2> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Header; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useContext } from 'react'; | ||
import { useSWRInfinite } from 'swr'; | ||
import type { | ||
MovieResult, | ||
TvResult, | ||
PersonResult, | ||
} from '../../../server/models/Search'; | ||
import ListView from '../Common/ListView'; | ||
import { LanguageContext } from '../../context/LanguageContext'; | ||
import { defineMessages, FormattedMessage } from 'react-intl'; | ||
import Header from '../Common/Header'; | ||
|
||
const messages = defineMessages({ | ||
trending: 'Trending', | ||
}); | ||
|
||
interface SearchResult { | ||
page: number; | ||
totalResults: number; | ||
totalPages: number; | ||
results: (MovieResult | TvResult | PersonResult)[]; | ||
} | ||
|
||
const Trending: React.FC = () => { | ||
const { locale } = useContext(LanguageContext); | ||
const { data, error, size, setSize } = useSWRInfinite<SearchResult>( | ||
(pageIndex: number, previousPageData: SearchResult | null) => { | ||
if (previousPageData && pageIndex + 1 > previousPageData.totalPages) { | ||
return null; | ||
} | ||
|
||
return `/api/v1/discover/trending?page=${ | ||
pageIndex + 1 | ||
}&language=${locale}`; | ||
}, | ||
{ | ||
initialSize: 3, | ||
} | ||
); | ||
|
||
const isLoadingInitialData = !data && !error; | ||
const isLoadingMore = | ||
isLoadingInitialData || | ||
(size > 0 && data && typeof data[size - 1] === 'undefined'); | ||
|
||
const fetchMore = () => { | ||
setSize(size + 1); | ||
}; | ||
|
||
if (error) { | ||
return <div>{error}</div>; | ||
} | ||
|
||
const titles = data?.reduce( | ||
(a, v) => [...a, ...v.results], | ||
[] as (MovieResult | TvResult | PersonResult)[] | ||
); | ||
|
||
const isEmpty = !isLoadingInitialData && titles?.length === 0; | ||
const isReachingEnd = | ||
isEmpty || (data && data[data.length - 1]?.results.length < 20); | ||
|
||
return ( | ||
<> | ||
<Header> | ||
<FormattedMessage {...messages.trending} /> | ||
</Header> | ||
<ListView | ||
items={titles} | ||
isEmpty={isEmpty} | ||
isLoading={ | ||
isLoadingInitialData || (isLoadingMore && (titles?.length ?? 0) > 0) | ||
} | ||
isReachingEnd={isReachingEnd} | ||
onScrollBottom={fetchMore} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default Trending; |
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,77 @@ | ||
import React, { useContext } from 'react'; | ||
import { useSWRInfinite } from 'swr'; | ||
import type { MovieResult } from '../../../server/models/Search'; | ||
import ListView from '../Common/ListView'; | ||
import { LanguageContext } from '../../context/LanguageContext'; | ||
import { defineMessages, FormattedMessage } from 'react-intl'; | ||
import Header from '../Common/Header'; | ||
|
||
const messages = defineMessages({ | ||
upcomingmovies: 'Upcoming Movies', | ||
}); | ||
|
||
interface SearchResult { | ||
page: number; | ||
totalResults: number; | ||
totalPages: number; | ||
results: MovieResult[]; | ||
} | ||
|
||
const UpcomingMovies: React.FC = () => { | ||
const { locale } = useContext(LanguageContext); | ||
const { data, error, size, setSize } = useSWRInfinite<SearchResult>( | ||
(pageIndex: number, previousPageData: SearchResult | null) => { | ||
if (previousPageData && pageIndex + 1 > previousPageData.totalPages) { | ||
return null; | ||
} | ||
|
||
return `/api/v1/discover/movies/upcoming?page=${ | ||
pageIndex + 1 | ||
}&language=${locale}`; | ||
}, | ||
{ | ||
initialSize: 3, | ||
} | ||
); | ||
|
||
const isLoadingInitialData = !data && !error; | ||
const isLoadingMore = | ||
isLoadingInitialData || | ||
(size > 0 && data && typeof data[size - 1] === 'undefined'); | ||
|
||
const fetchMore = () => { | ||
setSize(size + 1); | ||
}; | ||
|
||
if (error) { | ||
return <div>{error}</div>; | ||
} | ||
|
||
const titles = data?.reduce( | ||
(a, v) => [...a, ...v.results], | ||
[] as MovieResult[] | ||
); | ||
|
||
const isEmpty = !isLoadingInitialData && titles?.length === 0; | ||
const isReachingEnd = | ||
isEmpty || (data && data[data.length - 1]?.results.length < 20); | ||
|
||
return ( | ||
<> | ||
<Header> | ||
<FormattedMessage {...messages.upcomingmovies} /> | ||
</Header> | ||
<ListView | ||
items={titles} | ||
isEmpty={isEmpty} | ||
isLoading={ | ||
isLoadingInitialData || (isLoadingMore && (titles?.length ?? 0) > 0) | ||
} | ||
isReachingEnd={isReachingEnd} | ||
onScrollBottom={fetchMore} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default UpcomingMovies; |
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
Oops, something went wrong.