diff --git a/src/core/react-query/settings/helpers.ts b/src/core/react-query/settings/helpers.ts index ae2519b2a..77c9e71f5 100644 --- a/src/core/react-query/settings/helpers.ts +++ b/src/core/react-query/settings/helpers.ts @@ -418,11 +418,11 @@ export const initialSettings: SettingsType = { EnabledPlugins: {}, Priority: [], Renamer: { - DefaultRenamer: null, EnabledRenamers: {}, + MoveOnImport: false, + RenameOnImport: false, + DefaultRenamer: null, }, - MoveOnImport: false, - RenameOnImport: false, }, }; diff --git a/src/core/types/api/settings.ts b/src/core/types/api/settings.ts index dd8c5815f..3a300c662 100644 --- a/src/core/types/api/settings.ts +++ b/src/core/types/api/settings.ts @@ -368,15 +368,17 @@ export type SettingsImportType = { VideoExtensions: string[]; }; -export type PluginSettingsType = { - EnabledPlugins: Record; - Priority: number[]; - Renamer: { - DefaultRenamer: string | null; - EnabledRenamers: Record; - }; +export type PluginRenamerSettingsType = { + EnabledRenamers: Record; MoveOnImport: boolean; RenameOnImport: boolean; + DefaultRenamer: string | null; +}; + +export type PluginSettingsType = { + EnabledPlugins: Record; + Priority: string[]; + Renamer: PluginRenamerSettingsType; }; export type SettingsServerType = { diff --git a/src/hooks/useSettingsContext.ts b/src/hooks/useSettingsContext.ts index 64b67dbc1..4534c16c4 100644 --- a/src/hooks/useSettingsContext.ts +++ b/src/hooks/useSettingsContext.ts @@ -1,11 +1,11 @@ import { useOutletContext } from 'react-router-dom'; -import type { SettingsType } from '@/core/types/api/settings'; +import type { PluginRenamerSettingsType, SettingsType } from '@/core/types/api/settings'; type ContextType = { newSettings: SettingsType; setNewSettings: (settings: SettingsType) => void; - updateSetting: (type: string, key: string, value: string | string[] | boolean) => void; + updateSetting: (type: string, key: string, value: string | string[] | boolean | PluginRenamerSettingsType) => void; }; const useSettingsContext = () => useOutletContext(); diff --git a/src/pages/settings/SettingsPage.tsx b/src/pages/settings/SettingsPage.tsx index b3623f1f7..251148a85 100644 --- a/src/pages/settings/SettingsPage.tsx +++ b/src/pages/settings/SettingsPage.tsx @@ -15,6 +15,8 @@ import { useSettingsQuery } from '@/core/react-query/settings/queries'; import { setItem as setMiscItem } from '@/core/slices/misc'; import useEventCallback from '@/hooks/useEventCallback'; +import type { PluginRenamerSettingsType } from '@/core/types/api/settings'; + const items = [ { name: 'General', path: 'general' }, { name: 'Import', path: 'import' }, @@ -71,12 +73,12 @@ function SettingsPage() { if (toastId.current) toast.dismiss(toastId.current); }, []); - const updateSetting = (type: string, key: string, value: string | string[] | boolean) => { + const updateSetting = (type: string, key: string, value: string | string[] | boolean | PluginRenamerSettingsType) => { if (key === 'theme' && typeof value === 'string') { globalThis.localStorage.setItem('theme', value); } - const tempSettings: Record = { + const tempSettings: Record = { ...(newSettings[type] as Record), [key]: value, }; diff --git a/src/pages/settings/tabs/ImportSettings.tsx b/src/pages/settings/tabs/ImportSettings.tsx index 190134abe..5b03f4de8 100644 --- a/src/pages/settings/tabs/ImportSettings.tsx +++ b/src/pages/settings/tabs/ImportSettings.tsx @@ -1,7 +1,9 @@ import React from 'react'; +import { produce } from 'immer'; import Checkbox from '@/components/Input/Checkbox'; import InputSmall from '@/components/Input/InputSmall'; +import useEventCallback from '@/hooks/useEventCallback'; import useSettingsContext from '@/hooks/useSettingsContext'; function ImportSettings() { @@ -17,7 +19,15 @@ function ImportSettings() { const { MoveOnImport, RenameOnImport, - } = newSettings.Plugins; + } = newSettings.Plugins.Renamer; + + const handleRenamerSettingChange = useEventCallback((type: 'MoveOnImport' | 'RenameOnImport', value: boolean) => { + const renamerSettings = produce(newSettings.Plugins.Renamer, settings => ({ + ...settings, + [type]: value, + })); + updateSetting('Plugins', 'Renamer', renamerSettings); + }); return ( <> @@ -46,22 +56,15 @@ function ImportSettings() { label="Rename on import" id="rename-on-import" isChecked={RenameOnImport} - onChange={event => updateSetting('Plugins', 'RenameOnImport', event.target.checked)} + onChange={event => handleRenamerSettingChange('RenameOnImport', event.target.checked)} /> updateSetting('Plugins', 'MoveOnImport', event.target.checked)} + onChange={event => handleRenamerSettingChange('MoveOnImport', event.target.checked)} /> - {/* updateSetting('Import', 'RenameThenMove', event.target.checked)} */} - {/* /> */} { Server Version:  {versionQuery.data.Server.Version}
- Supported Server Version:  + Minimum Supported Server Version:  {minimumSupportedServerVersion}
Web UI Version: