2024-09-04 23:44:32 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { useContext, useEffect } from 'react';
|
|
|
|
|
import List from '@mui/material/List';
|
|
|
|
|
import ListItem from '@mui/material/ListItem';
|
|
|
|
|
import ListItemText from '@mui/material/ListItemText';
|
2024-09-04 23:46:04 +02:00
|
|
|
import MenuItem from '@mui/material/MenuItem';
|
|
|
|
|
import ListSubheader from '@mui/material/ListSubheader';
|
2024-09-05 00:08:23 +02:00
|
|
|
import Switch from '@mui/material/Switch';
|
2024-09-04 23:44:32 +02:00
|
|
|
import { NavBarContext } from '@/components/context/NavbarContext.tsx';
|
2024-09-04 23:46:04 +02:00
|
|
|
import { ThemeMode, ThemeModeContext } from '@/components/context/ThemeModeContext.tsx';
|
|
|
|
|
import { Select } from '@/components/atoms/Select.tsx';
|
2024-09-05 00:08:23 +02:00
|
|
|
import { MediaQuery } from '@/lib/ui/MediaQuery.tsx';
|
2024-09-04 23:44:32 +02:00
|
|
|
|
|
|
|
|
export const Appearance = () => {
|
|
|
|
|
const { t } = useTranslation();
|
2024-09-05 00:08:23 +02:00
|
|
|
const { themeMode, setThemeMode, pureBlackMode, setPureBlackMode } = useContext(ThemeModeContext);
|
|
|
|
|
const isDarkMode = MediaQuery.getThemeMode() === ThemeMode.DARK;
|
2024-09-04 23:44:32 +02:00
|
|
|
|
|
|
|
|
const { setTitle, setAction } = useContext(NavBarContext);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setTitle(t('settings.appearance.title'));
|
|
|
|
|
setAction(null);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
setTitle('');
|
|
|
|
|
setAction(null);
|
|
|
|
|
};
|
|
|
|
|
}, [t]);
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-04 23:46:04 +02:00
|
|
|
<List
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="appearance-theme">
|
|
|
|
|
{t('settings.appearance.theme')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
2024-09-04 23:44:32 +02:00
|
|
|
<ListItem>
|
2024-09-04 23:46:04 +02:00
|
|
|
<ListItemText primary={t('settings.appearance.device_theme')} />
|
|
|
|
|
<Select<ThemeMode> value={themeMode} onChange={(e) => setThemeMode(e.target.value as ThemeMode)}>
|
|
|
|
|
<MenuItem key={ThemeMode.SYSTEM} value={ThemeMode.SYSTEM}>
|
|
|
|
|
System
|
|
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem key={ThemeMode.DARK} value={ThemeMode.DARK}>
|
|
|
|
|
Dark
|
|
|
|
|
</MenuItem>
|
|
|
|
|
<MenuItem key={ThemeMode.LIGHT} value={ThemeMode.LIGHT}>
|
|
|
|
|
Light
|
|
|
|
|
</MenuItem>
|
|
|
|
|
</Select>
|
2024-09-04 23:44:32 +02:00
|
|
|
</ListItem>
|
2024-09-05 00:08:23 +02:00
|
|
|
{isDarkMode && (
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText primary={t('settings.appearance.pure_black_mode')} />
|
|
|
|
|
<Switch checked={pureBlackMode} onChange={(_, enabled) => setPureBlackMode(enabled)} />
|
|
|
|
|
</ListItem>
|
|
|
|
|
)}
|
2024-09-04 23:44:32 +02:00
|
|
|
</List>
|
|
|
|
|
);
|
|
|
|
|
};
|