Handle long extra messages in EmptyView

This commit is contained in:
schroda
2024-12-20 19:15:18 +01:00
parent 083f98e9f6
commit 1f7fe5f20e
9 changed files with 41 additions and 22 deletions

View File

@@ -53,6 +53,7 @@ import { MangaIdInfo } from '@/modules/manga/Manga.types.ts';
import { GridLayout } from '@/modules/core/Core.types.ts';
import { AppRoutes } from '@/modules/core/AppRoute.constants.ts';
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
const DEFAULT_SOURCE: Pick<SourceType, 'id'> = { id: '-1' };
@@ -249,6 +250,16 @@ export function SourceMangas() {
const currentQuery = useRef(query);
const currentAbortRequest = useRef<(reason: any) => void>(() => {});
const contentTypeMenuRef = useRef<HTMLDivElement>(null);
const [contentTypeMenuHeight, setContentTypeMenuHeight] = useState(0);
useResizeObserver(
contentTypeMenuRef,
useCallback(
() => setContentTypeMenuHeight(contentTypeMenuRef.current?.clientHeight ?? 0),
[contentTypeMenuRef],
),
);
const didSearchChange = currentQuery.current !== query;
if (didSearchChange && contentType === SourceContentType.SEARCH) {
currentQuery.current = query;
@@ -428,9 +439,11 @@ export function SourceMangas() {
};
}, [t, source]);
const EmptyViewComponent = mangas.length ? EmptyView : EmptyViewAbsoluteCentered;
return (
<StyledGridWrapper>
<ContentTypeMenu sx={{ top: `${appBarHeight}px` }}>
<ContentTypeMenu ref={contentTypeMenuRef} sx={{ top: `${appBarHeight}px` }}>
<ContentTypeButton
variant={contentType === SourceContentType.POPULAR ? 'contained' : 'outlined'}
startIcon={<FavoriteIcon />}
@@ -466,6 +479,7 @@ export function SourceMangas() {
loadMore={loadMore}
message={message}
messageExtra={messageExtra}
topOffset={contentTypeMenuHeight}
isLoading={isLoading}
gridLayout={sourceGridLayout}
mode="source"
@@ -473,18 +487,12 @@ export function SourceMangas() {
/>
)}
{error && !mangas.length && (
<EmptyViewAbsoluteCentered
{error && (
<EmptyViewComponent
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => loadPage(lastPageNum).catch(defaultPromiseErrorHandler('SourceMangas::refetch'))}
/>
)}
{error && !!mangas.length && (
<EmptyView
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
messageExtra={getErrorMessage(error)}
retry={() => loadPage(lastPageNum).catch(defaultPromiseErrorHandler('SourceMangas::refetch'))}
topOffset={contentTypeMenuHeight}
/>
)}