import React, { useRef } from 'react'; import useSWR, { useSWRInfinite } from 'swr'; import type { MovieResult, TvResult } from '../../../server/models/Search'; import TitleCard from '../TitleCard'; import useVerticalScroll from '../../hooks/useVerticalScroll'; interface MovieDiscoverResult { page: number; totalResults: number; totalPages: number; results: MovieResult[]; } interface TvDiscoverResult { page: number; totalResults: number; totalPages: number; results: TvResult[]; } const getKey = ( pageIndex: number, previousPageData: MovieDiscoverResult | null ) => { if (previousPageData && pageIndex + 1 > previousPageData.totalPages) { return null; } return `/api/v1/discover/movies?page=${pageIndex + 1}`; }; const Discover: React.FC = () => { const { data: movieData, error: movieError } = useSWR( '/api/v1/discover/movies' ); const { data: tvData, error: tvError } = useSWR( '/api/v1/discover/tv' ); return ( <>

Popular Movies

{movieData?.results.map((title) => (
))} {!movieData && !movieError && [...Array(10)].map((_item, i) => (
))}

Popular TV Shows

{tvData?.results.map((title) => (
))} {!tvData && !tvError && [...Array(10)].map((_item, i) => (
))}
); }; export default Discover;