Prevent scrollbar from shortly disappearing on library category change

Due to the MangaGrid getting unmounted when changing the category, the "y overflow" value got reset to "auto" which caused the scrollbar from disappearing and immediately reappearing again.
This caused the site content to slightly "jump" due to the increase and immediate decrease in is width.

Related commit 871908eba9
This commit is contained in:
schroda
2024-05-24 17:29:30 +02:00
parent 3492c103a7
commit 230acc23d5
2 changed files with 10 additions and 3 deletions

View File

@@ -288,7 +288,7 @@ export const MangaGrid: React.FC<IMangaGridProps> = ({
clearTimeout(timeout); clearTimeout(timeout);
}; };
}, [gridLayout]); }, [gridLayout]);
useEffect( useLayoutEffect(
() => () => { () => () => {
document.body.style.overflowY = 'auto'; document.body.style.overflowY = 'auto';
}, },

View File

@@ -6,11 +6,11 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. * file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/ */
import React, { useEffect } from 'react'; import React, { useEffect, useLayoutEffect } from 'react';
import { StringParam, useQueryParam } from 'use-query-params'; import { StringParam, useQueryParam } from 'use-query-params';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { TManga } from '@/typings'; import { TManga } from '@/typings';
import { useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext'; import { GridLayout, useLibraryOptionsContext } from '@/components/context/LibraryOptionsContext';
import { IMangaGridProps, MangaGrid } from '@/components/MangaGrid'; import { IMangaGridProps, MangaGrid } from '@/components/MangaGrid';
interface LibraryMangaGridProps interface LibraryMangaGridProps
@@ -37,6 +37,13 @@ export const LibraryMangaGrid: React.FC<LibraryMangaGridProps> = ({
window.scrollTo(0, 0); window.scrollTo(0, 0);
}, [query, unread, downloaded]); }, [query, unread, downloaded]);
useLayoutEffect(() => {
document.body.style.overflowY = options.gridLayout === GridLayout.List ? 'auto' : 'scroll';
return () => {
document.body.style.overflowY = 'auto';
};
}, []);
return ( return (
<MangaGrid <MangaGrid
{...gridProps} {...gridProps}