feishin/src/renderer/features/settings/components/general/control-settings.tsx

324 lines
12 KiB
TypeScript
Raw Normal View History

2023-03-30 06:44:33 -07:00
import { Group } from '@mantine/core';
import { t } from 'i18next';
import isElectron from 'is-electron';
2023-03-30 06:44:33 -07:00
import { Select, Tooltip, NumberInput, Switch, Slider } from '/@/renderer/components';
import { SettingsSection } from '/@/renderer/features/settings/components/settings-section';
import {
2023-07-01 19:10:05 -07:00
SideQueueType,
useGeneralSettings,
useSettingsStoreActions,
2023-03-30 06:44:33 -07:00
} from '/@/renderer/store/settings.store';
import { Play } from '/@/renderer/types';
import { useTranslation } from 'react-i18next';
2023-03-30 06:44:33 -07:00
const localSettings = isElectron() ? window.electron.localSettings : null;
2023-03-30 06:44:33 -07:00
const SIDE_QUEUE_OPTIONS = [
{
label: t('setting.sidePlayQueueStyle', {
context: 'optionAttached',
postProcess: 'sentenceCase',
}),
value: 'sideQueue',
},
{
label: t('setting.sidePlayQueueStyle', {
context: 'optionDetached',
postProcess: 'sentenceCase',
}),
value: 'sideDrawerQueue',
},
2023-03-30 06:44:33 -07:00
];
export const ControlSettings = () => {
const { t } = useTranslation();
2023-07-01 19:10:05 -07:00
const settings = useGeneralSettings();
const { setSettings } = useSettingsStoreActions();
2023-03-30 06:44:33 -07:00
2023-07-01 19:10:05 -07:00
const controlOptions = [
{
control: (
<NumberInput
defaultValue={settings.buttonSize}
max={30}
min={15}
rightSection="px"
width={75}
onBlur={(e) => {
if (!e) return;
const newVal = e.currentTarget.value
? Math.min(Math.max(Number(e.currentTarget.value), 15), 30)
: settings.buttonSize;
setSettings({
general: {
...settings,
buttonSize: newVal,
},
});
}}
/>
),
description: t('setting.buttonSize', {
context: 'description',
postProcess: 'sentenceCase',
}),
isHidden: false,
title: t('setting.buttonSize', { postProcess: 'sentenceCase' }),
},
2023-07-01 19:10:05 -07:00
{
control: (
<Switch
aria-label="Toggle skip buttons"
defaultChecked={settings.skipButtons?.enabled}
onChange={(e) =>
setSettings({
general: {
...settings,
skipButtons: {
...settings.skipButtons,
enabled: e.currentTarget.checked,
},
},
})
}
/>
),
description: t('setting.showSkipButtons', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: false,
title: t('setting.showSkipButtons', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Group>
<Tooltip label={t('common.backward', { postProcess: 'titleCase' })}>
2023-07-01 19:10:05 -07:00
<NumberInput
defaultValue={settings.skipButtons.skipBackwardSeconds}
min={0}
width={75}
onBlur={(e) =>
setSettings({
general: {
...settings,
skipButtons: {
...settings.skipButtons,
skipBackwardSeconds: e.currentTarget.value
? Number(e.currentTarget.value)
: 0,
},
},
})
}
/>
</Tooltip>
<Tooltip label={t('common.forward', { postProcess: 'titleCase' })}>
2023-07-01 19:10:05 -07:00
<NumberInput
defaultValue={settings.skipButtons.skipForwardSeconds}
min={0}
width={75}
onBlur={(e) =>
setSettings({
general: {
...settings,
skipButtons: {
...settings.skipButtons,
skipForwardSeconds: e.currentTarget.value
? Number(e.currentTarget.value)
: 0,
},
},
})
}
/>
</Tooltip>
</Group>
),
description: t('setting.skipDuration', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: false,
title: t('setting.skipDuration', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Select
data={[
{
label: t('setting.playButtonBehavior', {
context: 'optionPlay',
postProcess: 'titleCase',
}),
value: Play.NOW,
},
{
label: t('setting.playButtonBehavior', {
context: 'optionAddNext',
postProcess: 'titleCase',
}),
value: Play.NEXT,
},
{
label: t('setting.playButtonBehavior', {
context: 'optionAddLast',
postProcess: 'titleCase',
}),
value: Play.LAST,
},
2023-07-01 19:10:05 -07:00
]}
defaultValue={settings.playButtonBehavior}
onChange={(e) =>
setSettings({
general: {
...settings,
playButtonBehavior: e as Play,
},
})
}
/>
),
description: t('setting.playButtonBehavior', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: false,
title: t('setting.playButtonBehavior', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Select
data={SIDE_QUEUE_OPTIONS}
defaultValue={settings.sideQueueType}
onChange={(e) => {
setSettings({
general: {
...settings,
sideQueueType: e as SideQueueType,
},
});
}}
/>
),
description: t('setting.sidePlayQueueStyle', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: false,
title: t('setting.sidePlayQueueStyle', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Switch
defaultChecked={settings.showQueueDrawerButton}
onChange={(e) => {
setSettings({
general: {
...settings,
showQueueDrawerButton: e.currentTarget.checked,
},
});
}}
/>
),
description: t('setting.sidePlayQueueStyle', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: false,
title: t('setting.floatingQueueArea', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Slider
defaultValue={settings.volumeWheelStep}
max={20}
min={1}
w={100}
onChangeEnd={(e) => {
setSettings({
general: {
...settings,
volumeWheelStep: e,
},
});
}}
/>
),
description: t('setting.volumeWheelStep', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: false,
title: t('setting.volumeWheelStep', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Switch
defaultChecked={settings.resume}
onChange={(e) => {
localSettings?.set('resume', e.target.checked);
setSettings({
general: {
...settings,
resume: e.currentTarget.checked,
},
});
}}
/>
),
description: t('setting.savePlayQueue', {
context: 'description',
postProcess: 'sentenceCase',
}),
2023-07-01 19:10:05 -07:00
isHidden: !isElectron(),
title: t('setting.savePlayQueue', { postProcess: 'sentenceCase' }),
2023-07-01 19:10:05 -07:00
},
{
control: (
<Switch
aria-label="Go to playlist songs page by default"
defaultChecked={settings.defaultFullPlaylist}
onChange={(e) =>
setSettings({
general: {
...settings,
defaultFullPlaylist: e.currentTarget.checked,
},
})
}
/>
),
description: t('setting.skipPlaylistPage', {
context: 'description',
postProcess: 'sentenceCase',
}),
isHidden: false,
title: t('setting.skipPlaylistPage', { postProcess: 'sentenceCase' }),
},
2024-01-15 22:10:50 -08:00
{
control: (
<Switch
defaultChecked={settings.externalLinks}
onChange={(e) => {
setSettings({
general: {
...settings,
externalLinks: e.currentTarget.checked,
},
});
}}
/>
),
description: t('setting.externalLinks', {
context: 'description',
postProcess: 'sentenceCase',
}),
title: t('setting.externalLinks', { postProcess: 'sentenceCase' }),
},
2023-07-01 19:10:05 -07:00
];
2023-03-30 06:44:33 -07:00
2023-07-01 19:10:05 -07:00
return <SettingsSection options={controlOptions} />;
2023-03-30 06:44:33 -07:00
};