158 lines
5.5 KiB
JavaScript
158 lines
5.5 KiB
JavaScript
// @flow
|
|
import { SETTINGS_GRP } from 'constants/settings';
|
|
import React from 'react';
|
|
import * as SETTINGS from 'constants/settings';
|
|
import Card from 'component/common/card';
|
|
import { FormField } from 'component/common/form';
|
|
import Button from 'component/button';
|
|
import FileSelector from 'component/common/file-selector';
|
|
import HomepageSelector from 'component/homepageSelector';
|
|
import SettingLanguage from 'component/settingLanguage';
|
|
import SettingsRow from 'component/settingsRow';
|
|
import ThemeSelector from 'component/themeSelector';
|
|
// $FlowFixMe
|
|
import homepages from 'homepages';
|
|
|
|
type Props = {
|
|
disableBackground: boolean,
|
|
backgroundMode: string,
|
|
customBackgroundImage: string,
|
|
clock24h: boolean,
|
|
searchInLanguage: boolean,
|
|
hideBalance: boolean,
|
|
setClientSetting: (string, boolean | string | number) => void,
|
|
setSearchInLanguage: (boolean) => void,
|
|
};
|
|
|
|
export default function SettingAppearance(props: Props) {
|
|
const {
|
|
clock24h,
|
|
disableBackground,
|
|
backgroundMode,
|
|
customBackgroundImage,
|
|
searchInLanguage,
|
|
hideBalance,
|
|
setClientSetting,
|
|
setSearchInLanguage,
|
|
} = props;
|
|
|
|
function handleBackgroundImageChosen(fileWithPath: FileWithPath) {
|
|
const file = fileWithPath && fileWithPath.file;
|
|
if (!file) return;
|
|
|
|
const reader = new FileReader();
|
|
reader.onload = () => {
|
|
if (reader.result) {
|
|
setClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE, reader.result.toString());
|
|
}
|
|
};
|
|
reader.readAsDataURL(file);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="card__title-section">
|
|
<h2 className="card__title">{__('Appearance')}</h2>
|
|
</div>
|
|
<Card
|
|
id={SETTINGS_GRP.APPEARANCE}
|
|
isBodyList
|
|
body={
|
|
<>
|
|
{homepages && Object.keys(homepages).length > 1 && (
|
|
<SettingsRow title={__('Homepage')} subtitle={__('Tailor your experience.')}>
|
|
<HomepageSelector />
|
|
</SettingsRow>
|
|
)}
|
|
|
|
<SettingsRow title={__('Language')} subtitle={__(HELP.LANGUAGE)}>
|
|
<SettingLanguage />
|
|
</SettingsRow>
|
|
|
|
<SettingsRow title={__('Search only in the selected language by default')}>
|
|
<FormField
|
|
name="search-in-language"
|
|
type="checkbox"
|
|
checked={searchInLanguage}
|
|
onChange={() => setSearchInLanguage(!searchInLanguage)}
|
|
/>
|
|
</SettingsRow>
|
|
|
|
<SettingsRow title={__('Theme')}>
|
|
<ThemeSelector />
|
|
</SettingsRow>
|
|
|
|
<SettingsRow title={__('24-hour clock')}>
|
|
<FormField
|
|
type="checkbox"
|
|
name="clock24h"
|
|
onChange={() => setClientSetting(SETTINGS.CLOCK_24H, !clock24h)}
|
|
checked={clock24h}
|
|
/>
|
|
</SettingsRow>
|
|
<SettingsRow
|
|
title={__('Background')}
|
|
subtitle={__('Use a custom image or mirror the video that is currently playing.')}
|
|
>
|
|
<FormField
|
|
type="select"
|
|
name="app-background-mode"
|
|
value={backgroundMode || SETTINGS.APP_BACKGROUND_MODES.DEFAULT}
|
|
onChange={(e) => setClientSetting(SETTINGS.APP_BACKGROUND_MODE, e.target.value)}
|
|
>
|
|
<option value={SETTINGS.APP_BACKGROUND_MODES.DEFAULT}>{__('Default')}</option>
|
|
<option value={SETTINGS.APP_BACKGROUND_MODES.CUSTOM}>{__('Custom image')}</option>
|
|
<option value={SETTINGS.APP_BACKGROUND_MODES.VIDEO}>{__('Playing video')}</option>
|
|
</FormField>
|
|
</SettingsRow>
|
|
{backgroundMode === SETTINGS.APP_BACKGROUND_MODES.CUSTOM && (
|
|
<SettingsRow
|
|
title={__('Custom background image')}
|
|
subtitle={__('Choose an image to use as the app background.')}
|
|
multirow
|
|
>
|
|
<FileSelector
|
|
type="openFile"
|
|
accept="image/*"
|
|
filters={[{ name: __('Images'), extensions: ['jpg', 'jpeg', 'png', 'gif', 'webp', 'bmp'] }]}
|
|
currentPath={customBackgroundImage ? __('Image selected') : undefined}
|
|
label={__('Background image')}
|
|
onFileChosen={handleBackgroundImageChosen}
|
|
/>
|
|
{customBackgroundImage && (
|
|
<Button
|
|
button="link"
|
|
label={__('Remove custom background')}
|
|
onClick={() => setClientSetting(SETTINGS.CUSTOM_BACKGROUND_IMAGE, '')}
|
|
/>
|
|
)}
|
|
</SettingsRow>
|
|
)}
|
|
<SettingsRow title={__('Disable background')}>
|
|
<FormField
|
|
type="checkbox"
|
|
name="background"
|
|
onChange={() => setClientSetting(SETTINGS.DISABLE_BACKGROUND, !disableBackground)}
|
|
checked={disableBackground}
|
|
/>
|
|
</SettingsRow>
|
|
<SettingsRow title={__('Hide wallet balance in header')}>
|
|
<FormField
|
|
type="checkbox"
|
|
name="hide_balance"
|
|
onChange={() => setClientSetting(SETTINGS.HIDE_BALANCE, !hideBalance)}
|
|
checked={hideBalance}
|
|
/>
|
|
</SettingsRow>
|
|
</>
|
|
}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
|
|
// prettier-ignore
|
|
const HELP = {
|
|
LANGUAGE: 'Multi-language support is brand new and incomplete. Switching your language may have unintended consequences, like glossolalia.',
|
|
};
|