diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index 5a24ea22..aa3bb1e3 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -669,6 +669,16 @@ export class RequestManager { const { signal, abortRequest } = this.createAbortController(); setAbortRequest(abortRequest); + const isRefetch = newPage === [...cachedPages][cachedPages.size - 1]; + if (isRefetch) { + this.cache.cacheResponse( + cachePagesKey, + getVariablesFor(0), + new Set([...cachedPages].slice(0, cachedPages.size - 1)), + ); + this.cache.clearFor(this.cache.getKeyFor(cacheResultsKey, getVariablesFor(newPage))); + } + setResult({ ...getResultIdInfo(), ...createPaginatedResult({ isLoading: true, abortRequest, size: newPage, called: true }), @@ -689,6 +699,7 @@ export class RequestManager { basePaginatedResult.data = response.data; } catch (error: any) { + defaultPromiseErrorHandler('RequestManager::fetchPaginatedMutationPage')(error); if (error instanceof ApolloError) { basePaginatedResult.error = error; } else { @@ -706,12 +717,9 @@ export class RequestManager { setResult(fetchPaginatedResult); - const shouldCacheResult = !fetchPaginatedResult.error; - if (shouldCacheResult) { - const currentCachedPages = this.cache.getResponseFor>(cachePagesKey, getVariablesFor(0)) ?? []; - this.cache.cacheResponse(cachePagesKey, getVariablesFor(0), new Set([...currentCachedPages, newPage])); - this.cache.cacheResponse(cacheResultsKey, getVariablesFor(newPage), fetchPaginatedResult); - } + const currentCachedPages = this.cache.getResponseFor>(cachePagesKey, getVariablesFor(0)) ?? []; + this.cache.cacheResponse(cachePagesKey, getVariablesFor(0), new Set([...currentCachedPages, newPage])); + this.cache.cacheResponse(cacheResultsKey, getVariablesFor(newPage), fetchPaginatedResult); return response; } diff --git a/src/modules/global-search/screens/SearchAll.tsx b/src/modules/global-search/screens/SearchAll.tsx index dccd02ae..1239e3c5 100644 --- a/src/modules/global-search/screens/SearchAll.tsx +++ b/src/modules/global-search/screens/SearchAll.tsx @@ -114,9 +114,10 @@ const SourceSearchPreview = React.memo( skipRequest: !searchString, addAbortSignal: true, }); + console.log('SearchAll', source.displayName, results); const { data: searchResult, isLoading, error, abortRequest } = results[0]!; const mangas = searchResult?.fetchSourceManga?.mangas ?? []; - const noMangasFound = !isLoading && !mangas.length; + const noMangasFound = !error && !isLoading && !mangas.length; useEffect(() => { onSearchRequestFinished(source, isLoading, !noMangasFound, !searchString); diff --git a/src/modules/source/screens/SourceMangas.tsx b/src/modules/source/screens/SourceMangas.tsx index 9eac6eb3..b5a9e758 100644 --- a/src/modules/source/screens/SourceMangas.tsx +++ b/src/modules/source/screens/SourceMangas.tsx @@ -47,6 +47,9 @@ import { GET_SOURCE_BROWSE } from '@/lib/graphql/queries/SourceQuery.ts'; import { MangaIdInfo } from '@/modules/manga/services/Mangas.ts'; import { TranslationKey } from '@/Base.types.ts'; import { IPos } from '@/modules/source/Source.types.ts'; +import { defaultPromiseErrorHandler } from '@/lib/DefaultPromiseErrorHandler.ts'; +import { EmptyView } from '@/modules/core/components/placeholder/EmptyView.tsx'; +import { EmptyViewAbsoluteCentered } from '@/modules/core/components/placeholder/EmptyViewAbsoluteCentered.tsx'; const ContentTypeMenu = styled('div')(({ theme }) => ({ display: 'flex', @@ -262,8 +265,10 @@ export function SourceMangas() { setLocationContentType(newContentType); }; - const [loadPage, { data, isLoading: loading, size: lastPageNum, abortRequest, filteredOutAllItemsOfFetchedPage }] = - useSourceManga(sourceId, contentType, query, filtersToApply, 1, hideLibraryEntries); + const [ + loadPage, + { data, error, isLoading: loading, size: lastPageNum, abortRequest, filteredOutAllItemsOfFetchedPage }, + ] = useSourceManga(sourceId, contentType, query, filtersToApply, 1, hideLibraryEntries); const isLoading = loading || filteredOutAllItemsOfFetchedPage; const mangas = data?.fetchSourceManga?.mangas ?? []; const hasNextPage = !!data?.fetchSourceManga?.hasNextPage; @@ -454,19 +459,38 @@ export function SourceMangas() { {t('global.button.filter')} - + + {(isLoading || !error || (!!error && !!mangas.length)) && ( + + )} + + {error && !mangas.length && ( + loadPage(lastPageNum).catch(defaultPromiseErrorHandler('SourceMangas::refetch'))} + /> + )} + {error && !!mangas.length && ( + loadPage(lastPageNum).catch(defaultPromiseErrorHandler('SourceMangas::refetch'))} + /> + )} + {contentType === SourceContentType.SEARCH && (