Add missing error handling

This commit is contained in:
schroda
2024-04-27 22:28:55 +02:00
parent a447719309
commit 773d2b1026
20 changed files with 322 additions and 65 deletions

View File

@@ -7,7 +7,6 @@
*/ */
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import Stack from '@mui/material/Stack'; import Stack from '@mui/material/Stack';
import Tooltip from '@mui/material/Tooltip'; import Tooltip from '@mui/material/Tooltip';
import { styled } from '@mui/material/styles'; import { styled } from '@mui/material/styles';
@@ -36,6 +35,8 @@ import { Chapters } from '@/lib/data/Chapters.ts';
import { ChaptersWithMeta } from '@/lib/data/ChaptersWithMeta.ts'; import { ChaptersWithMeta } from '@/lib/data/ChaptersWithMeta.ts';
import { ChapterActionMenuItems } from '@/components/chapter/ChapterActionMenuItems.tsx'; import { ChapterActionMenuItems } from '@/components/chapter/ChapterActionMenuItems.tsx';
import { ChaptersDownloadActionMenuItems } from '@/components/chapter/ChaptersDownloadActionMenuItems.tsx'; import { ChaptersDownloadActionMenuItems } from '@/components/chapter/ChaptersDownloadActionMenuItems.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
const ChapterListHeader = styled(Stack)(({ theme }) => ({ const ChapterListHeader = styled(Stack)(({ theme }) => ({
margin: 8, margin: 8,
@@ -77,7 +78,12 @@ export const ChapterList: React.FC<IProps> = ({ manga, isRefreshing }) => {
const queue = (downloaderData?.downloadStatus.queue as DownloadType[]) ?? []; const queue = (downloaderData?.downloadStatus.queue as DownloadType[]) ?? [];
const [options, dispatch] = useChapterOptions(manga.id); const [options, dispatch] = useChapterOptions(manga.id);
const { data: chaptersData, loading: isLoading } = requestManager.useGetMangaChapters(manga.id); const {
data: chaptersData,
loading: isLoading,
error,
refetch,
} = requestManager.useGetMangaChapters(manga.id, { notifyOnNetworkStatusChange: true });
const chapters = useMemo(() => chaptersData?.chapters.nodes ?? [], [chaptersData?.chapters.nodes]); const chapters = useMemo(() => chaptersData?.chapters.nodes ?? [], [chaptersData?.chapters.nodes]);
const chapterIds = useMemo(() => chapters.map((chapter) => chapter.id), [chapters]); const chapterIds = useMemo(() => chapters.map((chapter) => chapter.id), [chapters]);
@@ -134,15 +140,21 @@ export const ChapterList: React.FC<IProps> = ({ manga, isRefreshing }) => {
if (isLoading || (noChaptersFound && isRefreshing)) { if (isLoading || (noChaptersFound && isRefreshing)) {
return ( return (
<div <Stack sx={{ justifyContent: 'center', alignItems: 'center', position: 'relative', flexGrow: 1 }}>
style={{ <LoadingPlaceholder />
margin: '10px auto', </Stack>
display: 'flex', );
justifyContent: 'center', }
}}
> if (error) {
<CircularProgress thickness={5} /> return (
</div> <Stack sx={{ justifyContent: 'center', position: 'relative', flexGrow: 1 }}>
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('ChapterList::refetch'))}
/>
</Stack>
); );
} }

View File

@@ -20,6 +20,8 @@ import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarC
import { ActiveDevice, DEFAULT_DEVICE } from '@/util/device.ts'; import { ActiveDevice, DEFAULT_DEVICE } from '@/util/device.ts';
import { Select } from '@/components/atoms/Select.tsx'; import { Select } from '@/components/atoms/Select.tsx';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
export const DeviceSetting = () => { export const DeviceSetting = () => {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -41,6 +43,7 @@ export const DeviceSetting = () => {
metadata, metadata,
settings: { devices }, settings: { devices },
loading, loading,
request: { error, refetch },
} = useMetadataServerSettings(); } = useMetadataServerSettings();
const { activeDevice, setActiveDevice } = useContext(ActiveDevice); const { activeDevice, setActiveDevice } = useContext(ActiveDevice);
@@ -67,6 +70,16 @@ export const DeviceSetting = () => {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('DeviceSetting::refetch'))}
/>
);
}
return ( return (
<List> <List>
<MutableListSetting <MutableListSetting

View File

@@ -11,8 +11,10 @@
import { useMemo } from 'react'; import { useMemo } from 'react';
import Typography from '@mui/material/Typography'; import Typography from '@mui/material/Typography';
import { useTheme } from '@mui/material/styles'; import { useTheme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import useMediaQuery from '@mui/material/useMediaQuery'; import useMediaQuery from '@mui/material/useMediaQuery';
import { useTranslation } from 'react-i18next';
import Button from '@mui/material/Button';
import Stack from '@mui/material/Stack';
const ERROR_FACES = ['(・o・;)', 'Σ(ಠ_ಠ)', 'ಥ_ಥ', '(˘・_・˘)', '(; ̄Д ̄)', '(・Д・。']; const ERROR_FACES = ['(・o・;)', 'Σ(ಠ_ಠ)', 'ಥ_ಥ', '(˘・_・˘)', '(; ̄Д ̄)', '(・Д・。'];
@@ -24,30 +26,34 @@ function getRandomErrorFace() {
interface IProps { interface IProps {
message: string; message: string;
messageExtra?: JSX.Element | string; messageExtra?: JSX.Element | string;
retry?: () => void;
} }
export function EmptyView({ message, messageExtra }: IProps) { export function EmptyView({ message, messageExtra, retry }: IProps) {
const { t } = useTranslation();
const theme = useTheme(); const theme = useTheme();
const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm')); const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm'));
const errorFace = useMemo(() => getRandomErrorFace(), []); const errorFace = useMemo(() => getRandomErrorFace(), []);
return ( return (
<Box <Stack
sx={{ sx={{
position: 'absolute', position: 'absolute',
left: `calc(50% + ${isMobileWidth ? '0px' : theme.spacing(8 / 2)})`, left: `calc(50% + ${isMobileWidth ? '0px' : theme.spacing(8 / 2)})`,
top: '50%', top: '50%',
transform: 'translate(-50%, -50%)', transform: 'translate(-50%, -50%)',
textAlign: 'center', textAlign: 'center',
alignItems: 'center',
}} }}
> >
<Typography variant="h3" gutterBottom> <Typography variant="h3" gutterBottom>
{errorFace} {errorFace}
</Typography> </Typography>
{retry && <Button onClick={retry}>{t('global.button.retry')}</Button>}
<Typography variant="h5">{message}</Typography> <Typography variant="h5">{message}</Typography>
{messageExtra} {messageExtra}
</Box> </Stack>
); );
} }

View File

@@ -76,12 +76,14 @@ export const useMetadataServerSettings = (): {
metadata?: Metadata; metadata?: Metadata;
settings: MetadataServerSettings; settings: MetadataServerSettings;
loading: boolean; loading: boolean;
request: ReturnType<typeof requestManager.useGetGlobalMeta>;
} => { } => {
const { data, loading } = requestManager.useGetGlobalMeta(); const request = requestManager.useGetGlobalMeta({ notifyOnNetworkStatusChange: true });
const { data, loading } = request;
const metadata = convertFromGqlMeta(data?.metas.nodes); const metadata = convertFromGqlMeta(data?.metas.nodes);
const settings = getMetadataServerSettingsWithDefaultFallback(metadata); const settings = getMetadataServerSettingsWithDefaultFallback(metadata);
return { metadata, settings, loading }; return { metadata, settings, loading, request };
}; };
export const getMetadataServerSettings = async (): Promise<MetadataServerSettings> => { export const getMetadataServerSettings = async (): Promise<MetadataServerSettings> => {

View File

@@ -54,12 +54,14 @@ export const useDefaultReaderSettings = (): {
metadata?: Metadata; metadata?: Metadata;
settings: IReaderSettings; settings: IReaderSettings;
loading: boolean; loading: boolean;
request: ReturnType<typeof requestManager.useGetGlobalMeta>;
} => { } => {
const { data, loading } = requestManager.useGetGlobalMeta(); const request = requestManager.useGetGlobalMeta({ notifyOnNetworkStatusChange: true });
const { data, loading } = request;
const metadata = convertFromGqlMeta(data?.metas.nodes); const metadata = convertFromGqlMeta(data?.metas.nodes);
const settings = getReaderSettingsWithDefaultValueFallback<IReaderSettings>(metadata); const settings = getReaderSettingsWithDefaultValueFallback<IReaderSettings>(metadata);
return { metadata, settings, loading }; return { metadata, settings, loading, request };
}; };
/** /**

View File

@@ -25,7 +25,7 @@ import {
useQuery, useQuery,
useSubscription, useSubscription,
} from '@apollo/client'; } from '@apollo/client';
import { OperationVariables } from '@apollo/client/core'; import { OperationVariables, Reference } from '@apollo/client/core';
import { useEffect, useMemo, useRef, useState } from 'react'; import { useEffect, useMemo, useRef, useState } from 'react';
import { IRestClient, RestClient } from '@/lib/requests/client/RestClient.ts'; import { IRestClient, RestClient } from '@/lib/requests/client/RestClient.ts';
import { GraphQLClient } from '@/lib/requests/client/GraphQLClient.ts'; import { GraphQLClient } from '@/lib/requests/client/GraphQLClient.ts';
@@ -269,7 +269,12 @@ import { DOWNLOAD_STATUS_SUBSCRIPTION } from '@/lib/graphql/subscriptions/Downlo
import { UPDATER_SUBSCRIPTION } from '@/lib/graphql/subscriptions/UpdaterSubscription.ts'; import { UPDATER_SUBSCRIPTION } from '@/lib/graphql/subscriptions/UpdaterSubscription.ts';
import { GET_SERVER_SETTINGS } from '@/lib/graphql/queries/SettingsQuery.ts'; import { GET_SERVER_SETTINGS } from '@/lib/graphql/queries/SettingsQuery.ts';
import { UPDATE_SERVER_SETTINGS } from '@/lib/graphql/mutations/SettingsMutation.ts'; import { UPDATE_SERVER_SETTINGS } from '@/lib/graphql/mutations/SettingsMutation.ts';
import { BASE_MANGA_FIELDS, FULL_DOWNLOAD_STATUS, FULL_EXTENSION_FIELDS } from '@/lib/graphql/Fragments.ts'; import {
BASE_MANGA_FIELDS,
FULL_DOWNLOAD_STATUS,
FULL_EXTENSION_FIELDS,
GLOBAL_METADATA,
} from '@/lib/graphql/Fragments.ts';
import { CLEAR_SERVER_CACHE } from '@/lib/graphql/mutations/ImageMutation.ts'; import { CLEAR_SERVER_CACHE } from '@/lib/graphql/mutations/ImageMutation.ts';
import { RESET_WEBUI_UPDATE_STATUS, UPDATE_WEBUI } from '@/lib/graphql/mutations/ServerInfoMutation.ts'; import { RESET_WEBUI_UPDATE_STATUS, UPDATE_WEBUI } from '@/lib/graphql/mutations/ServerInfoMutation.ts';
import { WEBUI_UPDATE_SUBSCRIPTION } from '@/lib/graphql/subscriptions/ServerInfoSubscription.ts'; import { WEBUI_UPDATE_SUBSCRIPTION } from '@/lib/graphql/subscriptions/ServerInfoSubscription.ts';
@@ -1023,18 +1028,40 @@ export class RequestManager {
value: any, value: any,
options?: MutationOptions<SetGlobalMetadataMutation, SetGlobalMetadataMutationVariables>, options?: MutationOptions<SetGlobalMetadataMutation, SetGlobalMetadataMutationVariables>,
): AbortableApolloMutationResponse<SetGlobalMetadataMutation> { ): AbortableApolloMutationResponse<SetGlobalMetadataMutation> {
const result = this.doRequest<SetGlobalMetadataMutation, SetGlobalMetadataMutationVariables>( return this.doRequest<SetGlobalMetadataMutation, SetGlobalMetadataMutationVariables>(
GQLMethod.MUTATION, GQLMethod.MUTATION,
SET_GLOBAL_METADATA, SET_GLOBAL_METADATA,
{ input: { meta: { key, value: `${value}` } } }, { input: { meta: { key, value: `${value}` } } },
options, {
update(cache, { data }) {
cache.modify({
fields: {
metas(existingMetas, { readField }) {
if (!existingMetas) {
return existingMetas;
}
const exists = existingMetas.nodes.some(
// eslint-disable-next-line no-underscore-dangle
(meta: Reference) => readField('key', meta) === key,
);
if (exists) {
return existingMetas;
}
const newMetaRef = cache.writeFragment({
data: data!.setGlobalMeta.meta,
fragment: GLOBAL_METADATA,
});
return [...existingMetas, newMetaRef];
},
},
});
},
...options,
},
); );
result.response.then(() => {
this.graphQLClient.client.cache.evict({ fieldName: 'metas' });
});
return result;
} }
public useGetAbout( public useGetAbout(
@@ -1116,7 +1143,7 @@ export class RequestManager {
}, },
}, },
}, },
[this.cache.getFetchTimestampFor(EXTENSION_LIST_CACHE_KEY, undefined)], [this.cache.getFetchTimestampFor(EXTENSION_LIST_CACHE_KEY, undefined), result.loading],
); );
const wrappedMutate = async (mutateOptions: Parameters<typeof mutate>[0]) => { const wrappedMutate = async (mutateOptions: Parameters<typeof mutate>[0]) => {
@@ -2063,6 +2090,7 @@ export class RequestManager {
GQLMethod.USE_QUERY, GQLMethod.USE_QUERY,
GET_CATEGORY_MANGAS, GET_CATEGORY_MANGAS,
{ id }, { id },
options as QueryHookOptions<GetCategoryMangasQuery, GetCategoryMangasQueryVariables>,
); );
return { return {

View File

@@ -103,7 +103,12 @@ export const DownloadQueue: React.FC = () => {
const [reorderDownload, { reset: revertReorder }] = requestManager.useReorderChapterInDownloadQueue(); const [reorderDownload, { reset: revertReorder }] = requestManager.useReorderChapterInDownloadQueue();
const { data: downloadStatusData, loading: isLoading } = requestManager.useGetDownloadStatus(); const {
data: downloadStatusData,
loading: isLoading,
error,
refetch,
} = requestManager.useGetDownloadStatus({ notifyOnNetworkStatusChange: true });
const downloaderData = downloadStatusData?.downloadStatus; const downloaderData = downloadStatusData?.downloadStatus;
const queue = (downloaderData?.queue as DownloadType[]) ?? []; const queue = (downloaderData?.queue as DownloadType[]) ?? [];
@@ -203,7 +208,7 @@ export const DownloadQueue: React.FC = () => {
// bug: The folder and the last image downloaded are not deleted // bug: The folder and the last image downloaded are not deleted
requestManager.deleteDownloadedChapter(chapter.id).response, requestManager.deleteDownloadedChapter(chapter.id).response,
]); ]);
} catch (error) { } catch (e) {
makeToast(t('download.queue.error.label.failed_to_remove'), 'error'); makeToast(t('download.queue.error.label.failed_to_remove'), 'error');
} }
@@ -218,6 +223,16 @@ export const DownloadQueue: React.FC = () => {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('DownloadQueue::refetch'))}
/>
);
}
if (isQueueEmpty) { if (isQueueEmpty) {
return <EmptyView message={t('download.queue.label.no_downloads')} />; return <EmptyView message={t('download.queue.label.no_downloads')} />;
} }

View File

@@ -39,6 +39,8 @@ import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { StyledGroupedVirtuoso } from '@/components/virtuoso/StyledGroupedVirtuoso.tsx'; import { StyledGroupedVirtuoso } from '@/components/virtuoso/StyledGroupedVirtuoso.tsx';
import { StyledGroupHeader } from '@/components/virtuoso/StyledGroupHeader.tsx'; import { StyledGroupHeader } from '@/components/virtuoso/StyledGroupHeader.tsx';
import { StyledGroupItemWrapper } from '@/components/virtuoso/StyledGroupItemWrapper.tsx'; import { StyledGroupItemWrapper } from '@/components/virtuoso/StyledGroupItemWrapper.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
const LANGUAGE = 0; const LANGUAGE = 0;
const EXTENSIONS = 1; const EXTENSIONS = 1;
@@ -114,7 +116,7 @@ export function Extensions() {
const [query] = useQueryParam('query', StringParam); const [query] = useQueryParam('query', StringParam);
const [refetchExtensions, setRefetchExtensions] = useState({}); const [refetchExtensions, setRefetchExtensions] = useState({});
const [fetchExtensions, { data, loading: isLoading, called }] = requestManager.useExtensionListFetch(); const [fetchExtensions, { data, loading: isLoading, error }] = requestManager.useExtensionListFetch();
const allExtensions = data?.fetchExtensions.extensions; const allExtensions = data?.fetchExtensions.extensions;
const handleExtensionUpdate = useCallback(() => setRefetchExtensions({}), []); const handleExtensionUpdate = useCallback(() => setRefetchExtensions({}), []);
@@ -229,10 +231,20 @@ export function Extensions() {
[], [],
); );
if (!allExtensions && (isLoading || !called)) { if (isLoading) {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => fetchExtensions().catch(defaultPromiseErrorHandler('Extensions::refetch'))}
/>
);
}
const showAddRepoInfo = !allExtensions?.length && !areReposDefined; const showAddRepoInfo = !allExtensions?.length && !areReposDefined;
if (showAddRepoInfo) { if (showAddRepoInfo) {
return ( return (

View File

@@ -43,7 +43,9 @@ const getMigratableSources = (mangas?: TMigratableSourcesResult): TMigratableSou
export const Migration = () => { export const Migration = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, loading, error } = requestManager.useGetMigratableSources(); const { data, loading, error } = requestManager.useGetMigratableSources({
notifyOnNetworkStatusChange: true,
});
const migratableSources = useMemo(() => getMigratableSources(data?.mangas.nodes), [data?.mangas.nodes]); const migratableSources = useMemo(() => getMigratableSources(data?.mangas.nodes), [data?.mangas.nodes]);
if (loading) { if (loading) {

View File

@@ -32,6 +32,7 @@ import { UpdateChapterPatchInput } from '@/lib/graphql/generated/graphql.ts';
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts'; import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
import { Chapters } from '@/lib/data/Chapters.ts'; import { Chapters } from '@/lib/data/Chapters.ts';
import { EmptyView } from '@/components/util/EmptyView.tsx';
const getReaderComponent = (readerType: ReaderType) => { const getReaderComponent = (readerType: ReaderType) => {
switch (readerType) { switch (readerType) {
@@ -95,7 +96,12 @@ export function Reader() {
Number(chapterIndex) === loadedChapter.current?.sourceOrder && Number(chapterIndex) === loadedChapter.current?.sourceOrder &&
loadedChapter.current?.pageCount !== -1; loadedChapter.current?.pageCount !== -1;
const manga = data?.manga ?? initialManga; const manga = data?.manga ?? initialManga;
const { data: chapterData, loading: isChapterLoading } = requestManager.useGetMangaChapter(mangaId, chapterIndex); const {
data: chapterData,
loading: isChapterLoading,
error: chapterError,
refetch: fetchChapter,
} = requestManager.useGetMangaChapter(mangaId, chapterIndex, { notifyOnNetworkStatusChange: true });
const arePagesUpdatedRef = useRef(false); const arePagesUpdatedRef = useRef(false);
const { const {
@@ -124,20 +130,30 @@ export function Reader() {
loadedChapter.current = getLoadedChapter(); loadedChapter.current = getLoadedChapter();
const chapter = loadedChapter.current ?? initialChapter; const chapter = loadedChapter.current ?? initialChapter;
const [fetchPages] = requestManager.useGetChapterPagesFetch(chapter.id); const [fetchPages, { loading: arePagesLoading, error: pagesError }] = requestManager.useGetChapterPagesFetch(
chapter.id,
);
useEffect(() => { const doFetchPages = () => {
const shouldFetchPages = !isChapterLoading && !chapter.isDownloaded; const shouldFetchPages = !isChapterLoading && !chapter.isDownloaded;
if (shouldFetchPages) { if (shouldFetchPages) {
fetchPages().then(() => { fetchPages()
arePagesUpdatedRef.current = true; .then(() => {
}); arePagesUpdatedRef.current = true;
})
.catch(defaultPromiseErrorHandler('Reader::fetchPages'));
} else { } else {
arePagesUpdatedRef.current = true; arePagesUpdatedRef.current = true;
} }
};
useEffect(() => {
doFetchPages();
}, [chapter.id]); }, [chapter.id]);
const isLoading = isChapterLoading || !arePagesUpdatedRef.current; const isLoading =
isChapterLoading || arePagesLoading || (!arePagesUpdatedRef.current && !chapterError && !pagesError);
const error = chapterError ?? pagesError;
const [wasLastPageReadSet, setWasLastPageReadSet] = useState(false); const [wasLastPageReadSet, setWasLastPageReadSet] = useState(false);
const [curPage, setCurPage] = useState<number>(0); const [curPage, setCurPage] = useState<number>(0);
const isLastPage = curPage === chapter.pageCount - 1; const isLastPage = curPage === chapter.pageCount - 1;
@@ -416,6 +432,24 @@ export function Reader() {
); );
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => {
if (chapterError) {
fetchChapter().catch(defaultPromiseErrorHandler('Reader::refetchChapter'));
}
if (pagesError) {
doFetchPages();
}
}}
/>
);
}
const pages = range(chapter.pageCount).map((index) => ({ const pages = range(chapter.pageCount).map((index) => ({
index, index,
src: requestManager.getChapterPageUrl(mangaId, chapterIndex, index), src: requestManager.getChapterPageUrl(mangaId, chapterIndex, index),

View File

@@ -19,6 +19,8 @@ import { MultiSelectListPreference } from '@/components/sourceConfiguration/Mult
import { PreferenceProps } from '@/typings.ts'; import { PreferenceProps } from '@/typings.ts';
import { NavBarContext } from '@/components/context/NavbarContext.tsx'; import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
function getPrefComponent(type: string) { function getPrefComponent(type: string) {
switch (type) { switch (type) {
@@ -52,7 +54,9 @@ export function SourceConfigure() {
}, [t]); }, [t]);
const { sourceId } = useParams<{ sourceId: string }>(); const { sourceId } = useParams<{ sourceId: string }>();
const { data, loading } = requestManager.useGetSource(sourceId); const { data, loading, error, refetch } = requestManager.useGetSource(sourceId, {
notifyOnNetworkStatusChange: true,
});
const sourcePreferences = data?.source.preferences ?? []; const sourcePreferences = data?.source.preferences ?? [];
const updateValue = const updateValue =
@@ -65,6 +69,16 @@ export function SourceConfigure() {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('SourceConfigure::refetch'))}
/>
);
}
return ( return (
<List sx={{ padding: 0 }}> <List sx={{ padding: 0 }}>
{sourcePreferences.map((it, index) => { {sourcePreferences.map((it, index) => {

View File

@@ -22,6 +22,8 @@ import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder';
import { SourceCard } from '@/components/SourceCard'; import { SourceCard } from '@/components/SourceCard';
import { LangSelect } from '@/components/navbar/action/LangSelect'; import { LangSelect } from '@/components/navbar/action/LangSelect';
import { NavBarContext } from '@/components/context/NavbarContext.tsx'; import { NavBarContext } from '@/components/context/NavbarContext.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
function sourceToLangList(sources: ISource[]) { function sourceToLangList(sources: ISource[]) {
const result: string[] = []; const result: string[] = [];
@@ -55,7 +57,12 @@ export function Sources() {
const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', sourceDefualtLangs()); const [shownLangs, setShownLangs] = useLocalStorage<string[]>('shownSourceLangs', sourceDefualtLangs());
const [showNsfw] = useLocalStorage<boolean>('showNsfw', true); const [showNsfw] = useLocalStorage<boolean>('showNsfw', true);
const { data, loading: isLoading } = requestManager.useGetSourceList(); const {
data,
loading: isLoading,
error,
refetch,
} = requestManager.useGetSourceList({ notifyOnNetworkStatusChange: true });
const sources = data?.sources.nodes; const sources = data?.sources.nodes;
const areSourcesFromDifferentRepos = useMemo(() => { const areSourcesFromDifferentRepos = useMemo(() => {
@@ -109,8 +116,18 @@ export function Sources() {
if (isLoading) return <LoadingPlaceholder />; if (isLoading) return <LoadingPlaceholder />;
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('Sources::refetch'))}
/>
);
}
if (sources?.length === 0) { if (sources?.length === 0) {
return <h3>{t('source.error.label.no_sources_found')}</h3>; return <EmptyView message={t('source.error.label.no_sources_found')} />;
} }
return ( return (

View File

@@ -28,6 +28,7 @@ import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarC
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder';
import { GetAboutQuery, UpdateState } from '@/lib/graphql/generated/graphql.ts'; import { GetAboutQuery, UpdateState } from '@/lib/graphql/generated/graphql.ts';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
import { EmptyView } from '@/components/util/EmptyView.tsx';
type AboutServer = GetAboutQuery['aboutServer']; type AboutServer = GetAboutQuery['aboutServer'];
@@ -201,7 +202,7 @@ export function About() {
useSetDefaultBackTo('settings'); useSetDefaultBackTo('settings');
const { data, loading } = requestManager.useGetAbout(); const { data, loading, error, refetch } = requestManager.useGetAbout({ notifyOnNetworkStatusChange: true });
const { aboutServer, aboutWebUI } = data ?? {}; const { aboutServer, aboutWebUI } = data ?? {};
const { const {
@@ -239,6 +240,16 @@ export function About() {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('About::refetch'))}
/>
);
}
return ( return (
<List> <List>
<List <List

View File

@@ -32,6 +32,8 @@ import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
import { TimeSetting } from '@/components/settings/TimeSetting.tsx'; import { TimeSetting } from '@/components/settings/TimeSetting.tsx';
import { ServerSettings } from '@/typings.ts'; import { ServerSettings } from '@/typings.ts';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
type BackupSettingsType = Pick<ServerSettings, 'backupPath' | 'backupTime' | 'backupInterval' | 'backupTTL'>; type BackupSettingsType = Pick<ServerSettings, 'backupPath' | 'backupTime' | 'backupInterval' | 'backupTTL'>;
@@ -71,7 +73,12 @@ export function Backup() {
useSetDefaultBackTo('settings'); useSetDefaultBackTo('settings');
const { data: settingsData, loading } = requestManager.useGetServerSettings(); const {
data: settingsData,
loading,
error,
refetch,
} = requestManager.useGetServerSettings({ notifyOnNetworkStatusChange: true });
const [mutateSettings] = requestManager.useUpdateServerSettings(); const [mutateSettings] = requestManager.useUpdateServerSettings();
const backupSettings = settingsData ? extractBackupSettings(settingsData.settings) : undefined; const backupSettings = settingsData ? extractBackupSettings(settingsData.settings) : undefined;
@@ -228,6 +235,16 @@ export function Backup() {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('Backup::refetch'))}
/>
);
}
return ( return (
<> <>
<List sx={{ padding: 0 }}> <List sx={{ padding: 0 }}>

View File

@@ -24,6 +24,8 @@ import {
useMetadataServerSettings, useMetadataServerSettings,
} from '@/lib/metadata/metadataServerSettings.ts'; } from '@/lib/metadata/metadataServerSettings.ts';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
type ExtensionsSettings = Pick<GqlServerSettings, 'maxSourcesInParallel' | 'localSourcePath' | 'extensionRepos'>; type ExtensionsSettings = Pick<GqlServerSettings, 'maxSourcesInParallel' | 'localSourcePath' | 'extensionRepos'>;
@@ -46,7 +48,9 @@ export const BrowseSettings = () => {
const [showNsfw, setShowNsfw] = useLocalStorage<boolean>('showNsfw', true); const [showNsfw, setShowNsfw] = useLocalStorage<boolean>('showNsfw', true);
const { data, loading } = requestManager.useGetServerSettings(); const { data, loading, error, refetch } = requestManager.useGetServerSettings({
notifyOnNetworkStatusChange: true,
});
const serverSettings = data ? extractBrowseSettings(data.settings) : undefined; const serverSettings = data ? extractBrowseSettings(data.settings) : undefined;
const [mutateSettings] = requestManager.useUpdateServerSettings(); const [mutateSettings] = requestManager.useUpdateServerSettings();
@@ -66,6 +70,16 @@ export const BrowseSettings = () => {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('BrowseSettings::refetch'))}
/>
);
}
return ( return (
<List> <List>
<ListItem> <ListItem>

View File

@@ -35,6 +35,8 @@ import { DEFAULT_FULL_FAB_HEIGHT } from '@/components/util/StyledFab';
import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext'; import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext';
import { TCategory } from '@/typings.ts'; import { TCategory } from '@/typings.ts';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
const getItemStyle = ( const getItemStyle = (
isDragging: boolean, isDragging: boolean,
@@ -63,7 +65,7 @@ export function Categories() {
}; };
}, [t]); }, [t]);
const { data, loading } = requestManager.useGetCategories({ notifyOnNetworkStatusChange: true }); const { data, loading, error, refetch } = requestManager.useGetCategories({ notifyOnNetworkStatusChange: true });
const categories = useMemo(() => { const categories = useMemo(() => {
const res = [...(data?.categories.nodes ?? [])]; const res = [...(data?.categories.nodes ?? [])];
if (res.length > 0 && res[0].name === 'Default') { if (res.length > 0 && res[0].name === 'Default') {
@@ -140,6 +142,16 @@ export function Categories() {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('category.error.label.request_failure')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('Categories::refetch'))}
/>
);
}
return ( return (
<> <>
<DragDropContext onDragEnd={onDragEnd}> <DragDropContext onDragEnd={onDragEnd}>

View File

@@ -7,8 +7,6 @@
*/ */
import { useContext, useEffect } from 'react'; import { useContext, useEffect } from 'react';
import Box from '@mui/material/Box';
import CircularProgress from '@mui/material/CircularProgress';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { AllowedMetadataValueTypes, IReaderSettings } from '@/typings'; import { AllowedMetadataValueTypes, IReaderSettings } from '@/typings';
import { convertToGqlMeta, requestUpdateServerMetadata } from '@/lib/metadata/metadata.ts'; import { convertToGqlMeta, requestUpdateServerMetadata } from '@/lib/metadata/metadata.ts';
@@ -21,6 +19,8 @@ import { ReaderSettingsOptions } from '@/components/reader/ReaderSettingsOptions
import { makeToast } from '@/components/util/Toast'; import { makeToast } from '@/components/util/Toast';
import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext'; import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts'; import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
export function DefaultReaderSettings() { export function DefaultReaderSettings() {
const { t } = useTranslation(); const { t } = useTranslation();
@@ -35,7 +35,12 @@ export function DefaultReaderSettings() {
}; };
}, [t]); }, [t]);
const { metadata, settings, loading } = useDefaultReaderSettings(); const {
metadata,
settings,
loading,
request: { error, refetch },
} = useDefaultReaderSettings();
useSetDefaultBackTo('settings'); useSetDefaultBackTo('settings');
@@ -48,17 +53,16 @@ export function DefaultReaderSettings() {
}; };
if (loading) { if (loading) {
return <LoadingPlaceholder />;
}
if (error) {
return ( return (
<Box <EmptyView
sx={{ message={t('global.error.label.failed_to_load_data')}
height: '100vh', messageExtra={error.message}
width: '100vw', retry={() => refetch().catch(defaultPromiseErrorHandler('DefaultReaderSettings::refetch'))}
display: 'grid', />
placeItems: 'center',
}}
>
<CircularProgress thickness={5} />
</Box>
); );
} }

View File

@@ -27,6 +27,8 @@ import { DeleteChaptersWhileReadingSetting } from '@/components/settings/downloa
import { CategoriesInclusionSetting } from '@/components/settings/CategoriesInclusionSetting.tsx'; import { CategoriesInclusionSetting } from '@/components/settings/CategoriesInclusionSetting.tsx';
import { NumberSetting } from '@/components/settings/NumberSetting.tsx'; import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
type DownloadSettingsType = Pick< type DownloadSettingsType = Pick<
ServerSettings, ServerSettings,
@@ -63,7 +65,9 @@ export const DownloadSettings = () => {
}; };
}, [t]); }, [t]);
const { data } = requestManager.useGetServerSettings(); const { data, loading, error, refetch } = requestManager.useGetServerSettings({
notifyOnNetworkStatusChange: true,
});
const downloadSettings = data ? extractDownloadSettings(data.settings) : undefined; const downloadSettings = data ? extractDownloadSettings(data.settings) : undefined;
const [mutateSettings] = requestManager.useUpdateServerSettings(); const [mutateSettings] = requestManager.useUpdateServerSettings();
const { settings: metadataSettings } = useMetadataServerSettings(); const { settings: metadataSettings } = useMetadataServerSettings();
@@ -85,6 +89,16 @@ export const DownloadSettings = () => {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('DownloadSettings::refetch'))}
/>
);
}
return ( return (
<List> <List>
<TextSetting <TextSetting

View File

@@ -22,6 +22,8 @@ import { ServerSettings as GqlServerSettings } from '@/typings.ts';
import { NumberSetting } from '@/components/settings/NumberSetting.tsx'; import { NumberSetting } from '@/components/settings/NumberSetting.tsx';
import { SelectSetting } from '@/components/settings/SelectSetting.tsx'; import { SelectSetting } from '@/components/settings/SelectSetting.tsx';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
type ServerSettingsType = Pick< type ServerSettingsType = Pick<
GqlServerSettings, GqlServerSettings,
@@ -84,7 +86,9 @@ export const ServerSettings = () => {
}; };
}, [t]); }, [t]);
const { data, loading } = requestManager.useGetServerSettings(); const { data, loading, error, refetch } = requestManager.useGetServerSettings({
notifyOnNetworkStatusChange: true,
});
const serverSettings = data ? extractServerSettings(data.settings) : undefined; const serverSettings = data ? extractServerSettings(data.settings) : undefined;
const [mutateSettings] = requestManager.useUpdateServerSettings(); const [mutateSettings] = requestManager.useUpdateServerSettings();
@@ -107,6 +111,16 @@ export const ServerSettings = () => {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('ServerSettings::refetch'))}
/>
);
}
return ( return (
<List> <List>
<List <List

View File

@@ -24,6 +24,8 @@ import {
} from '@/components/settings/SelectSetting.tsx'; } from '@/components/settings/SelectSetting.tsx';
import { WebUiChannel, WebUiFlavor, WebUiInterface } from '@/lib/graphql/generated/graphql.ts'; import { WebUiChannel, WebUiFlavor, WebUiInterface } from '@/lib/graphql/generated/graphql.ts';
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx'; import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder.tsx';
import { EmptyView } from '@/components/util/EmptyView.tsx';
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
type WebUISettingsType = Pick< type WebUISettingsType = Pick<
ServerSettings, ServerSettings,
@@ -125,7 +127,9 @@ export const WebUISettings = () => {
}; };
}, [t]); }, [t]);
const { data, loading } = requestManager.useGetServerSettings(); const { data, loading, error, refetch } = requestManager.useGetServerSettings({
notifyOnNetworkStatusChange: true,
});
const webUISettings = data ? extractWebUISettings(data.settings) : undefined; const webUISettings = data ? extractWebUISettings(data.settings) : undefined;
const [mutateSettings] = requestManager.useUpdateServerSettings(); const [mutateSettings] = requestManager.useUpdateServerSettings();
@@ -146,6 +150,16 @@ export const WebUISettings = () => {
return <LoadingPlaceholder />; return <LoadingPlaceholder />;
} }
if (error) {
return (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('WebUISettings::refetch'))}
/>
);
}
return ( return (
<List> <List>
<SelectSetting<WebUiFlavor> <SelectSetting<WebUiFlavor>