From 908f63557ca03a1da8b16809ffa2c3acd782d94e Mon Sep 17 00:00:00 2001 From: sct Date: Fri, 18 Dec 2020 06:14:41 +0000 Subject: [PATCH] feat(holiday): special seasonal slider added to discover :) --- src/components/Discover/Holiday/index.tsx | 70 +++++++++++++++++++++++ src/components/Discover/index.tsx | 57 ++++++++++++++++++ src/pages/discover/holiday.tsx | 9 +++ 3 files changed, 136 insertions(+) create mode 100644 src/components/Discover/Holiday/index.tsx create mode 100644 src/pages/discover/holiday.tsx diff --git a/src/components/Discover/Holiday/index.tsx b/src/components/Discover/Holiday/index.tsx new file mode 100644 index 000000000..319101946 --- /dev/null +++ b/src/components/Discover/Holiday/index.tsx @@ -0,0 +1,70 @@ +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 Header from '../../Common/Header'; + +interface SearchResult { + page: number; + totalResults: number; + totalPages: number; + results: MovieResult[]; +} + +const Holiday: React.FC = () => { + const { locale } = useContext(LanguageContext); + const { data, error, size, setSize } = useSWRInfinite( + (pageIndex: number, previousPageData: SearchResult | null) => { + if (previousPageData && pageIndex + 1 > previousPageData.totalPages) { + return null; + } + + return `/api/v1/discover/keyword/207317/movies?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
{error}
; + } + + 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 ( + <> +
Happy Holidays!
+ 0) + } + isReachingEnd={isReachingEnd} + onScrollBottom={fetchMore} + /> + + ); +}; + +export default Holiday; diff --git a/src/components/Discover/index.tsx b/src/components/Discover/index.tsx index 895237c74..7790150f9 100644 --- a/src/components/Discover/index.tsx +++ b/src/components/Discover/index.tsx @@ -63,6 +63,12 @@ const Discover: React.FC = () => { } = useSWR( `/api/v1/discover/movies/upcoming?language=${locale}` ); + const { + data: holUpcomingData, + error: holUpcomingError, + } = useSWR( + `/api/v1/discover/keyword/207317/movies?language=${locale}` + ); const { data: trendingData, error: trendingError } = useSWR( `/api/v1/discover/trending?language=${locale}` @@ -140,6 +146,57 @@ const Discover: React.FC = () => { placeholder={} emptyMessage={intl.formatMessage(messages.nopending)} /> + {/* Special Temporary Slider */} + + ( + + ))} + /> + {/* End Special Temporary Slider */}
diff --git a/src/pages/discover/holiday.tsx b/src/pages/discover/holiday.tsx new file mode 100644 index 000000000..3123acb80 --- /dev/null +++ b/src/pages/discover/holiday.tsx @@ -0,0 +1,9 @@ +import React from 'react'; +import { NextPage } from 'next'; +import Holiday from '../../components/Discover/Holiday'; + +const HolidayPage: NextPage = () => { + return ; +}; + +export default HolidayPage;