From c19df43e4a92da0512a849df4e32fb93fb5c1e41 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 29 Apr 2024 15:34:12 +0200 Subject: [PATCH] Fix styling of SearchAll error messages --- src/components/util/EmptyView.tsx | 57 +++++++++++++++++++ .../util/EmptyViewAbsoluteCentered.tsx | 54 +----------------- src/screens/SearchAll.tsx | 27 +++++---- 3 files changed, 76 insertions(+), 62 deletions(-) create mode 100644 src/components/util/EmptyView.tsx diff --git a/src/components/util/EmptyView.tsx b/src/components/util/EmptyView.tsx new file mode 100644 index 00000000..f8d7a0dc --- /dev/null +++ b/src/components/util/EmptyView.tsx @@ -0,0 +1,57 @@ +/* + * 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 { useMemo } from 'react'; +import Typography from '@mui/material/Typography'; +import { SxProps, Theme } from '@mui/material/styles'; +import { useTranslation } from 'react-i18next'; +import Button from '@mui/material/Button'; +import Stack from '@mui/material/Stack'; + +const ERROR_FACES = ['(・o・;)', 'Σ(ಠ_ಠ)', 'ಥ_ಥ', '(˘・_・˘)', '(; ̄Д ̄)', '(・Д・。']; + +function getRandomErrorFace() { + const randIndex = Math.floor(Math.random() * ERROR_FACES.length); + return ERROR_FACES[randIndex]; +} + +export interface EmptyViewProps { + message: string; + messageExtra?: JSX.Element | string; + retry?: () => void; + noFaces?: boolean; + sx?: SxProps; +} + +export function EmptyView({ message, messageExtra, retry, noFaces, sx }: EmptyViewProps) { + const { t } = useTranslation(); + + const errorFace = useMemo(() => getRandomErrorFace(), []); + + return ( + + {!noFaces && ( + + {errorFace} + + )} + {retry && } + {message} + {messageExtra} + + ); +} diff --git a/src/components/util/EmptyViewAbsoluteCentered.tsx b/src/components/util/EmptyViewAbsoluteCentered.tsx index 696e662f..bf53e674 100644 --- a/src/components/util/EmptyViewAbsoluteCentered.tsx +++ b/src/components/util/EmptyViewAbsoluteCentered.tsx @@ -6,58 +6,10 @@ * 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 { EmptyView, EmptyViewProps } from '@/components/util/EmptyView.tsx'; -import { useMemo } from 'react'; -import Typography from '@mui/material/Typography'; -import { useTheme } from '@mui/material/styles'; -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・;)', 'Σ(ಠ_ಠ)', 'ಥ_ಥ', '(˘・_・˘)', '(; ̄Д ̄)', '(・Д・。']; - -function getRandomErrorFace() { - const randIndex = Math.floor(Math.random() * ERROR_FACES.length); - return ERROR_FACES[randIndex]; -} - -interface IProps { - message: string; - messageExtra?: JSX.Element | string; - retry?: () => void; - noFaces?: boolean; -} - -export function EmptyViewAbsoluteCentered({ message, messageExtra, retry, noFaces }: IProps) { - const { t } = useTranslation(); - const theme = useTheme(); - const isMobileWidth = useMediaQuery(theme.breakpoints.down('sm')); - - const errorFace = useMemo(() => getRandomErrorFace(), []); - - return ( - - {!noFaces && ( - - {errorFace} - - )} - {retry && } - {message} - {messageExtra} - - ); +export function EmptyViewAbsoluteCentered({ sx, ...emptyViewProps }: EmptyViewProps) { + return ; } EmptyViewAbsoluteCentered.defaultProps = { diff --git a/src/screens/SearchAll.tsx b/src/screens/SearchAll.tsx index ccf0eb6e..675a9fa0 100644 --- a/src/screens/SearchAll.tsx +++ b/src/screens/SearchAll.tsx @@ -24,6 +24,7 @@ import { MangaGrid } from '@/components/MangaGrid'; import { useDebounce } from '@/util/useDebounce.ts'; import { NavBarContext, useSetDefaultBackTo } from '@/components/context/NavbarContext.tsx'; import { MangaCardProps } from '@/components/manga/MangaCard.types.tsx'; +import { EmptyView } from '@/components/util/EmptyView'; type SourceLoadingState = { isLoading: boolean; hasResults: boolean; emptySearch: boolean }; type SourceToLoadingStateMap = Map; @@ -145,17 +146,21 @@ const SourceSearchPreview = React.memo( {translateExtensionLanguage(lang)} - undefined} - horizontal - noFaces - message={errorMessage} - inLibraryIndicator - mode={mode} - /> + {errorMessage ? ( + + ) : ( + undefined} + horizontal + noFaces + message={errorMessage} + inLibraryIndicator + mode={mode} + /> + )} ); },