From 58f5e9ff79086fb7719d9d12711494eaafa8bcaf Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 27 Apr 2024 22:14:42 +0200 Subject: [PATCH] Add retry logic to existing error handling --- src/components/tracker/TrackManga.tsx | 11 +++++++++-- src/components/tracker/TrackerSearch.tsx | 4 ++++ src/screens/Migrate.tsx | 22 ++++++++++++++++++++-- src/screens/Migration.tsx | 11 +++++++++-- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/components/tracker/TrackManga.tsx b/src/components/tracker/TrackManga.tsx index 6326e35c..f4437808 100644 --- a/src/components/tracker/TrackManga.tsx +++ b/src/components/tracker/TrackManga.tsx @@ -18,6 +18,7 @@ import { Trackers } from '@/lib/data/Trackers.ts'; import { TrackerCard, TrackerMode } from '@/components/tracker/TrackerCard.tsx'; import { TManga } from '@/typings.ts'; import { makeToast } from '@/components/util/Toast.tsx'; +import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; const getTrackerMode = (id: number, trackersInUse: number[], searchModeForTracker?: number): TrackerMode => { if (id === searchModeForTracker) { @@ -37,7 +38,7 @@ export const TrackManga = ({ manga }: { manga: Pick(); - const trackerList = requestManager.useGetTrackerList(); + const trackerList = requestManager.useGetTrackerList({ notifyOnNetworkStatusChange: true }); const mangaTrackers = manga.trackRecords.nodes; const loggedInTrackers = Trackers.getLoggedIn(trackerList.data?.trackers.nodes ?? []); @@ -79,7 +80,13 @@ export const TrackManga = ({ manga }: { manga: Pick; + return ( + trackerList.refetch().catch(defaultPromiseErrorHandler('TrackManga::refetch'))} + /> + ); } if (trackerList.loading) { diff --git a/src/components/tracker/TrackerSearch.tsx b/src/components/tracker/TrackerSearch.tsx index 8db77025..4aade758 100644 --- a/src/components/tracker/TrackerSearch.tsx +++ b/src/components/tracker/TrackerSearch.tsx @@ -25,6 +25,7 @@ import { makeToast } from '@/components/util/Toast.tsx'; import { TrackerMangaCard } from '@/components/tracker/TrackerMangaCard.tsx'; import { DIALOG_PADDING } from '@/components/tracker/constants.ts'; import { getOptionForDirection } from '@/theme.ts'; +import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; export const TrackerSearch = ({ mangaId, @@ -114,6 +115,9 @@ export const TrackerSearch = ({ + trackerSearch.refetch().catch(defaultPromiseErrorHandler('TrackerSearch::refetch')) + } /> )} diff --git a/src/screens/Migrate.tsx b/src/screens/Migrate.tsx index cc6f857e..9ae10e01 100644 --- a/src/screens/Migrate.tsx +++ b/src/screens/Migrate.tsx @@ -20,6 +20,7 @@ import { TPartialManga } from '@/typings.ts'; import { GridLayouts } from '@/components/source/GridLayouts.tsx'; import { useLocalStorage } from '@/util/useStorage.tsx'; import { GridLayout } from '@/components/context/LibraryOptionsContext.tsx'; +import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; export const Migrate = () => { const { t } = useTranslation(); @@ -46,7 +47,8 @@ export const Migrate = () => { data: migratableSourceData, loading: isSourceLoading, error: sourceError, - } = requestManager.useGetSource(paramSourceId, { skip: !!isKnownSource }); + refetch: refetchSource, + } = requestManager.useGetSource(paramSourceId, { skip: !!isKnownSource, notifyOnNetworkStatusChange: true }); const { sourceId, name } = { sourceId: paramSourceId, @@ -59,8 +61,10 @@ export const Migrate = () => { data: migratableSourceMangasData, loading: areMangasLoading, error: mangasError, + refetch: refetchMangas, } = requestManager.useGetMigratableSourceMangas(sourceId, { skip: !isKnownSource, + notifyOnNetworkStatusChange: true, }); useEffect(() => { @@ -94,7 +98,21 @@ export const Migrate = () => { const hasError = hasErrorSource || mangasError; if (hasError) { const error = (hasErrorSource ? sourceError : mangasError)!; - return ; + return ( + { + if (hasErrorSource) { + refetchSource().catch(defaultPromiseErrorHandler('Migrate::refetchSource')); + } + + if (mangasError) { + refetchMangas().catch(defaultPromiseErrorHandler('Migrate::refetchMangas')); + } + }} + /> + ); } return ( diff --git a/src/screens/Migration.tsx b/src/screens/Migration.tsx index 84daaa1d..b34fb822 100644 --- a/src/screens/Migration.tsx +++ b/src/screens/Migration.tsx @@ -15,6 +15,7 @@ import { EmptyView } from '@/components/util/EmptyView.tsx'; import { GetMigratableSourcesQuery } from '@/lib/graphql/generated/graphql.ts'; import { MigrationCard, TMigratableSource } from '@/components/MigrationCard.tsx'; import { StyledGroupItemWrapper } from '@/components/virtuoso/StyledGroupItemWrapper.tsx'; +import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; type TMigratableSourcesResult = GetMigratableSourcesQuery['mangas']['nodes']; type TMigratableSources = Record; @@ -43,7 +44,7 @@ const getMigratableSources = (mangas?: TMigratableSourcesResult): TMigratableSou export const Migration = () => { const { t } = useTranslation(); - const { data, loading, error } = requestManager.useGetMigratableSources({ + const { data, loading, error, refetch } = requestManager.useGetMigratableSources({ notifyOnNetworkStatusChange: true, }); const migratableSources = useMemo(() => getMigratableSources(data?.mangas.nodes), [data?.mangas.nodes]); @@ -53,7 +54,13 @@ export const Migration = () => { } if (error) { - return ; + return ( + refetch().catch(defaultPromiseErrorHandler('Migration::refetch'))} + /> + ); } return (