refactoring: server actions data fetching -> api routes
This commit is contained in:
1 parent
1111712d2c
commit
5cbf93b3b8
38 files changed
+326
-308
No files matched your search
@@ -1,22 +1,18 @@
|
||||
import { useRef } from 'react';
|
||||
|
||||
import { search } from '@/api';
|
||||
import searchQuery, { SearchQueryProps } from '@/api/queries/search';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
const useSearch = ({ query, type }: { query: string; type: Show['type'] }) => {
|
||||
const useSearch = (props: SearchQueryProps) => {
|
||||
const previousRef = useRef<Show[]>([]);
|
||||
|
||||
const infiniteQuery = useInfiniteList({
|
||||
queryKey: ['search', query, type],
|
||||
queryFn: ({ page }) => search({ query, page, type }),
|
||||
enabled: Boolean(query)
|
||||
});
|
||||
const infiniteQuery = useInfiniteList(searchQuery(props));
|
||||
|
||||
if (infiniteQuery.isFetched) {
|
||||
previousRef.current = infiniteQuery.shows;
|
||||
}
|
||||
|
||||
if (!query) {
|
||||
if (!props.query) {
|
||||
previousRef.current = [];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user