Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: settings not allowing saving, and not updating immediately
Kyle Mendell86731e673bcc
diff --git a/backend/internal/services/settings_service.go b/backend/internal/services/settings_service.goindex 214a9935c..9870875e1 100644--- a/backend/internal/services/settings_service.go+++ b/backend/internal/services/settings_service.go@@ -427,13 +427,7 @@ func (s *SettingsService) UpdateSettings(ctx context.Context, updates settings.Ureturn nil, err}- if changedPolling && s.OnImagePollingSettingsChanged != nil {- s.OnImagePollingSettingsChanged(ctx)- }- if changedAutoUpdate && s.OnAutoUpdateSettingsChanged != nil {- s.OnAutoUpdateSettingsChanged(ctx)- }-+ // Reload and store settings BEFORE calling callbacks so they read updated valuessettings, err := s.GetSettings(ctx)if err != nil {return nil, fmt.Errorf("failed to retrieve updated settings: %w", err)@@ -441,6 +435,14 @@ func (s *SettingsService) UpdateSettings(ctx context.Context, updates settings.Us.config.Store(settings)+ // Now call callbacks after in-memory config is updated+ if changedPolling && s.OnImagePollingSettingsChanged != nil {+ s.OnImagePollingSettingsChanged(ctx)+ }+ if changedAutoUpdate && s.OnAutoUpdateSettingsChanged != nil {+ s.OnAutoUpdateSettingsChanged(ctx)+ }+return settings.ToSettingVariableSlice(false, false), nil}diff --git a/frontend/src/lib/hooks/use-settings-form.svelte.ts b/frontend/src/lib/hooks/use-settings-form.svelte.tsindex 52e03c45a..72f3a4188 100644--- a/frontend/src/lib/hooks/use-settings-form.svelte.ts+++ b/frontend/src/lib/hooks/use-settings-form.svelte.ts@@ -3,6 +3,7 @@ import settingsStore from '$lib/stores/config-store';import { settingsService } from '$lib/services/settings-service';import type { Settings } from '$lib/types/settings.type';import { tryCatch } from '$lib/utils/try-catch';+import type { Readable } from 'svelte/store';type SettingsFormState = {hasChanges: boolean;@@ -11,18 +12,20 @@ type SettingsFormState = {resetFunction?: () => void;};-type Options = {- hasChangesChecker: () => boolean;+type Options<T> = {+ formInputs: Readable<T>;+ getCurrentSettings: () => Record<string, any>;};-export class UseSettingsForm {+export class UseSettingsForm<T extends Record<string, { value: any; error: string | null }>> {#hasChanges = $state(false);#isLoading = $state(false);+ #formValues = $state<T | null>(null);private formState: SettingsFormState | undefined;- private hasChangesChecker: () => boolean;+ private getCurrentSettings: () => Record<string, any>;- constructor({ hasChangesChecker }: Options) {- this.hasChangesChecker = hasChangesChecker;+ constructor({ formInputs, getCurrentSettings }: Options<T>) {+ this.getCurrentSettings = getCurrentSettings;try {this.formState = getContext('settingsFormState') as SettingsFormState | undefined;@@ -30,10 +33,34 @@ export class UseSettingsForm {// Context not available}+ // Subscribe to form inputs store to track changes+ formInputs.subscribe((value) => {+ this.#formValues = value;+ });+$effect(() => {- this.#hasChanges = this.hasChangesChecker();+ // Access reactive state to trigger re-runs+ const currentFormValues = this.#formValues;+ if (!currentFormValues) {+ this.#hasChanges = false;+ return;+ }++ const settingsToCompare = this.getCurrentSettings();+ const keys = Object.keys(currentFormValues) as (keyof T)[];++ const hasChanges = keys.some((key) => {+ const input = currentFormValues[key];+ if (input && 'value' in input) {+ return input.value !== settingsToCompare[key as string];+ }+ return false;+ });++ this.#hasChanges = hasChanges;+if (this.formState) {- this.formState.hasChanges = this.#hasChanges;+ this.formState.hasChanges = hasChanges;this.formState.isLoading = this.#isLoading;}});diff --git a/frontend/src/lib/utils/settings-form.util.ts b/frontend/src/lib/utils/settings-form.util.tsindex 3288ae7bd..ea90a081b 100644--- a/frontend/src/lib/utils/settings-form.util.ts+++ b/frontend/src/lib/utils/settings-form.util.ts@@ -2,7 +2,7 @@ import { z } from 'zod/v4';import { createForm } from '$lib/utils/form.utils';import { UseSettingsForm } from '$lib/hooks/use-settings-form.svelte';import { toast } from 'svelte-sonner';-import { get, type Writable } from 'svelte/store';+import type { Writable } from 'svelte/store';type FormInput<T> = { value: T; error: string | null };type FormInputs<T> = { [K in keyof T]: FormInput<T[K]> };@@ -10,6 +10,7 @@ type FormInputs<T> = { [K in keyof T]: FormInput<T[K]> };export interface SettingsFormConfig<T extends z.ZodType<any, any>> {schema: T;currentSettings: z.infer<T>;+ getCurrentSettings?: () => z.infer<T>;onSuccess?: () => void;onReset?: () => void;successMessage?: string;@@ -18,44 +19,37 @@ export interface SettingsFormConfig<T extends z.ZodType<any, any>> {/*** Creates a complete settings form with automatic change detection and save/reset handling.- *+ ** Usage:* ```ts* const { formInputs, form, settingsForm, registerOnMount } = createSettingsForm({* schema: formSchema,* currentSettings,+ * getCurrentSettings: () => $settingsStore || data.settings!,* successMessage: m.general_settings_saved(),* onReset: () => applyAccentColor(currentSettings.accentColor)* });- *+ ** onMount(() => registerOnMount());* ```*/export function createSettingsForm<T extends z.ZodType<any, any>>(config: SettingsFormConfig<T>) {- const {- schema,- currentSettings,- onSuccess,+ const {+ schema,+ currentSettings,+ getCurrentSettings,+ onSuccess,onReset,- successMessage = 'Settings saved',- errorMessage = 'Failed to save settings'+ successMessage = 'Settings saved',+ errorMessage = 'Failed to save settings'} = config;const { inputs: formInputs, ...form } = createForm(schema, currentSettings);- const hasChangesChecker = () => {- const current = get(formInputs);- const keys = Object.keys(currentSettings) as (keyof z.infer<T>)[];- return keys.some(key => {- const input = current[key];- if (input && 'value' in input) {- return input.value !== currentSettings[key];- }- return false;- });- };-- const settingsForm = new UseSettingsForm({ hasChangesChecker });+ const settingsForm = new UseSettingsForm({+ formInputs,+ getCurrentSettings: getCurrentSettings ?? (() => currentSettings)+ });const onSubmit = async () => {const data = form.validate();diff --git a/frontend/src/routes/(app)/settings/docker/+page.svelte b/frontend/src/routes/(app)/settings/docker/+page.svelteindex 0c7fd9cda..6a57686c9 100644--- a/frontend/src/routes/(app)/settings/docker/+page.svelte+++ b/frontend/src/routes/(app)/settings/docker/+page.svelte@@ -78,6 +78,7 @@createSettingsForm({schema: formSchema,currentSettings,+ getCurrentSettings: () => $settingsStore || data.settings!,successMessage: m.general_settings_saved()}));diff --git a/frontend/src/routes/(app)/settings/general/+page.svelte b/frontend/src/routes/(app)/settings/general/+page.svelteindex e1ea5c0d7..d228674d2 100644--- a/frontend/src/routes/(app)/settings/general/+page.svelte+++ b/frontend/src/routes/(app)/settings/general/+page.svelte@@ -35,6 +35,7 @@createSettingsForm({schema: formSchema,currentSettings,+ getCurrentSettings: () => $settingsStore || data.settings!,successMessage: m.general_settings_saved(),onReset: () => applyAccentColor(currentSettings.accentColor)})diff --git a/frontend/src/routes/(app)/settings/navigation/+page.svelte b/frontend/src/routes/(app)/settings/navigation/+page.svelteindex 260f807e0..62bda4105 100644--- a/frontend/src/routes/(app)/settings/navigation/+page.svelte+++ b/frontend/src/routes/(app)/settings/navigation/+page.svelte@@ -41,6 +41,7 @@createSettingsForm({schema: formSchema,currentSettings,+ getCurrentSettings: () => $settingsStore || data.settings!,successMessage: m.navigation_settings_saved()}));diff --git a/frontend/src/routes/(app)/settings/security/+page.svelte b/frontend/src/routes/(app)/settings/security/+page.svelteindex ec800f44a..fb2f1fa14 100644--- a/frontend/src/routes/(app)/settings/security/+page.svelte+++ b/frontend/src/routes/(app)/settings/security/+page.svelte@@ -79,6 +79,19 @@createSettingsForm({schema: formSchema,currentSettings: formDefaults,+ getCurrentSettings: () => ({+ authLocalEnabled: ($settingsStore || data.settings!).authLocalEnabled,+ authSessionTimeout: ($settingsStore || data.settings!).authSessionTimeout,+ authPasswordPolicy: ($settingsStore || data.settings!).authPasswordPolicy,+ oidcEnabled: ($settingsStore || data.settings!).oidcEnabled,+ oidcMergeAccounts: ($settingsStore || data.settings!).oidcMergeAccounts,+ oidcClientId: ($settingsStore || data.settings!).oidcClientId,+ oidcClientSecret: '',+ oidcIssuerUrl: ($settingsStore || data.settings!).oidcIssuerUrl,+ oidcScopes: ($settingsStore || data.settings!).oidcScopes,+ oidcAdminClaim: ($settingsStore || data.settings!).oidcAdminClaim,+ oidcAdminValue: ($settingsStore || data.settings!).oidcAdminValue+ }),successMessage: m.security_settings_saved()}));