|
|
@ -45,13 +45,14 @@ export const Search: Component = () => {
|
|
|
|
return new Error(`The provided filter \`${filter}\` is invalid`);
|
|
|
|
return new Error(`The provided filter \`${filter}\` is invalid`);
|
|
|
|
}, [filter]);
|
|
|
|
}, [filter]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const canSearch = !(!!invalidQuery || !!invalidFilter);
|
|
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
data,
|
|
|
|
data,
|
|
|
|
error: fetchError,
|
|
|
|
error: fetchError,
|
|
|
|
fetchNextPage,
|
|
|
|
fetchNextPage,
|
|
|
|
// hasNextPage,
|
|
|
|
|
|
|
|
refetch,
|
|
|
|
refetch,
|
|
|
|
isFetching,
|
|
|
|
isPending,
|
|
|
|
isFetchingNextPage
|
|
|
|
isFetchingNextPage
|
|
|
|
} = useInfiniteQuery({
|
|
|
|
} = useInfiniteQuery({
|
|
|
|
queryKey: ["search", query, filter],
|
|
|
|
queryKey: ["search", query, filter],
|
|
|
@ -61,12 +62,12 @@ export const Search: Component = () => {
|
|
|
|
type: filter
|
|
|
|
type: filter
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
enabled: !!invalidQuery || !!invalidFilter,
|
|
|
|
enabled: canSearch,
|
|
|
|
initialPageParam: "",
|
|
|
|
initialPageParam: "",
|
|
|
|
getNextPageParam: (lastPage) => lastPage.nextCursor
|
|
|
|
getNextPageParam: (lastPage) => lastPage.nextCursor
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const error = invalidQuery ?? invalidFilter ?? fetchError ?? undefined;
|
|
|
|
const error = invalidFilter ?? fetchError ?? undefined;
|
|
|
|
|
|
|
|
|
|
|
|
const searchFor = useSearch();
|
|
|
|
const searchFor = useSearch();
|
|
|
|
|
|
|
|
|
|
|
@ -84,6 +85,13 @@ export const Search: Component = () => {
|
|
|
|
[isFetchingNextPage, fetchNextPage]
|
|
|
|
[isFetchingNextPage, fetchNextPage]
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const hasLoadedData =
|
|
|
|
|
|
|
|
canSearch && data?.pages.flat().length
|
|
|
|
|
|
|
|
? data?.pages.flat().length !== 0
|
|
|
|
|
|
|
|
: false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isLoadingInitialData = canSearch && !isFetchingNextPage && isPending;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<>
|
|
|
|
<Container>
|
|
|
|
<Container>
|
|
|
@ -91,12 +99,13 @@ export const Search: Component = () => {
|
|
|
|
<div className="flex-1">
|
|
|
|
<div className="flex-1">
|
|
|
|
<SearchInput initialQueryValue={query ?? undefined} />
|
|
|
|
<SearchInput initialQueryValue={query ?? undefined} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{canSearch && (
|
|
|
|
<Filter filter={filter} setFilter={setFilter} />
|
|
|
|
<div>
|
|
|
|
</div>
|
|
|
|
<Filter filter={filter} setFilter={setFilter} />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<Spacer y={4} />
|
|
|
|
{isLoadingInitialData && <LoadingPage />}
|
|
|
|
{isFetching && !error && <LoadingPage />}
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
{error && (
|
|
|
|
<div className="flex-1 flex items-center justify-center">
|
|
|
|
<div className="flex-1 flex items-center justify-center">
|
|
|
|
<div className="text-center">
|
|
|
|
<div className="text-center">
|
|
|
@ -111,32 +120,34 @@ export const Search: Component = () => {
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
)}
|
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
{hasLoadedData && (
|
|
|
|
{!error &&
|
|
|
|
<>
|
|
|
|
data?.pages.map((page, i) => {
|
|
|
|
<div className="flex flex-col gap-4 mt-4">
|
|
|
|
return (
|
|
|
|
{data?.pages.map((page, i) => {
|
|
|
|
<Fragment key={i}>
|
|
|
|
return (
|
|
|
|
{page.items.map((result) => {
|
|
|
|
<Fragment key={i}>
|
|
|
|
switch (result.type) {
|
|
|
|
{page.items.map((result) => {
|
|
|
|
case "channel":
|
|
|
|
switch (result.type) {
|
|
|
|
return <Channel key={result.id} data={result} />;
|
|
|
|
case "channel":
|
|
|
|
|
|
|
|
return <Channel key={result.id} data={result} />;
|
|
|
|
case "video":
|
|
|
|
|
|
|
|
return <Video key={result.id} data={result} />;
|
|
|
|
case "video":
|
|
|
|
|
|
|
|
return <Video key={result.id} data={result} />;
|
|
|
|
case "playlist":
|
|
|
|
|
|
|
|
return <Playlist key={result.id} data={result} />;
|
|
|
|
case "playlist":
|
|
|
|
}
|
|
|
|
return <Playlist key={result.id} data={result} />;
|
|
|
|
})}
|
|
|
|
}
|
|
|
|
</Fragment>
|
|
|
|
})}
|
|
|
|
);
|
|
|
|
</Fragment>
|
|
|
|
})}
|
|
|
|
);
|
|
|
|
|
|
|
|
})}
|
|
|
|
<Loading
|
|
|
|
</div>
|
|
|
|
isFetching={isFetchingNextPage}
|
|
|
|
<Loading
|
|
|
|
onVisible={handleUserReachedPageEnd}
|
|
|
|
isFetching={isFetchingNextPage && !isPending}
|
|
|
|
/>
|
|
|
|
onVisible={handleUserReachedPageEnd}
|
|
|
|
</div>
|
|
|
|
/>
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
|
|
|
)}
|
|
|
|
</Container>
|
|
|
|
</Container>
|
|
|
|
</>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
);
|
|
|
|