From f5a961e82fb6ddb7b79b3789eaa9102b7af83dd7 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 1 May 2023 23:31:14 +0200 Subject: [PATCH] Fix/manga white screen missing extension (#285) * Prevent white screen when source is missing A undefined source caused a TypeError * Show error message when source is missing --- src/components/manga/MangaDetails.tsx | 13 +++++++++---- src/i18n/locale/en.json | 6 ++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/components/manga/MangaDetails.tsx b/src/components/manga/MangaDetails.tsx index ca23ff02..541186eb 100644 --- a/src/components/manga/MangaDetails.tsx +++ b/src/components/manga/MangaDetails.tsx @@ -12,12 +12,14 @@ import { Typography } from '@mui/material'; import IconButton from '@mui/material/IconButton'; import { Theme } from '@mui/material/styles'; import makeStyles from '@mui/styles/makeStyles'; -import React from 'react'; +import React, { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { mutate } from 'swr'; import client from 'util/client'; import useLocalStorage from 'util/useLocalStorage'; import { IManga, ISource } from 'typings'; +import { t as translate } from 'i18next'; +import makeToast from 'components/util/Toast'; const useStyles = (inLibrary: boolean) => makeStyles((theme: Theme) => ({ @@ -119,10 +121,11 @@ interface IProps { } function getSourceName(source: ISource) { - if (source.displayName !== null) { - return source.displayName; + if (!source) { + return translate('global.label.unknown'); } - return source.id; + + return source.displayName ?? source.id; } function getValueOrUnknown(val: string) { @@ -137,6 +140,8 @@ const MangaDetails: React.FC = ({ manga }) => { const classes = useStyles(manga.inLibrary)(); + useEffect(() => makeToast(translate('source.error.label.source_not_found'), 'error'), [manga.id]); + const addToLibrary = () => { mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`, { ...manga, inLibrary: true }, { revalidate: false }); client diff --git a/src/i18n/locale/en.json b/src/i18n/locale/en.json index d011124f..01569043 100644 --- a/src/i18n/locale/en.json +++ b/src/i18n/locale/en.json @@ -238,7 +238,8 @@ "filter": "Filter", "loading": "Loading...", "none": "None", - "sort": "Sort" + "sort": "Sort", + "unknown": "Unknown" }, "language": { "label": { @@ -435,7 +436,8 @@ }, "error": { "label": { - "no_sources_found": "No sources found. Install Some Extensions first." + "no_sources_found": "No sources found. Install Some Extensions first.", + "source_not_found": "Could not find source. Check your installed extensions." } }, "local_source": {