Save appearance settings on server
- app theme - theme mode - pure black mode - manga grid item width
This commit is contained in:
@@ -25,7 +25,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/feedback/EmptyViewAbsoluteCentered.tsx';
|
import { EmptyViewAbsoluteCentered } from '@/modules/core/components/feedback/EmptyViewAbsoluteCentered.tsx';
|
||||||
import { LoadingPlaceholder } from '@/modules/core/components/feedback/LoadingPlaceholder.tsx';
|
import { LoadingPlaceholder } from '@/modules/core/components/feedback/LoadingPlaceholder.tsx';
|
||||||
import { MangaCard } from '@/modules/manga/components/cards/MangaCard.tsx';
|
import { MangaCard } from '@/modules/manga/components/cards/MangaCard.tsx';
|
||||||
import { useLocalStorage, useSessionStorage } from '@/modules/core/hooks/useStorage.tsx';
|
import { useSessionStorage } from '@/modules/core/hooks/useStorage.tsx';
|
||||||
import { SelectableCollectionReturnType } from '@/modules/collection/hooks/useSelectableCollection.ts';
|
import { SelectableCollectionReturnType } from '@/modules/collection/hooks/useSelectableCollection.ts';
|
||||||
import { DEFAULT_FULL_FAB_HEIGHT } from '@/modules/core/components/buttons/StyledFab.tsx';
|
import { DEFAULT_FULL_FAB_HEIGHT } from '@/modules/core/components/buttons/StyledFab.tsx';
|
||||||
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
||||||
@@ -34,6 +34,7 @@ import { MangaType } from '@/lib/graphql/generated/graphql.ts';
|
|||||||
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
|
import { useResizeObserver } from '@/modules/core/hooks/useResizeObserver.tsx';
|
||||||
import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
|
import { useNavBarContext } from '@/modules/navigation-bar/contexts/NavbarContext.tsx';
|
||||||
import { GridLayout } from '@/modules/core/Core.types.ts';
|
import { GridLayout } from '@/modules/core/Core.types.ts';
|
||||||
|
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||||
|
|
||||||
const GridContainer = React.forwardRef<HTMLDivElement, GridTypeMap['props']>(({ children, ...props }, ref) => (
|
const GridContainer = React.forwardRef<HTMLDivElement, GridTypeMap['props']>(({ children, ...props }, ref) => (
|
||||||
<Grid {...props} ref={ref} container spacing={1}>
|
<Grid {...props} ref={ref} container spacing={1}>
|
||||||
@@ -255,6 +256,9 @@ export const MangaGrid: React.FC<IMangaGridProps> = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const { navBarWidth } = useNavBarContext();
|
const { navBarWidth } = useNavBarContext();
|
||||||
|
const {
|
||||||
|
settings: { mangaGridItemWidth },
|
||||||
|
} = useMetadataServerSettings();
|
||||||
|
|
||||||
const gridRef = useRef<HTMLDivElement>(null);
|
const gridRef = useRef<HTMLDivElement>(null);
|
||||||
const gridWrapperRef = useRef<HTMLDivElement>(null);
|
const gridWrapperRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -262,10 +266,9 @@ export const MangaGrid: React.FC<IMangaGridProps> = ({
|
|||||||
const [dimensions, setDimensions] = useState(
|
const [dimensions, setDimensions] = useState(
|
||||||
gridWrapperRef.current?.offsetWidth ?? Math.max(0, document.documentElement.offsetWidth - navBarWidth),
|
gridWrapperRef.current?.offsetWidth ?? Math.max(0, document.documentElement.offsetWidth - navBarWidth),
|
||||||
);
|
);
|
||||||
const [gridItemWidth] = useLocalStorage<number>('ItemWidth', 300);
|
|
||||||
const GridItemContainer = useMemo(
|
const GridItemContainer = useMemo(
|
||||||
() => GridItemContainerWithDimension(dimensions, gridItemWidth, gridLayout),
|
() => GridItemContainerWithDimension(dimensions, mangaGridItemWidth, gridLayout),
|
||||||
[dimensions, gridItemWidth, gridLayout],
|
[dimensions, mangaGridItemWidth, gridLayout],
|
||||||
);
|
);
|
||||||
|
|
||||||
// always show vertical scrollbar to prevent https://github.com/Suwayomi/Suwayomi-WebUI/issues/758
|
// always show vertical scrollbar to prevent https://github.com/Suwayomi/Suwayomi-WebUI/issues/758
|
||||||
|
|||||||
@@ -89,6 +89,10 @@ const APP_METADATA_OBJECT: Record<AppMetadataKeys, undefined> = {
|
|||||||
showNsfw: undefined,
|
showNsfw: undefined,
|
||||||
shouldUseInfiniteScroll: undefined,
|
shouldUseInfiniteScroll: undefined,
|
||||||
shouldShowTransitionPage: undefined,
|
shouldShowTransitionPage: undefined,
|
||||||
|
appTheme: undefined,
|
||||||
|
themeMode: undefined,
|
||||||
|
shouldUsePureBlackMode: undefined,
|
||||||
|
mangaGridItemWidth: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const VALID_APP_METADATA_KEYS = Object.keys(APP_METADATA_OBJECT);
|
export const VALID_APP_METADATA_KEYS = Object.keys(APP_METADATA_OBJECT);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export interface IMetadataMigration {
|
|||||||
* Otherwise, all metadata keys will get migrated.
|
* Otherwise, all metadata keys will get migrated.
|
||||||
*/
|
*/
|
||||||
key?: string;
|
key?: string;
|
||||||
oldValue: string | RegExp;
|
oldValue: string | RegExp | undefined;
|
||||||
newValue: string | ((oldValue: string) => string);
|
newValue: string | ((oldValue: string) => string);
|
||||||
}[];
|
}[];
|
||||||
keys?: { oldKey: string; newKey: string }[];
|
keys?: { oldKey: string; newKey: string }[];
|
||||||
|
|||||||
@@ -83,7 +83,10 @@ const applyMetadataValueMigration = (meta: Metadata, migration: IMetadataMigrati
|
|||||||
|
|
||||||
metadataValueChanges.forEach(({ key, oldValue, newValue }) => {
|
metadataValueChanges.forEach(({ key, oldValue, newValue }) => {
|
||||||
const migrateValue = (metaKey: string) => {
|
const migrateValue = (metaKey: string) => {
|
||||||
if (meta[metaKey].match(oldValue)) {
|
if (
|
||||||
|
(oldValue === undefined && meta[metaKey] === oldValue) ||
|
||||||
|
(oldValue !== undefined && meta[metaKey].match(oldValue))
|
||||||
|
) {
|
||||||
migratedMetadata[metaKey] = typeof newValue === 'function' ? newValue(meta[metaKey]) : newValue;
|
migratedMetadata[metaKey] = typeof newValue === 'function' ? newValue(meta[metaKey]) : newValue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ import { CacheProvider } from '@emotion/react';
|
|||||||
import { ThemeProvider } from '@mui/material/styles';
|
import { ThemeProvider } from '@mui/material/styles';
|
||||||
import Box, { BoxProps } from '@mui/material/Box';
|
import Box, { BoxProps } from '@mui/material/Box';
|
||||||
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
import { getTheme } from '@/modules/theme/services/AppThemes.ts';
|
||||||
import { AppThemes, getTheme } from '@/modules/theme/services/AppThemes.ts';
|
|
||||||
import { ThemeMode } from '@/modules/theme/contexts/AppThemeContext.tsx';
|
|
||||||
import { createTheme } from '@/modules/theme/services/ThemeCreator.ts';
|
import { createTheme } from '@/modules/theme/services/ThemeCreator.ts';
|
||||||
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
import { ReaderService } from '@/modules/reader/services/ReaderService.ts';
|
||||||
import { DIRECTION_TO_CACHE } from '@/modules/theme/ThemeDirectionCache.ts';
|
import { DIRECTION_TO_CACHE } from '@/modules/theme/ThemeDirectionCache.ts';
|
||||||
@@ -25,17 +23,13 @@ const BaseReaderProgressBarDirectionWrapper = forwardRef<
|
|||||||
direction: ReturnType<typeof ReaderService.useGetThemeDirection>;
|
direction: ReturnType<typeof ReaderService.useGetThemeDirection>;
|
||||||
}
|
}
|
||||||
>(({ direction, ...boxProps }, ref) => {
|
>(({ direction, ...boxProps }, ref) => {
|
||||||
const [appTheme] = useLocalStorage<AppThemes>('appTheme', 'default');
|
|
||||||
const [themeMode] = useLocalStorage<ThemeMode>('themeMode', ThemeMode.SYSTEM);
|
|
||||||
const [pureBlackMode] = useLocalStorage<boolean>('pureBlackMode', false);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
settings: { customThemes },
|
settings: { customThemes, appTheme, themeMode, shouldUsePureBlackMode },
|
||||||
} = useMetadataServerSettings();
|
} = useMetadataServerSettings();
|
||||||
|
|
||||||
const readerTheme = useMemo(
|
const readerTheme = useMemo(
|
||||||
() => createTheme(themeMode, getTheme(appTheme, customThemes), pureBlackMode, direction),
|
() => createTheme(themeMode, getTheme(appTheme, customThemes), shouldUsePureBlackMode, direction),
|
||||||
[themeMode, appTheme, customThemes, pureBlackMode, direction],
|
[themeMode, appTheme, customThemes, shouldUsePureBlackMode, direction],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { DEFAULT_SORT_SETTINGS } from '@/modules/migration/Migration.constants.t
|
|||||||
import { MetadataServerSettings } from '@/modules/settings/Settings.types.ts';
|
import { MetadataServerSettings } from '@/modules/settings/Settings.types.ts';
|
||||||
import { GridLayout } from '@/modules/core/Core.types.ts';
|
import { GridLayout } from '@/modules/core/Core.types.ts';
|
||||||
import { getDefaultLanguages } from '@/modules/core/utils/Languages.ts';
|
import { getDefaultLanguages } from '@/modules/core/utils/Languages.ts';
|
||||||
|
import { ThemeMode } from '@/modules/theme/contexts/AppThemeContext.tsx';
|
||||||
|
|
||||||
export const SERVER_SETTINGS_METADATA_DEFAULT: MetadataServerSettings = {
|
export const SERVER_SETTINGS_METADATA_DEFAULT: MetadataServerSettings = {
|
||||||
// downloads
|
// downloads
|
||||||
@@ -56,7 +57,11 @@ export const SERVER_SETTINGS_METADATA_DEFAULT: MetadataServerSettings = {
|
|||||||
serverInformAvailableUpdate: true,
|
serverInformAvailableUpdate: true,
|
||||||
|
|
||||||
// themes
|
// themes
|
||||||
|
appTheme: 'default',
|
||||||
|
themeMode: ThemeMode.SYSTEM,
|
||||||
|
shouldUsePureBlackMode: false,
|
||||||
customThemes: {},
|
customThemes: {},
|
||||||
mangaThumbnailBackdrop: true,
|
mangaThumbnailBackdrop: true,
|
||||||
mangaDynamicColorSchemes: true,
|
mangaDynamicColorSchemes: true,
|
||||||
|
mangaGridItemWidth: 300,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import { ThemeMode, useAppThemeContext } from '@/modules/theme/contexts/AppTheme
|
|||||||
import { Select } from '@/modules/core/components/inputs/Select.tsx';
|
import { Select } from '@/modules/core/components/inputs/Select.tsx';
|
||||||
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
|
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
|
||||||
import { NumberSetting } from '@/modules/core/components/settings/NumberSetting.tsx';
|
import { NumberSetting } from '@/modules/core/components/settings/NumberSetting.tsx';
|
||||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
|
||||||
import { I18nResourceCode, i18nResources } from '@/i18n';
|
import { I18nResourceCode, i18nResources } from '@/i18n';
|
||||||
import { languageCodeToName } from '@/modules/core/utils/Languages.ts';
|
import { languageCodeToName } from '@/modules/core/utils/Languages.ts';
|
||||||
import { ThemeList } from '@/modules/theme/components/ThemeList.tsx';
|
import { ThemeList } from '@/modules/theme/components/ThemeList.tsx';
|
||||||
@@ -35,17 +34,18 @@ import { MetadataThemeSettings } from '@/modules/theme/AppTheme.types.ts';
|
|||||||
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
||||||
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
import { AppStorage } from '@/lib/storage/AppStorage.ts';
|
||||||
import { useAppTitle } from '@/modules/navigation-bar/hooks/useAppTitle.ts';
|
import { useAppTitle } from '@/modules/navigation-bar/hooks/useAppTitle.ts';
|
||||||
|
import { SERVER_SETTINGS_METADATA_DEFAULT } from '@/modules/settings/Settings.constants.ts';
|
||||||
|
|
||||||
export const Appearance = () => {
|
export const Appearance = () => {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const { themeMode, setThemeMode, pureBlackMode, setPureBlackMode } = useAppThemeContext();
|
const { themeMode, setThemeMode, shouldUsePureBlackMode, setShouldUsePureBlackMode } = useAppThemeContext();
|
||||||
const { mode, setMode } = useColorScheme();
|
const { mode, setMode } = useColorScheme();
|
||||||
const actualThemeMode = (mode ?? themeMode) as ThemeMode;
|
const actualThemeMode = (mode ?? themeMode) as ThemeMode;
|
||||||
|
|
||||||
useAppTitle(t('settings.appearance.title'));
|
useAppTitle(t('settings.appearance.title'));
|
||||||
|
|
||||||
const {
|
const {
|
||||||
settings,
|
settings: { mangaThumbnailBackdrop, mangaDynamicColorSchemes, mangaGridItemWidth },
|
||||||
request: { loading, error, refetch },
|
request: { loading, error, refetch },
|
||||||
} = useMetadataServerSettings();
|
} = useMetadataServerSettings();
|
||||||
const updateMetadataSetting = createUpdateMetadataServerSettings<keyof MetadataThemeSettings>((e) =>
|
const updateMetadataSetting = createUpdateMetadataServerSettings<keyof MetadataThemeSettings>((e) =>
|
||||||
@@ -54,9 +54,6 @@ export const Appearance = () => {
|
|||||||
|
|
||||||
const isDarkMode = MediaQuery.getThemeMode() === ThemeMode.DARK;
|
const isDarkMode = MediaQuery.getThemeMode() === ThemeMode.DARK;
|
||||||
|
|
||||||
const DEFAULT_ITEM_WIDTH = 300;
|
|
||||||
const [itemWidth, setItemWidth] = useLocalStorage<number>('ItemWidth', DEFAULT_ITEM_WIDTH);
|
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <LoadingPlaceholder />;
|
return <LoadingPlaceholder />;
|
||||||
}
|
}
|
||||||
@@ -107,7 +104,10 @@ export const Appearance = () => {
|
|||||||
{isDarkMode && (
|
{isDarkMode && (
|
||||||
<ListItem>
|
<ListItem>
|
||||||
<ListItemText primary={t('settings.appearance.theme.pure_black_mode')} />
|
<ListItemText primary={t('settings.appearance.theme.pure_black_mode')} />
|
||||||
<Switch checked={pureBlackMode} onChange={(_, enabled) => setPureBlackMode(enabled)} />
|
<Switch
|
||||||
|
checked={shouldUsePureBlackMode}
|
||||||
|
onChange={(_, enabled) => setShouldUsePureBlackMode(enabled)}
|
||||||
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
)}
|
)}
|
||||||
<List
|
<List
|
||||||
@@ -152,15 +152,15 @@ export const Appearance = () => {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
<NumberSetting
|
<NumberSetting
|
||||||
settingTitle={t('settings.label.manga_item_width')}
|
settingTitle={t('settings.label.manga_item_width')}
|
||||||
settingValue={`px: ${itemWidth}`}
|
settingValue={`px: ${mangaGridItemWidth}`}
|
||||||
value={itemWidth}
|
value={mangaGridItemWidth}
|
||||||
defaultValue={DEFAULT_ITEM_WIDTH}
|
defaultValue={SERVER_SETTINGS_METADATA_DEFAULT.mangaGridItemWidth}
|
||||||
minValue={100}
|
minValue={100}
|
||||||
maxValue={1000}
|
maxValue={1000}
|
||||||
stepSize={10}
|
stepSize={10}
|
||||||
valueUnit="px"
|
valueUnit="px"
|
||||||
showSlider
|
showSlider
|
||||||
handleUpdate={setItemWidth}
|
handleUpdate={(width) => updateMetadataSetting('mangaGridItemWidth', width)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ListItem>
|
<ListItem>
|
||||||
@@ -170,7 +170,7 @@ export const Appearance = () => {
|
|||||||
/>
|
/>
|
||||||
<Switch
|
<Switch
|
||||||
edge="end"
|
edge="end"
|
||||||
checked={settings.mangaThumbnailBackdrop}
|
checked={mangaThumbnailBackdrop}
|
||||||
onChange={(e) => updateMetadataSetting('mangaThumbnailBackdrop', e.target.checked)}
|
onChange={(e) => updateMetadataSetting('mangaThumbnailBackdrop', e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
@@ -182,7 +182,7 @@ export const Appearance = () => {
|
|||||||
/>
|
/>
|
||||||
<Switch
|
<Switch
|
||||||
edge="end"
|
edge="end"
|
||||||
checked={settings.mangaDynamicColorSchemes}
|
checked={mangaDynamicColorSchemes}
|
||||||
onChange={(e) => updateMetadataSetting('mangaDynamicColorSchemes', e.target.checked)}
|
onChange={(e) => updateMetadataSetting('mangaDynamicColorSchemes', e.target.checked)}
|
||||||
/>
|
/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
|
|||||||
@@ -6,10 +6,15 @@
|
|||||||
* 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 { AppTheme } from '@/modules/theme/services/AppThemes.ts';
|
import { AppTheme, AppThemes } from '@/modules/theme/services/AppThemes.ts';
|
||||||
|
import { ThemeMode } from '@/modules/theme/contexts/AppThemeContext.tsx';
|
||||||
|
|
||||||
export type MetadataThemeSettings = {
|
export type MetadataThemeSettings = {
|
||||||
|
appTheme: AppThemes;
|
||||||
|
themeMode: ThemeMode;
|
||||||
|
shouldUsePureBlackMode: boolean;
|
||||||
customThemes: Record<string, AppTheme>;
|
customThemes: Record<string, AppTheme>;
|
||||||
mangaThumbnailBackdrop: boolean;
|
mangaThumbnailBackdrop: boolean;
|
||||||
mangaDynamicColorSchemes: boolean;
|
mangaDynamicColorSchemes: boolean;
|
||||||
|
mangaGridItemWidth: number;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -37,15 +37,15 @@ export const ThemePreview = ({ appTheme, onDelete }: { appTheme: AppTheme; onDel
|
|||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { themeMode, setAppTheme, appTheme: activeAppTheme, pureBlackMode } = useAppThemeContext();
|
const { themeMode, setAppTheme, appTheme: activeAppTheme, shouldUsePureBlackMode } = useAppThemeContext();
|
||||||
|
|
||||||
const popupState = usePopupState({ variant: 'popover', popupId: `theme-edit-dialog-${appTheme.id}` });
|
const popupState = usePopupState({ variant: 'popover', popupId: `theme-edit-dialog-${appTheme.id}` });
|
||||||
|
|
||||||
const isSelected = appTheme.id === activeAppTheme;
|
const isSelected = appTheme.id === activeAppTheme;
|
||||||
|
|
||||||
const muiTheme = useMemo(
|
const muiTheme = useMemo(
|
||||||
() => createTheme(themeMode, appTheme, pureBlackMode),
|
() => createTheme(themeMode, appTheme, shouldUsePureBlackMode),
|
||||||
[appTheme, themeMode, pureBlackMode],
|
[appTheme, themeMode, shouldUsePureBlackMode],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -19,11 +19,11 @@ export enum ThemeMode {
|
|||||||
|
|
||||||
export type TAppThemeContext = {
|
export type TAppThemeContext = {
|
||||||
appTheme: AppThemes;
|
appTheme: AppThemes;
|
||||||
setAppTheme: React.Dispatch<React.SetStateAction<AppThemes>>;
|
setAppTheme: (theme: AppThemes) => void;
|
||||||
themeMode: ThemeMode;
|
themeMode: ThemeMode;
|
||||||
setThemeMode: React.Dispatch<React.SetStateAction<ThemeMode>>;
|
setThemeMode: (mode: ThemeMode) => void;
|
||||||
pureBlackMode: boolean;
|
shouldUsePureBlackMode: boolean;
|
||||||
setPureBlackMode: React.Dispatch<React.SetStateAction<boolean>>;
|
setShouldUsePureBlackMode: (value: boolean) => void;
|
||||||
dynamicColor: (NonNullableProperties<Palette> & { average: FastAverageColorResult }) | null;
|
dynamicColor: (NonNullableProperties<Palette> & { average: FastAverageColorResult }) | null;
|
||||||
setDynamicColor: React.Dispatch<
|
setDynamicColor: React.Dispatch<
|
||||||
React.SetStateAction<(NonNullableProperties<Palette> & { average: FastAverageColorResult }) | null>
|
React.SetStateAction<(NonNullableProperties<Palette> & { average: FastAverageColorResult }) | null>
|
||||||
@@ -35,8 +35,8 @@ export const AppThemeContext = React.createContext<TAppThemeContext>({
|
|||||||
setAppTheme: (): void => {},
|
setAppTheme: (): void => {},
|
||||||
themeMode: ThemeMode.SYSTEM,
|
themeMode: ThemeMode.SYSTEM,
|
||||||
setThemeMode: (): void => {},
|
setThemeMode: (): void => {},
|
||||||
pureBlackMode: false,
|
shouldUsePureBlackMode: false,
|
||||||
setPureBlackMode: (): void => {},
|
setShouldUsePureBlackMode: (): void => {},
|
||||||
dynamicColor: null,
|
dynamicColor: null,
|
||||||
setDynamicColor: (): void => {},
|
setDynamicColor: (): void => {},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,21 +12,22 @@ import { CacheProvider } from '@emotion/react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { AppThemeContext, TAppThemeContext, ThemeMode } from '@/modules/theme/contexts/AppThemeContext.tsx';
|
import { AppThemeContext, TAppThemeContext, ThemeMode } from '@/modules/theme/contexts/AppThemeContext.tsx';
|
||||||
import { DIRECTION_TO_CACHE } from '@/modules/theme/ThemeDirectionCache.ts';
|
import { DIRECTION_TO_CACHE } from '@/modules/theme/ThemeDirectionCache.ts';
|
||||||
import { useMetadataServerSettings } from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
import {
|
||||||
|
createUpdateMetadataServerSettings,
|
||||||
|
useMetadataServerSettings,
|
||||||
|
} from '@/modules/settings/services/ServerSettingsMetadata.ts';
|
||||||
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
|
import { MediaQuery } from '@/modules/core/utils/MediaQuery.tsx';
|
||||||
import { useLocalStorage } from '@/modules/core/hooks/useStorage.tsx';
|
import { getTheme } from '@/modules/theme/services/AppThemes.ts';
|
||||||
import { AppThemes, getTheme } from '@/modules/theme/services/AppThemes.ts';
|
|
||||||
import { createAndSetTheme } from '@/modules/theme/services/ThemeCreator.ts';
|
import { createAndSetTheme } from '@/modules/theme/services/ThemeCreator.ts';
|
||||||
|
import { makeToast } from '@/modules/core/utils/Toast.ts';
|
||||||
|
import { getErrorMessage } from '@/lib/HelperFunctions.ts';
|
||||||
|
|
||||||
export const AppThemeContextProvider = ({ children }: { children: ReactNode }) => {
|
export const AppThemeContextProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const { i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
const { mode } = useColorScheme();
|
const { mode } = useColorScheme();
|
||||||
const {
|
const {
|
||||||
settings: { customThemes },
|
settings: { appTheme, themeMode, shouldUsePureBlackMode, customThemes },
|
||||||
} = useMetadataServerSettings();
|
} = useMetadataServerSettings();
|
||||||
const [appTheme, setAppTheme] = useLocalStorage<AppThemes>('appTheme', 'default');
|
|
||||||
const [themeMode, setThemeMode] = useLocalStorage<ThemeMode>('themeMode', ThemeMode.SYSTEM);
|
|
||||||
const [pureBlackMode, setPureBlackMode] = useLocalStorage<boolean>('pureBlackMode', false);
|
|
||||||
|
|
||||||
const directionRef = useRef<Direction>('ltr');
|
const directionRef = useRef<Direction>('ltr');
|
||||||
|
|
||||||
@@ -36,18 +37,23 @@ export const AppThemeContextProvider = ({ children }: { children: ReactNode }) =
|
|||||||
const actualThemeMode = mode ?? themeMode ?? 'dark';
|
const actualThemeMode = mode ?? themeMode ?? 'dark';
|
||||||
const currentDirection = i18n.dir();
|
const currentDirection = i18n.dir();
|
||||||
|
|
||||||
|
const updateSetting = createUpdateMetadataServerSettings<'appTheme' | 'themeMode' | 'shouldUsePureBlackMode'>((e) =>
|
||||||
|
makeToast(t('global.error.label.failed_to_save_changes'), 'error', getErrorMessage(e)),
|
||||||
|
);
|
||||||
|
|
||||||
const appThemeContext = useMemo(
|
const appThemeContext = useMemo(
|
||||||
() => ({
|
() =>
|
||||||
appTheme,
|
({
|
||||||
setAppTheme,
|
appTheme,
|
||||||
themeMode,
|
setAppTheme: (value) => updateSetting('appTheme', value),
|
||||||
setThemeMode,
|
themeMode,
|
||||||
pureBlackMode,
|
setThemeMode: (value) => updateSetting('themeMode', value),
|
||||||
setPureBlackMode,
|
shouldUsePureBlackMode,
|
||||||
dynamicColor,
|
setShouldUsePureBlackMode: (value) => updateSetting('shouldUsePureBlackMode', value),
|
||||||
setDynamicColor,
|
dynamicColor,
|
||||||
}),
|
setDynamicColor,
|
||||||
[themeMode, pureBlackMode, appTheme, dynamicColor],
|
}) satisfies TAppThemeContext,
|
||||||
|
[themeMode, shouldUsePureBlackMode, appTheme, dynamicColor],
|
||||||
);
|
);
|
||||||
|
|
||||||
const theme = useMemo(
|
const theme = useMemo(
|
||||||
@@ -55,11 +61,19 @@ export const AppThemeContextProvider = ({ children }: { children: ReactNode }) =
|
|||||||
createAndSetTheme(
|
createAndSetTheme(
|
||||||
actualThemeMode as ThemeMode,
|
actualThemeMode as ThemeMode,
|
||||||
getTheme(appTheme, customThemes),
|
getTheme(appTheme, customThemes),
|
||||||
pureBlackMode,
|
shouldUsePureBlackMode,
|
||||||
currentDirection,
|
currentDirection,
|
||||||
dynamicColor,
|
dynamicColor,
|
||||||
),
|
),
|
||||||
[actualThemeMode, currentDirection, systemThemeMode, pureBlackMode, appTheme, customThemes, dynamicColor],
|
[
|
||||||
|
actualThemeMode,
|
||||||
|
currentDirection,
|
||||||
|
systemThemeMode,
|
||||||
|
shouldUsePureBlackMode,
|
||||||
|
appTheme,
|
||||||
|
customThemes,
|
||||||
|
dynamicColor,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user