From 3dd26c7785329c38f1a468c8561a49ce7d36fe3f Mon Sep 17 00:00:00 2001 From: Grady Hallenbeck Date: Thu, 19 Oct 2023 12:02:54 -0700 Subject: [PATCH] feat: (preferences) hook react display settings into user settings --- .../user/display/DisplayPreferences.tsx | 72 +++++++- .../user/display/ItemDetailPreferences.tsx | 18 +- .../user/display/LibraryPreferences.tsx | 45 ++++- .../user/display/LocalizationPreferences.tsx | 26 ++- .../routes/user/display/NextUpPreferences.tsx | 29 +++- .../display/hooks/useDisplaySettingForm.ts | 46 +++++ .../user/display/hooks/useDisplaySettings.ts | 159 ++++++++++++++++++ .../user/display/hooks/useScreensavers.ts | 29 ++++ .../user/display/hooks/useServerThemes.ts | 32 ++++ .../routes/user/display/index.tsx | 65 ++++++- .../experimental/routes/user/display/types.ts | 22 +++ src/scripts/settings/userSettings.js | 30 ++-- src/types/webConfig.ts | 3 +- 13 files changed, 530 insertions(+), 46 deletions(-) create mode 100644 src/apps/experimental/routes/user/display/hooks/useDisplaySettingForm.ts create mode 100644 src/apps/experimental/routes/user/display/hooks/useDisplaySettings.ts create mode 100644 src/apps/experimental/routes/user/display/hooks/useScreensavers.ts create mode 100644 src/apps/experimental/routes/user/display/hooks/useServerThemes.ts create mode 100644 src/apps/experimental/routes/user/display/types.ts diff --git a/src/apps/experimental/routes/user/display/DisplayPreferences.tsx b/src/apps/experimental/routes/user/display/DisplayPreferences.tsx index a898f0bf36..a862727cf1 100644 --- a/src/apps/experimental/routes/user/display/DisplayPreferences.tsx +++ b/src/apps/experimental/routes/user/display/DisplayPreferences.tsx @@ -3,15 +3,26 @@ import FormControl from '@mui/material/FormControl'; import FormControlLabel from '@mui/material/FormControlLabel'; import FormHelperText from '@mui/material/FormHelperText'; import MenuItem from '@mui/material/MenuItem'; -import Select from '@mui/material/Select'; +import Select, { SelectChangeEvent } from '@mui/material/Select'; import Stack from '@mui/material/Stack'; import TextField from '@mui/material/TextField'; import Typography from '@mui/material/Typography'; import React from 'react'; import globalize from 'scripts/globalize'; +import { DisplaySettingsValues } from './types'; +import { useScreensavers } from './hooks/useScreensavers'; +import { useServerThemes } from './hooks/useServerThemes'; + +interface DisplayPreferencesProps { + onChange: (event: SelectChangeEvent | React.SyntheticEvent) => void; + values: DisplaySettingsValues; +} + +export function DisplayPreferences({ onChange, values }: Readonly) { + const { screensavers } = useScreensavers(); + const { themes } = useServerThemes(); -export function DisplayPreferences() { return ( {globalize.translate('Display')} @@ -19,7 +30,12 @@ export function DisplayPreferences() { + } + control={ + + } label={globalize.translate('DisableCustomCss')} + name='disableCustomCss' /> {globalize.translate('LabelDisableCustomCss')} @@ -52,8 +84,11 @@ export function DisplayPreferences() { {globalize.translate('LabelLocalCustomCss')} @@ -64,7 +99,18 @@ export function DisplayPreferences() { {/* Server Dashboard Theme */} - + {/* TODO: There are some extra options here related to screensavers */} @@ -72,8 +118,14 @@ export function DisplayPreferences() { } + control={ + + } label={globalize.translate('EnableFasterAnimations')} + name='enableFasterAnimation' /> {globalize.translate('EnableFasterAnimationsHelp')} @@ -83,8 +135,14 @@ export function DisplayPreferences() { } + control={ + + } label={globalize.translate('EnableBlurHash')} + name='enableBlurHash' /> {globalize.translate('EnableBlurHashHelp')} diff --git a/src/apps/experimental/routes/user/display/ItemDetailPreferences.tsx b/src/apps/experimental/routes/user/display/ItemDetailPreferences.tsx index 409167a657..00da9439de 100644 --- a/src/apps/experimental/routes/user/display/ItemDetailPreferences.tsx +++ b/src/apps/experimental/routes/user/display/ItemDetailPreferences.tsx @@ -7,17 +7,29 @@ import Typography from '@mui/material/Typography'; import React from 'react'; import globalize from 'scripts/globalize'; +import { DisplaySettingsValues } from './types'; -export function ItemDetailPreferences() { +interface ItemDetailPreferencesProps { + onChange: (event: React.SyntheticEvent) => void; + values: DisplaySettingsValues; +} + +export function ItemDetailPreferences({ onChange, values }: Readonly) { return ( - + {globalize.translate('ItemDetails')} } + control={ + + } label={globalize.translate('EnableDetailsBanner')} + name='enableItemDetailsBanner' /> {globalize.translate('EnableDetailsBannerHelp')} diff --git a/src/apps/experimental/routes/user/display/LibraryPreferences.tsx b/src/apps/experimental/routes/user/display/LibraryPreferences.tsx index ec13aa4112..04ae913999 100644 --- a/src/apps/experimental/routes/user/display/LibraryPreferences.tsx +++ b/src/apps/experimental/routes/user/display/LibraryPreferences.tsx @@ -8,10 +8,16 @@ import Typography from '@mui/material/Typography'; import React from 'react'; import globalize from 'scripts/globalize'; +import { DisplaySettingsValues } from './types'; -export function LibraryPreferences() { +interface LibraryPreferencesProps { + onChange: (event: React.SyntheticEvent) => void; + values: DisplaySettingsValues; +} + +export function LibraryPreferences({ onChange, values }: Readonly) { return ( - + {globalize.translate('HeaderLibraries')} @@ -26,7 +32,10 @@ export function LibraryPreferences() { required: true, step: '1' }} + defaultValue={values.libraryPageSize} label={globalize.translate('LabelLibraryPageSize')} + name='libraryPageSize' + onChange={onChange} /> {globalize.translate('LabelLibraryPageSizeHelp')} @@ -36,8 +45,14 @@ export function LibraryPreferences() { } + control={ + + } label={globalize.translate('Backdrops')} + name='enableLibraryBackdrops' /> {globalize.translate('EnableBackdropsHelp')} @@ -47,8 +62,14 @@ export function LibraryPreferences() { } + control={ + + } label={globalize.translate('ThemeSongs')} + name='enableLibraryThemeSongs' /> {globalize.translate('EnableThemeSongsHelp')} @@ -58,8 +79,14 @@ export function LibraryPreferences() { } + control={ + + } label={globalize.translate('ThemeVideos')} + name='enableLibraryThemeVideos' /> {globalize.translate('EnableThemeVideosHelp')} @@ -69,8 +96,14 @@ export function LibraryPreferences() { } + control={ + + } label={globalize.translate('DisplayMissingEpisodesWithinSeasons')} + name='displayMissingEpisodes' /> {globalize.translate('DisplayMissingEpisodesWithinSeasonsHelp')} diff --git a/src/apps/experimental/routes/user/display/LocalizationPreferences.tsx b/src/apps/experimental/routes/user/display/LocalizationPreferences.tsx index 50a0b2252d..d0e625174e 100644 --- a/src/apps/experimental/routes/user/display/LocalizationPreferences.tsx +++ b/src/apps/experimental/routes/user/display/LocalizationPreferences.tsx @@ -2,23 +2,34 @@ import FormControl from '@mui/material/FormControl'; import FormHelperText from '@mui/material/FormHelperText'; import Link from '@mui/material/Link'; import MenuItem from '@mui/material/MenuItem'; -import Select from '@mui/material/Select'; +import Select, { SelectChangeEvent } from '@mui/material/Select'; import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import React from 'react'; import globalize from 'scripts/globalize'; import { DATE_LOCALE_OPTIONS, LANGUAGE_OPTIONS } from './constants'; +import { DisplaySettingsValues } from './types'; -export function LocalizationPreferences() { +interface LocalizationPreferencesProps { + onChange: (event: SelectChangeEvent) => void; + values: DisplaySettingsValues; +} + +export function LocalizationPreferences({ onChange, values }: Readonly) { return ( - + {globalize.translate('Localization')} +