Reader progress bars
This commit is contained in:
@@ -12,10 +12,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { QueryParamProvider } from 'use-query-params';
|
||||
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { CacheProvider, EmotionCache } from '@emotion/react';
|
||||
import createCache from '@emotion/cache';
|
||||
import { prefixer } from 'stylis';
|
||||
import rtlPlugin from 'stylis-plugin-rtl';
|
||||
import { CacheProvider } from '@emotion/react';
|
||||
import { SnackbarProvider } from 'notistack';
|
||||
import { createAndSetTheme } from '@/theme.tsx';
|
||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
||||
@@ -27,21 +24,12 @@ import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
|
||||
import { AppThemes, getTheme } from '@/modules/theme/services/AppThemes.ts';
|
||||
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||
import { ReaderContextProvider } from '@/modules/reader/contexts/ReaderContextProvider.tsx';
|
||||
import { DIRECTION_TO_CACHE } from '@/modules/theme/ThemeDirectionCache.ts';
|
||||
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
const directionToCache: Record<Direction, EmotionCache> = {
|
||||
ltr: createCache({
|
||||
key: 'muiltr',
|
||||
}),
|
||||
rtl: createCache({
|
||||
key: 'muirtl',
|
||||
stylisPlugins: [prefixer, rtlPlugin],
|
||||
}),
|
||||
};
|
||||
|
||||
export const AppContext: React.FC<Props> = ({ children }) => {
|
||||
const directionRef = useRef<Direction>('ltr');
|
||||
const { i18n } = useTranslation();
|
||||
@@ -88,7 +76,7 @@ export const AppContext: React.FC<Props> = ({ children }) => {
|
||||
return (
|
||||
<Router>
|
||||
<StyledEngineProvider injectFirst>
|
||||
<CacheProvider value={directionToCache[currentDirection]}>
|
||||
<CacheProvider value={DIRECTION_TO_CACHE[currentDirection]}>
|
||||
<ThemeProvider theme={theme}>
|
||||
<ThemeModeContext.Provider value={darkThemeContext}>
|
||||
<QueryParamProvider adapter={ReactRouter6Adapter}>
|
||||
|
||||
15
src/modules/core/utils/ApplyStyles.ts
Normal file
15
src/modules/core/utils/ApplyStyles.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* 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/.
|
||||
*/
|
||||
|
||||
import { Theme } from '@mui/material/styles';
|
||||
|
||||
// use CSSObject instead of SxProps<Theme> because this completely fucks over typescript by causing an out of memory error during compilation
|
||||
type CSSObject = ReturnType<Theme['applyStyles']>;
|
||||
|
||||
const emptyStyle = {};
|
||||
export const applyStyles = (isActive: boolean, styling: CSSObject): CSSObject => (isActive ? styling : emptyStyle);
|
||||
@@ -27,18 +27,45 @@ export class MediaQuery {
|
||||
return this.useIsBelowWidth('sm');
|
||||
}
|
||||
|
||||
static useGetScrollbarSize(type: 'height' | 'width'): number {
|
||||
private static getScrollbarSize(type: 'height' | 'width'): number {
|
||||
const outer = document.createElement('div');
|
||||
outer.style.visibility = 'hidden';
|
||||
outer.style.overflow = 'scroll';
|
||||
document.body.appendChild(outer);
|
||||
|
||||
const inner = document.createElement('div');
|
||||
inner.style.width = '100%';
|
||||
inner.style.height = '100%';
|
||||
outer.appendChild(inner);
|
||||
|
||||
const width = outer.offsetWidth - inner.offsetWidth;
|
||||
const height = outer.offsetHeight - inner.offsetHeight;
|
||||
|
||||
outer.parentNode?.removeChild(outer);
|
||||
|
||||
return type === 'height' ? height : width;
|
||||
}
|
||||
|
||||
static useGetScrollbarSize(
|
||||
type: 'height' | 'width',
|
||||
element: HTMLElement | null = document.documentElement,
|
||||
): number {
|
||||
const [scrollbarSize, setScrollbarSize] = useState(0);
|
||||
|
||||
useResizeObserver(
|
||||
document.documentElement,
|
||||
element,
|
||||
useCallback(() => {
|
||||
const height = window.innerHeight - document.documentElement.clientHeight;
|
||||
const width = window.innerWidth - document.documentElement.clientWidth;
|
||||
const size = type === 'height' ? height : width;
|
||||
const hasYScrollbar = !!(element!.scrollHeight - element!.clientHeight);
|
||||
const hasXScrollbar = !!(element!.scrollWidth - element!.clientWidth);
|
||||
|
||||
setScrollbarSize(size);
|
||||
}, []),
|
||||
const hasScrollbar = (type === 'height' && hasYScrollbar) || (type === 'width' && hasXScrollbar);
|
||||
if (hasScrollbar) {
|
||||
setScrollbarSize(this.getScrollbarSize(type));
|
||||
return;
|
||||
}
|
||||
|
||||
setScrollbarSize(0);
|
||||
}, [element]),
|
||||
);
|
||||
|
||||
return scrollbarSize;
|
||||
|
||||
Reference in New Issue
Block a user