fix the ugliness of bare messages
- replace "loading..." messages with LoadingPlaceholder - Use EmptyView where appropriate
This commit is contained in:
@@ -90,7 +90,12 @@ export default function App() {
|
|||||||
id="appMainContainer"
|
id="appMainContainer"
|
||||||
maxWidth={false}
|
maxWidth={false}
|
||||||
disableGutters
|
disableGutters
|
||||||
style={{ paddingTop: theme.spacing(8), paddingLeft: isMobileWidth ? '' : theme.spacing(8) }}
|
style={{
|
||||||
|
marginTop: theme.spacing(8),
|
||||||
|
marginLeft: isMobileWidth ? '' : theme.spacing(8),
|
||||||
|
width: 'auto',
|
||||||
|
overflow: 'auto',
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Switch>
|
<Switch>
|
||||||
{/* General Routes */}
|
{/* General Routes */}
|
||||||
|
|||||||
59
src/components/EmptyView.tsx
Normal file
59
src/components/EmptyView.tsx
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) Contributors to the Suwayomi project
|
||||||
|
*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
// adopted from: https://github.com/tachiyomiorg/tachiyomi/blob/master/app/src/main/java/eu/kanade/tachiyomi/widget/EmptyView.kt
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import { useTheme } from '@mui/material/styles';
|
||||||
|
import { useMediaQuery } from '@mui/material';
|
||||||
|
|
||||||
|
const ERROR_FACES = [
|
||||||
|
'(・o・;)',
|
||||||
|
'Σ(ಠ_ಠ)',
|
||||||
|
'ಥ_ಥ',
|
||||||
|
'(˘・_・˘)',
|
||||||
|
'(; ̄Д ̄)',
|
||||||
|
'(・Д・。',
|
||||||
|
];
|
||||||
|
|
||||||
|
function getRandomErrorFace() {
|
||||||
|
const randIndex = Math.floor(Math.random() * ERROR_FACES.length);
|
||||||
|
return ERROR_FACES[randIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
message: string
|
||||||
|
messageExtra?: JSX.Element
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function EmptyView({ message, messageExtra }: IProps) {
|
||||||
|
const theme = useTheme();
|
||||||
|
const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm'));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{
|
||||||
|
position: 'absolute',
|
||||||
|
left: `calc(50% + ${isMobileWidth ? '0px' : theme.spacing(8 / 2)})`,
|
||||||
|
top: '50%',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
textAlign: 'center',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="h3" gutterBottom>
|
||||||
|
{getRandomErrorFace()}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="h5">
|
||||||
|
{message}
|
||||||
|
</Typography>
|
||||||
|
{messageExtra}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
EmptyView.defaultProps = {
|
||||||
|
messageExtra: undefined,
|
||||||
|
};
|
||||||
@@ -20,7 +20,7 @@ const useStyles = makeStyles({
|
|||||||
});
|
});
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
shouldRender: boolean | (() => boolean)
|
shouldRender?: boolean | (() => boolean)
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
component?: string | React.FunctionComponent<any> | React.ComponentClass<any, any>
|
component?: string | React.FunctionComponent<any> | React.ComponentClass<any, any>
|
||||||
componentProps?: any
|
componentProps?: any
|
||||||
@@ -32,7 +32,10 @@ export default function LoadingPlaceholder(props: IProps) {
|
|||||||
} = props;
|
} = props;
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const condition = shouldRender instanceof Function ? shouldRender() : shouldRender;
|
let condition = true;
|
||||||
|
if (shouldRender !== undefined) {
|
||||||
|
condition = shouldRender instanceof Function ? shouldRender() : shouldRender;
|
||||||
|
}
|
||||||
|
|
||||||
if (condition) {
|
if (condition) {
|
||||||
if (component) {
|
if (component) {
|
||||||
|
|||||||
@@ -7,10 +7,13 @@
|
|||||||
|
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
|
import EmptyView from 'components/EmptyView';
|
||||||
|
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
||||||
import MangaCard from './MangaCard';
|
import MangaCard from './MangaCard';
|
||||||
|
|
||||||
interface IProps{
|
interface IProps{
|
||||||
mangas: IMangaCard[]
|
mangas: IMangaCard[]
|
||||||
|
isLoading: boolean
|
||||||
message?: string
|
message?: string
|
||||||
messageExtra?: JSX.Element
|
messageExtra?: JSX.Element
|
||||||
hasNextPage: boolean
|
hasNextPage: boolean
|
||||||
@@ -20,7 +23,7 @@ interface IProps{
|
|||||||
|
|
||||||
export default function MangaGrid(props: IProps) {
|
export default function MangaGrid(props: IProps) {
|
||||||
const {
|
const {
|
||||||
mangas, message, messageExtra, hasNextPage, lastPageNum, setLastPageNum,
|
mangas, isLoading, message, messageExtra, hasNextPage, lastPageNum, setLastPageNum,
|
||||||
} = props;
|
} = props;
|
||||||
let mapped;
|
let mapped;
|
||||||
const lastManga = useRef<HTMLDivElement>(null);
|
const lastManga = useRef<HTMLDivElement>(null);
|
||||||
@@ -41,12 +44,15 @@ export default function MangaGrid(props: IProps) {
|
|||||||
}, [hasNextPage, mangas]);
|
}, [hasNextPage, mangas]);
|
||||||
|
|
||||||
if (mangas.length === 0) {
|
if (mangas.length === 0) {
|
||||||
mapped = (
|
if (isLoading) {
|
||||||
<div>
|
mapped = (
|
||||||
<h3>{message}</h3>
|
<LoadingPlaceholder />
|
||||||
{messageExtra}
|
);
|
||||||
</div>
|
} else {
|
||||||
);
|
mapped = (
|
||||||
|
<EmptyView message={message!} messageExtra={messageExtra} />
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mapped = mangas.map((it, idx) => {
|
mapped = mangas.map((it, idx) => {
|
||||||
if (idx === mangas.length - 1) {
|
if (idx === mangas.length - 1) {
|
||||||
@@ -75,6 +81,6 @@ export default function MangaGrid(props: IProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MangaGrid.defaultProps = {
|
MangaGrid.defaultProps = {
|
||||||
message: 'loading...',
|
message: '',
|
||||||
messageExtra: undefined,
|
messageExtra: undefined,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ import ExtensionIcon from '@mui/icons-material/Extension';
|
|||||||
import ExploreIcon from '@mui/icons-material/Explore';
|
import ExploreIcon from '@mui/icons-material/Explore';
|
||||||
import GetAppIcon from '@mui/icons-material/GetApp';
|
import GetAppIcon from '@mui/icons-material/GetApp';
|
||||||
import SettingsIcon from '@mui/icons-material/Settings';
|
import SettingsIcon from '@mui/icons-material/Settings';
|
||||||
import TemporaryDrawer from 'components/TemporaryDrawer';
|
import NavBarContext from 'context/NavbarContext';
|
||||||
import NavBarContext from '../../context/NavbarContext';
|
import DarkTheme from 'context/DarkTheme';
|
||||||
import DarkTheme from '../../context/DarkTheme';
|
|
||||||
import PermanentSideBar from './PermanentSideBar';
|
import PermanentSideBar from './PermanentSideBar';
|
||||||
|
import TemporaryDrawer from './TemporaryDrawer';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import useLocalStorage from 'util/useLocalStorage';
|
|||||||
import LangSelect from 'components/manga/LangSelect';
|
import LangSelect from 'components/manga/LangSelect';
|
||||||
import { extensionDefaultLangs, langCodeToName, langSortCmp } from 'util/language';
|
import { extensionDefaultLangs, langCodeToName, langSortCmp } from 'util/language';
|
||||||
import { makeToaster } from 'components/Toast';
|
import { makeToaster } from 'components/Toast';
|
||||||
|
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
||||||
|
|
||||||
const allLangs: string[] = [];
|
const allLangs: string[] = [];
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ export default function MangaExtensions() {
|
|||||||
}, [extensions]); // useEffect only after <input> renders
|
}, [extensions]); // useEffect only after <input> renders
|
||||||
|
|
||||||
if (Object.entries(extensions).length === 0) {
|
if (Object.entries(extensions).length === 0) {
|
||||||
return <h3>loading...</h3>;
|
return <LoadingPlaceholder />;
|
||||||
}
|
}
|
||||||
const groupsToShow = ['updates pending', 'installed', ...shownLangs];
|
const groupsToShow = ['updates pending', 'installed', ...shownLangs];
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import MangaGrid from 'components/manga/MangaGrid';
|
|||||||
import NavbarContext from 'context/NavbarContext';
|
import NavbarContext from 'context/NavbarContext';
|
||||||
import client from 'util/client';
|
import client from 'util/client';
|
||||||
import cloneObject from 'util/cloneObject';
|
import cloneObject from 'util/cloneObject';
|
||||||
|
import EmptyView from 'components/EmptyView';
|
||||||
|
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
||||||
|
|
||||||
interface IMangaCategory {
|
interface IMangaCategory {
|
||||||
category: ICategory
|
category: ICategory
|
||||||
@@ -93,11 +95,11 @@ export default function Library() {
|
|||||||
}, [tabs?.length, tabNum]);
|
}, [tabs?.length, tabNum]);
|
||||||
|
|
||||||
if (tabs === undefined) {
|
if (tabs === undefined) {
|
||||||
return <h3>Loading...</h3>;
|
return <LoadingPlaceholder />;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tabs.length === 0) {
|
if (tabs.length === 0) {
|
||||||
return <h3>Library is empty</h3>;
|
return <EmptyView message="Your Library is empty" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
let toRender;
|
let toRender;
|
||||||
@@ -112,7 +114,8 @@ export default function Library() {
|
|||||||
hasNextPage={false}
|
hasNextPage={false}
|
||||||
lastPageNum={lastPageNum}
|
lastPageNum={lastPageNum}
|
||||||
setLastPageNum={setLastPageNum}
|
setLastPageNum={setLastPageNum}
|
||||||
message={tab.isFetched ? 'Category is Empty' : 'Loading...'}
|
message="Category is Empty"
|
||||||
|
isLoading={!tab.isFetched}
|
||||||
/>
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
));
|
));
|
||||||
@@ -145,7 +148,8 @@ export default function Library() {
|
|||||||
hasNextPage={false}
|
hasNextPage={false}
|
||||||
lastPageNum={lastPageNum}
|
lastPageNum={lastPageNum}
|
||||||
setLastPageNum={setLastPageNum}
|
setLastPageNum={setLastPageNum}
|
||||||
message={tabs.length > 0 ? 'Library is Empty' : undefined}
|
message="Your Library is empty"
|
||||||
|
isLoading={!tabs[0].isFetched}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export default function SearchSingle() {
|
|||||||
const [searchTerm, setSearchTerm] = useState<string>('');
|
const [searchTerm, setSearchTerm] = useState<string>('');
|
||||||
const [hasNextPage, setHasNextPage] = useState<boolean>(false);
|
const [hasNextPage, setHasNextPage] = useState<boolean>(false);
|
||||||
const [lastPageNum, setLastPageNum] = useState<number>(1);
|
const [lastPageNum, setLastPageNum] = useState<number>(1);
|
||||||
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
const textInput = React.createRef<HTMLInputElement>();
|
const textInput = React.createRef<HTMLInputElement>();
|
||||||
|
|
||||||
@@ -53,22 +54,23 @@ export default function SearchSingle() {
|
|||||||
const { value } = textInput.current;
|
const { value } = textInput.current;
|
||||||
if (value === '') {
|
if (value === '') {
|
||||||
setError(true);
|
setError(true);
|
||||||
setMessage('Type something to search');
|
} else if (value !== searchTerm) {
|
||||||
} else {
|
|
||||||
setError(false);
|
setError(false);
|
||||||
setSearchTerm(value);
|
setSearchTerm(value);
|
||||||
setMangas([]);
|
setMangas([]);
|
||||||
setMessage('loading...');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (searchTerm.length > 0) {
|
if (searchTerm.length > 0) {
|
||||||
|
setIsLoading(true);
|
||||||
|
|
||||||
client.get(`/api/v1/source/${sourceId}/search/${searchTerm}/${lastPageNum}`)
|
client.get(`/api/v1/source/${sourceId}/search/${searchTerm}/${lastPageNum}`)
|
||||||
.then((response) => response.data)
|
.then((response) => response.data)
|
||||||
.then((data: { mangaList: IManga[], hasNextPage: boolean }) => {
|
.then((data: { mangaList: IManga[], hasNextPage: boolean }) => {
|
||||||
setMessage('');
|
setMessage('');
|
||||||
|
|
||||||
if (data.mangaList.length > 0) {
|
if (data.mangaList.length > 0) {
|
||||||
setMangas([
|
setMangas([
|
||||||
...mangas,
|
...mangas,
|
||||||
@@ -77,22 +79,14 @@ export default function SearchSingle() {
|
|||||||
}))]);
|
}))]);
|
||||||
setHasNextPage(data.hasNextPage);
|
setHasNextPage(data.hasNextPage);
|
||||||
} else {
|
} else {
|
||||||
setMessage('search query returned nothing.');
|
setMessage('Search query returned nothing.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setIsLoading(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [searchTerm]);
|
}, [searchTerm]);
|
||||||
|
|
||||||
const mangaGrid = (
|
|
||||||
<MangaGrid
|
|
||||||
mangas={mangas}
|
|
||||||
message={message}
|
|
||||||
hasNextPage={hasNextPage}
|
|
||||||
lastPageNum={lastPageNum}
|
|
||||||
setLastPageNum={setLastPageNum}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
@@ -109,7 +103,17 @@ export default function SearchSingle() {
|
|||||||
Search
|
Search
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{mangaGrid}
|
{searchTerm.length > 0
|
||||||
|
&& (
|
||||||
|
<MangaGrid
|
||||||
|
mangas={mangas}
|
||||||
|
message={message}
|
||||||
|
hasNextPage={hasNextPage}
|
||||||
|
lastPageNum={lastPageNum}
|
||||||
|
setLastPageNum={setLastPageNum}
|
||||||
|
isLoading={isLoading}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ export default function SourceMangas(props: { popular: boolean }) {
|
|||||||
setLastPageNum={setLastPageNum}
|
setLastPageNum={setLastPageNum}
|
||||||
message={message}
|
message={message}
|
||||||
messageExtra={messageExtra}
|
messageExtra={messageExtra}
|
||||||
|
isLoading={!fetched}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
sourceDefualtLangs, sourceForcedDefaultLangs, langCodeToName, langSortCmp,
|
sourceDefualtLangs, sourceForcedDefaultLangs, langCodeToName, langSortCmp,
|
||||||
} from 'util/language';
|
} from 'util/language';
|
||||||
import useLocalStorage from 'util/useLocalStorage';
|
import useLocalStorage from 'util/useLocalStorage';
|
||||||
|
import LoadingPlaceholder from 'components/LoadingPlaceholder';
|
||||||
|
|
||||||
function sourceToLangList(sources: ISource[]) {
|
function sourceToLangList(sources: ISource[]) {
|
||||||
const result: string[] = [];
|
const result: string[] = [];
|
||||||
@@ -81,7 +82,7 @@ export default function MangaSources() {
|
|||||||
|
|
||||||
if (sources.length === 0) {
|
if (sources.length === 0) {
|
||||||
if (fetched) return (<h3>No sources found. Install Some Extensions first.</h3>);
|
if (fetched) return (<h3>No sources found. Install Some Extensions first.</h3>);
|
||||||
return (<h3>loading...</h3>);
|
return <LoadingPlaceholder />;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
Reference in New Issue
Block a user