52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
import Head from 'next/head'
|
|
import { useRouter } from 'next/router'
|
|
import { useState } from 'react'
|
|
import useSWR from 'swr'
|
|
import CollectionSearch from '../../components/CollectionSearch'
|
|
import Loading from '../../components/Loading'
|
|
import PageTitle from '../../components/PageTitle'
|
|
import PaginationImproved from '../../components/PaginationImproved'
|
|
import SearchBar from '../../components/SearchBar'
|
|
import { getUrl, movieUpcoming } from '../../lib/tmdb'
|
|
import { fetcher, pathToSearchMovie } from '../../utils'
|
|
|
|
export default function UpcomingMovies() {
|
|
const router = useRouter()
|
|
const { page } = router.query
|
|
const [currentPage, setCurrentPage] = useState(Number(page))
|
|
const url = getUrl(movieUpcoming) + `&page=${currentPage}`
|
|
const { data, error } = useSWR(url, fetcher)
|
|
const isFirst = currentPage === 1
|
|
const isLast = data ? currentPage === data.total_pages : false
|
|
|
|
return (
|
|
<div>
|
|
<Head>
|
|
<title>Upcoming Movies | Watcho</title>
|
|
</Head>
|
|
<SearchBar
|
|
placeholder='Search for movies'
|
|
searchPath={pathToSearchMovie}
|
|
/>
|
|
<PageTitle title='upcoming movies' />
|
|
{data ? (
|
|
<>
|
|
<CollectionSearch isGenre arr={data.results} />
|
|
<PaginationImproved
|
|
currentPageAdvance={currentPage + 1}
|
|
currentPage={currentPage}
|
|
prevHref={`/movie/upcoming?page=${currentPage - 1}`}
|
|
nextHref={`/movie/upcoming?page=${currentPage + 1}`}
|
|
isFirst={isFirst}
|
|
isLast={isLast}
|
|
goToPreviousPage={() => setCurrentPage(currentPage - 1)}
|
|
goToNextPage={() => setCurrentPage(currentPage + 1)}
|
|
totalPages={data.total_pages}
|
|
/>
|
|
</>
|
|
) : (
|
|
<Loading />
|
|
)}
|
|
</div>
|
|
)
|
|
}
|