2024-09-28 03:24:16 +02:00
|
|
|
/*
|
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-01-02 21:25:35 +01:00
|
|
|
import { forwardRef, useMemo } from 'react';
|
2024-09-28 03:24:16 +02:00
|
|
|
import { CacheProvider } from '@emotion/react';
|
|
|
|
|
import { ThemeProvider } from '@mui/material/styles';
|
2025-01-02 21:25:35 +01:00
|
|
|
import Box, { BoxProps } from '@mui/material/Box';
|
2024-09-28 03:24:16 +02:00
|
|
|
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
2025-05-17 21:04:44 +02:00
|
|
|
import { getTheme } from '@/modules/theme/services/AppThemes.ts';
|
2024-12-11 13:59:50 +01:00
|
|
|
import { createTheme } from '@/modules/theme/services/ThemeCreator.ts';
|
2024-09-28 03:24:16 +02:00
|
|
|
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
|
|
|
|
import { DIRECTION_TO_CACHE } from '@/modules/theme/ThemeDirectionCache.ts';
|
2024-12-21 03:46:55 +01:00
|
|
|
import { withPropsFrom } from '@/modules/core/hoc/withPropsFrom.tsx';
|
2024-09-28 03:24:16 +02:00
|
|
|
|
2025-01-02 21:25:35 +01:00
|
|
|
const BaseReaderProgressBarDirectionWrapper = forwardRef<
|
|
|
|
|
HTMLElement,
|
|
|
|
|
BoxProps & {
|
|
|
|
|
direction: ReturnType<typeof ReaderService.useGetThemeDirection>;
|
|
|
|
|
}
|
|
|
|
|
>(({ direction, ...boxProps }, ref) => {
|
2024-09-28 03:24:16 +02:00
|
|
|
const {
|
2025-05-17 21:04:44 +02:00
|
|
|
settings: { customThemes, appTheme, themeMode, shouldUsePureBlackMode },
|
2024-09-28 03:24:16 +02:00
|
|
|
} = useMetadataServerSettings();
|
|
|
|
|
|
|
|
|
|
const readerTheme = useMemo(
|
2025-05-17 21:04:44 +02:00
|
|
|
() => createTheme(themeMode, getTheme(appTheme, customThemes), shouldUsePureBlackMode, direction),
|
|
|
|
|
[themeMode, appTheme, customThemes, shouldUsePureBlackMode, direction],
|
2024-09-28 03:24:16 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<CacheProvider value={DIRECTION_TO_CACHE[direction]}>
|
|
|
|
|
<ThemeProvider theme={readerTheme}>
|
2025-01-02 21:25:35 +01:00
|
|
|
<Box {...boxProps} ref={ref} dir={direction} />
|
2024-09-28 03:24:16 +02:00
|
|
|
</ThemeProvider>
|
|
|
|
|
</CacheProvider>
|
|
|
|
|
);
|
2025-01-02 21:25:35 +01:00
|
|
|
});
|
2024-12-21 03:46:55 +01:00
|
|
|
|
|
|
|
|
export const ReaderProgressBarDirectionWrapper = withPropsFrom(
|
|
|
|
|
BaseReaderProgressBarDirectionWrapper,
|
|
|
|
|
[() => ({ direction: ReaderService.useGetThemeDirection() })],
|
|
|
|
|
['direction'],
|
|
|
|
|
);
|