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
This commit is contained in:
@@ -12,12 +12,14 @@ import { Typography } from '@mui/material';
|
|||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
import { Theme } from '@mui/material/styles';
|
import { Theme } from '@mui/material/styles';
|
||||||
import makeStyles from '@mui/styles/makeStyles';
|
import makeStyles from '@mui/styles/makeStyles';
|
||||||
import React from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { mutate } from 'swr';
|
import { mutate } from 'swr';
|
||||||
import client from 'util/client';
|
import client from 'util/client';
|
||||||
import useLocalStorage from 'util/useLocalStorage';
|
import useLocalStorage from 'util/useLocalStorage';
|
||||||
import { IManga, ISource } from 'typings';
|
import { IManga, ISource } from 'typings';
|
||||||
|
import { t as translate } from 'i18next';
|
||||||
|
import makeToast from 'components/util/Toast';
|
||||||
|
|
||||||
const useStyles = (inLibrary: boolean) =>
|
const useStyles = (inLibrary: boolean) =>
|
||||||
makeStyles((theme: Theme) => ({
|
makeStyles((theme: Theme) => ({
|
||||||
@@ -119,10 +121,11 @@ interface IProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSourceName(source: ISource) {
|
function getSourceName(source: ISource) {
|
||||||
if (source.displayName !== null) {
|
if (!source) {
|
||||||
return source.displayName;
|
return translate('global.label.unknown');
|
||||||
}
|
}
|
||||||
return source.id;
|
|
||||||
|
return source.displayName ?? source.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getValueOrUnknown(val: string) {
|
function getValueOrUnknown(val: string) {
|
||||||
@@ -137,6 +140,8 @@ const MangaDetails: React.FC<IProps> = ({ manga }) => {
|
|||||||
|
|
||||||
const classes = useStyles(manga.inLibrary)();
|
const classes = useStyles(manga.inLibrary)();
|
||||||
|
|
||||||
|
useEffect(() => makeToast(translate('source.error.label.source_not_found'), 'error'), [manga.id]);
|
||||||
|
|
||||||
const addToLibrary = () => {
|
const addToLibrary = () => {
|
||||||
mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`, { ...manga, inLibrary: true }, { revalidate: false });
|
mutate(`/api/v1/manga/${manga.id}/?onlineFetch=false`, { ...manga, inLibrary: true }, { revalidate: false });
|
||||||
client
|
client
|
||||||
|
|||||||
@@ -238,7 +238,8 @@
|
|||||||
"filter": "Filter",
|
"filter": "Filter",
|
||||||
"loading": "Loading...",
|
"loading": "Loading...",
|
||||||
"none": "None",
|
"none": "None",
|
||||||
"sort": "Sort"
|
"sort": "Sort",
|
||||||
|
"unknown": "Unknown"
|
||||||
},
|
},
|
||||||
"language": {
|
"language": {
|
||||||
"label": {
|
"label": {
|
||||||
@@ -435,7 +436,8 @@
|
|||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"label": {
|
"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": {
|
"local_source": {
|
||||||
|
|||||||
Reference in New Issue
Block a user