fix: search autocomplete
This commit is contained in:
1 parent
91f8b4fc1e
commit
a747461505
6 files changed
+43
-14
No files matched your search
@@ -22,5 +22,3 @@ export default async function Starring({ searchParams }: { searchParams: Record<
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
export const revalidate = 3600;
|
||||
@@ -7,9 +7,7 @@ const useStarring = ({ actorId }: { actorId?: string }) =>
|
||||
useInfiniteList({
|
||||
queryKey: ['starring', actorId],
|
||||
enabled: Boolean(actorId),
|
||||
queryFn: ({ page }) => {
|
||||
return topMovies({ page, starring: actorId });
|
||||
}
|
||||
queryFn: ({ page }) => topMovies({ page, starring: actorId })
|
||||
});
|
||||
|
||||
export default useStarring;
|
||||
+1
-3
@@ -32,9 +32,7 @@ const RootLayout = ({ children }: { children: ReactNode }) => {
|
||||
</head>
|
||||
<body style={font.style}>
|
||||
<Providers theme={theme}>
|
||||
<div className='sticky top-0 z-20'>
|
||||
<Header />
|
||||
</div>
|
||||
<Header className='sticky top-0 z-20' />
|
||||
<main className='container'>{children}</main>
|
||||
</Providers>
|
||||
</body>
|
||||
|
||||
@@ -17,6 +17,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
const [title, setTitle] = useState('');
|
||||
const scrollRef = useRef<HTMLDivElement>(null) as MutableRefObject<HTMLDivElement>;
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const isFetchedRef = useRef(false);
|
||||
|
||||
const query = useDistinctUntilChanged(title);
|
||||
|
||||
@@ -35,7 +36,13 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
{ title: 'Series', data: series, type: 'tv' as const }
|
||||
].filter(({ data: { shows } }) => shows.length);
|
||||
|
||||
const isFetched = movies.isFetched && series.isFetched;
|
||||
if (!isFetchedRef.current && movies.isFetched && series.isFetched) {
|
||||
isFetchedRef.current = true;
|
||||
}
|
||||
|
||||
if (!query) {
|
||||
isFetchedRef.current = false;
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal className='block max-w-[932px] p-0' onClose={onResolve} scrollRef={scrollRef}>
|
||||
@@ -59,7 +66,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
<XCircle />
|
||||
</Button>
|
||||
</div>
|
||||
{isFetched && (
|
||||
{isFetchedRef.current && (
|
||||
<div className='px-2'>
|
||||
{tabs.length > 1 ? (
|
||||
<Tabs defaultValue='movie'>
|
||||
|
||||
@@ -1,11 +1,29 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
import { search } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
const useSearch = ({ query, type }: { query: string; type: Show['type'] }) =>
|
||||
useInfiniteList({
|
||||
const useSearch = ({ query, type }: { query: string; type: Show['type'] }) => {
|
||||
const previous = useRef<Show[]>([]);
|
||||
|
||||
const infiniteQuery = useInfiniteList({
|
||||
queryKey: ['search', query, type],
|
||||
queryFn: ({ page }) => search({ query, page, type }),
|
||||
enabled: Boolean(query)
|
||||
});
|
||||
|
||||
if (infiniteQuery.isFetched) {
|
||||
previous.current = infiniteQuery.shows;
|
||||
}
|
||||
|
||||
if (!query) {
|
||||
previous.current = [];
|
||||
}
|
||||
|
||||
return {
|
||||
...infiniteQuery,
|
||||
shows: infiniteQuery.isLoading ? previous.current : infiniteQuery.shows
|
||||
};
|
||||
};
|
||||
|
||||
export default useSearch;
|
||||
@@ -2,13 +2,23 @@ import { FC } from 'react';
|
||||
import Link from 'next/link';
|
||||
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
import { DesktopNavigation, MobileNavigation } from './components/Navigation';
|
||||
import ToggleSearch from './components/Search';
|
||||
import ToggleTheme from './components/ThemeToggle';
|
||||
|
||||
const Header: FC = () => (
|
||||
<header className='flex justify-center bg-background/95 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/60'>
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Header: FC<Props> = ({ className }) => (
|
||||
<header
|
||||
className={cn(
|
||||
'flex justify-center bg-background/95 py-2 backdrop-blur supports-[backdrop-filter]:bg-background/60',
|
||||
className
|
||||
)}
|
||||
>
|
||||
<div className='container'>
|
||||
<div className='flex items-center justify-between gap-2 xs:flex-nowrap'>
|
||||
<Link shallow href='/'>
|
||||
|
||||
Reference in new issue
Block a user