Use gql for "mangas" III - global search
This commit is contained in:
@@ -21,6 +21,7 @@ import LangSelect from '@/components/navbar/action/LangSelect';
|
||||
import MangaGrid from '@/components/MangaGrid';
|
||||
import NavbarContext from '@/components/context/NavbarContext';
|
||||
import { useDebounce } from '@/components/manga/hooks';
|
||||
import { MangaType } from '@/lib/graphql/generated/graphql.ts';
|
||||
|
||||
type SourceLoadingState = { isLoading: boolean; hasResults: boolean; emptySearch: boolean };
|
||||
type SourceToLoadingStateMap = Map<string, SourceLoadingState>;
|
||||
@@ -99,15 +100,17 @@ const SourceSearchPreview = React.memo(
|
||||
const skipRequest = !searchString;
|
||||
|
||||
const { id, displayName, lang } = source;
|
||||
const {
|
||||
data: searchResult,
|
||||
isLoading,
|
||||
error,
|
||||
abortRequest,
|
||||
} = requestManager.useSourceQuickSearch(id, searchString ?? '', [], 1, { skipRequest });
|
||||
const mangas = !isLoading ? searchResult?.[0]?.mangaList ?? [] : [];
|
||||
const [loadPage, results] = requestManager.useSourceSearch(id, searchString ?? '', []);
|
||||
const { data: searchResult, loading: isLoading, error, abortRequest } = results[0]!;
|
||||
const mangas = (searchResult?.fetchSourceManga.mangas as MangaType[]) ?? [];
|
||||
const noMangasFound = !isLoading && !mangas.length;
|
||||
|
||||
useEffect(() => {
|
||||
if (!skipRequest) {
|
||||
loadPage(1);
|
||||
}
|
||||
}, [skipRequest, searchString]);
|
||||
|
||||
useEffect(() => {
|
||||
onSearchRequestFinished(source, isLoading, !noMangasFound, !searchString);
|
||||
}, [isLoading, noMangasFound, searchString]);
|
||||
|
||||
Reference in New Issue
Block a user