Skip to content

Commit

Permalink
Handle long extra messages in EmptyView
Browse files Browse the repository at this point in the history
  • Loading branch information
schroda committed Dec 20, 2024
1 parent 083f98e commit 1f7fe5f
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/modules/browse/screens/Browse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function Browse() {
<Tab value={Tabs.MIGRATE} sx={{ textTransform: 'none' }} label={t('migrate.title')} />
</TabsMenu>
<TabPanel index={Tabs.SOURCE} currentIndex={tabName}>
<Sources />
<Sources tabsMenuHeight={tabsMenuHeight} />
</TabPanel>
<TabPanel index={Tabs.EXTENSIONS} currentIndex={tabName}>
<Extensions tabsMenuHeight={tabsMenuHeight} />
Expand Down
3 changes: 2 additions & 1 deletion src/modules/chapter/components/ChapterList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
import { shouldForwardProp } from '@/modules/core/utils/ShouldForwardProp.ts';
import { useChapterOptions } from '@/modules/chapter/hooks/useChapterOptions.tsx';
import { getErrorMessage } from '@/lib/HelperFunctions.ts';

type ChapterListHeaderProps = {
scrollbarWidth: number;
Expand Down Expand Up @@ -175,7 +176,7 @@ export const ChapterList = ({
<Stack sx={{ justifyContent: 'center', position: 'relative', flexGrow: 1 }}>
<EmptyViewAbsoluteCentered
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
messageExtra={getErrorMessage(error)}
retry={() => refetch().catch(defaultPromiseErrorHandler('ChapterList::refetch'))}
/>
</Stack>
Expand Down
11 changes: 8 additions & 3 deletions src/modules/core/components/placeholder/EmptyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export interface EmptyViewProps {
messageExtra?: JSX.Element | string;
retry?: () => void;
noFaces?: boolean;
topOffset?: number;
sx?: SxProps<Theme>;
}

export function EmptyView({ message, messageExtra, retry, noFaces, sx }: EmptyViewProps) {
export function EmptyView({ message, messageExtra, retry, noFaces, topOffset = 0, sx }: EmptyViewProps) {
const { t } = useTranslation();

const errorFace = useMemo(() => getRandomErrorFace(), []);
Expand All @@ -41,7 +42,9 @@ export function EmptyView({ message, messageExtra, retry, noFaces, sx }: EmptyVi
textAlign: 'center',
alignItems: 'center',
justifyContent: 'center',
height: '100%',
minWidth: '100%',
minHeight: `calc(100% - ${topOffset}px)`,
mt: `${topOffset}px`,
...sx,
}}
>
Expand All @@ -51,7 +54,9 @@ export function EmptyView({ message, messageExtra, retry, noFaces, sx }: EmptyVi
</Typography>
)}
<Typography variant="h5">{message}</Typography>
{messageExtra}
<Typography variant="body1" sx={{ wordBreak: 'break-word' }}>
{messageExtra}
</Typography>
{retry && <Button onClick={retry}>{t('global.button.retry')}</Button>}
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export function EmptyViewAbsoluteCentered({ sx, ...emptyViewProps }: EmptyViewPr
{...emptyViewProps}
sx={{
position: 'absolute',
height: undefined,
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
top: 0,
left: 0,
...sx,
}}
/>
Expand Down
1 change: 1 addition & 0 deletions src/modules/extension/screens/Extensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export function Extensions({ tabsMenuHeight }: { tabsMenuHeight: number }) {
fetchExtensions().catch(defaultPromiseErrorHandler('Extensions::refetchExtensions'));
}
}}
topOffset={tabsMenuHeight}
/>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/manga/components/MangaGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export const MangaGrid: React.FC<IMangaGridProps> = ({
isLoading,
message,
messageExtra,
topOffset,
hasNextPage,
loadMore,
gridLayout,
Expand Down Expand Up @@ -348,6 +349,7 @@ export const MangaGrid: React.FC<IMangaGridProps> = ({
message={message ?? t('manga.error.label.no_mangas_found')}
messageExtra={messageExtra}
retry={retry}
topOffset={topOffset}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/migration/screens/Migration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const Migration = ({ tabsMenuHeight }: { tabsMenuHeight: number }) => {
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('Migration::refetch'))}
topOffset={tabsMenuHeight}
/>
);
}
Expand Down
30 changes: 19 additions & 11 deletions src/modules/source/screens/SourceMangas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' };

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 />}
Expand Down Expand Up @@ -466,25 +479,20 @@ export function SourceMangas() {
loadMore={loadMore}
message={message}
messageExtra={messageExtra}
topOffset={contentTypeMenuHeight}
isLoading={isLoading}
gridLayout={sourceGridLayout}
mode="source"
inLibraryIndicator
/>
)}

{error && !mangas.length && (
<EmptyViewAbsoluteCentered
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => loadPage(lastPageNum).catch(defaultPromiseErrorHandler('SourceMangas::refetch'))}
/>
)}
{error && !!mangas.length && (
<EmptyView
{error && (
<EmptyViewComponent
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
messageExtra={getErrorMessage(error)}
retry={() => loadPage(lastPageNum).catch(defaultPromiseErrorHandler('SourceMangas::refetch'))}
topOffset={contentTypeMenuHeight}
/>
)}

Expand Down
7 changes: 5 additions & 2 deletions src/modules/source/screens/Sources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function groupByLang<Source extends Pick<SourceType, 'id' | 'name' | 'lang'>>(
return result;
}

export function Sources() {
export function Sources({ tabsMenuHeight }: { tabsMenuHeight: number }) {
const { t } = useTranslation();
const { setAction } = useContext(NavBarContext);

Expand Down Expand Up @@ -138,12 +138,15 @@ export function Sources() {
message={t('global.error.label.failed_to_load_data')}
messageExtra={error.message}
retry={() => refetch().catch(defaultPromiseErrorHandler('Sources::refetch'))}
topOffset={tabsMenuHeight}
/>
);
}

if (sources?.length === 0) {
return <EmptyViewAbsoluteCentered message={t('source.error.label.no_sources_found')} />;
return (
<EmptyViewAbsoluteCentered message={t('source.error.label.no_sources_found')} topOffset={tabsMenuHeight} />
);
}

return (
Expand Down

0 comments on commit 1f7fe5f

Please sign in to comment.