You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.4 KiB
63 lines
1.4 KiB
import { useRouter } from 'next/router';
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
import type {
|
|
MovieResult,
|
|
PersonResult,
|
|
TvResult,
|
|
} from '../../../server/models/Search';
|
|
import useDiscover from '../../hooks/useDiscover';
|
|
import Error from '../../pages/_error';
|
|
import Header from '../Common/Header';
|
|
import ListView from '../Common/ListView';
|
|
import PageTitle from '../Common/PageTitle';
|
|
|
|
const messages = defineMessages({
|
|
search: 'Search',
|
|
searchresults: 'Search Results',
|
|
});
|
|
|
|
const Search = () => {
|
|
const intl = useIntl();
|
|
const router = useRouter();
|
|
|
|
const {
|
|
isLoadingInitialData,
|
|
isEmpty,
|
|
isLoadingMore,
|
|
isReachingEnd,
|
|
titles,
|
|
fetchMore,
|
|
error,
|
|
} = useDiscover<MovieResult | TvResult | PersonResult>(
|
|
`/api/v1/search`,
|
|
{
|
|
query: router.query.query,
|
|
},
|
|
{ hideAvailable: false }
|
|
);
|
|
|
|
if (error) {
|
|
return <Error statusCode={500} />;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<PageTitle title={intl.formatMessage(messages.search)} />
|
|
<div className="mt-1 mb-5">
|
|
<Header>{intl.formatMessage(messages.searchresults)}</Header>
|
|
</div>
|
|
<ListView
|
|
items={titles}
|
|
isEmpty={isEmpty}
|
|
isLoading={
|
|
isLoadingInitialData || (isLoadingMore && (titles?.length ?? 0) > 0)
|
|
}
|
|
isReachingEnd={isReachingEnd}
|
|
onScrollBottom={fetchMore}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Search;
|