session-desktop/ts/components/settings/section/CategoryAppearance.tsx

56 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-10-22 01:39:05 +02:00
import React from 'react';
2021-10-22 01:39:05 +02:00
import useUpdate from 'react-use/lib/useUpdate';
import { SettingsKey } from '../../../data/settings-key';
2022-03-23 06:19:38 +01:00
import { isHideMenuBarSupported } from '../../../types/Settings';
import { useHasFollowSystemThemeEnabled } from '../../../state/selectors/settings';
import { ensureThemeConsistency } from '../../../themes/SessionTheme';
import { SessionToggleWithDescription } from '../SessionSettingListItem';
import { SettingsThemeSwitcher } from '../SettingsThemeSwitcher';
2021-10-22 01:39:05 +02:00
import { ZoomingSessionSlider } from '../ZoomingSessionSlider';
export const SettingsCategoryAppearance = (props: { hasPassword: boolean | null }) => {
const forceUpdate = useUpdate();
const isFollowSystemThemeEnabled = useHasFollowSystemThemeEnabled();
2021-10-22 01:39:05 +02:00
if (props.hasPassword !== null) {
const isHideMenuBarActive =
window.getSettingValue(SettingsKey.settingsMenuBar) === undefined
2021-10-22 01:39:05 +02:00
? true
: window.getSettingValue(SettingsKey.settingsMenuBar);
2021-10-22 01:39:05 +02:00
return (
<>
<SettingsThemeSwitcher />
<ZoomingSessionSlider />
2022-03-23 06:19:38 +01:00
{isHideMenuBarSupported() && (
2021-10-22 01:39:05 +02:00
<SessionToggleWithDescription
onClickToggle={() => {
window.toggleMenuBar();
forceUpdate();
}}
title={window.i18n('hideMenuBarTitle')}
description={window.i18n('hideMenuBarDescription')}
active={isHideMenuBarActive}
/>
)}
<SessionToggleWithDescription
// eslint-disable-next-line @typescript-eslint/no-misused-promises
onClickToggle={async () => {
const toggledValue = !isFollowSystemThemeEnabled;
await window.setSettingValue(SettingsKey.hasFollowSystemThemeEnabled, toggledValue);
if (!isFollowSystemThemeEnabled) {
await ensureThemeConsistency();
}
}}
title={window.i18n('matchThemeSystemSettingTitle')}
description={window.i18n('matchThemeSystemSettingDescription')}
active={isFollowSystemThemeEnabled}
dataTestId="enable-follow-system-theme"
/>
2021-10-22 01:39:05 +02:00
</>
);
}
return null;
};