Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
refactor: update environment page to use settings form util (#1469)
Kyle Mendell3836c30005bc
diff --git a/frontend/src/lib/hooks/use-settings-form.svelte.ts b/frontend/src/lib/hooks/use-settings-form.svelte.tsindex ad25f5bf0..94528ac94 100644--- a/frontend/src/lib/hooks/use-settings-form.svelte.ts+++ b/frontend/src/lib/hooks/use-settings-form.svelte.ts@@ -12,21 +12,33 @@ type SettingsFormState = {resetFunction?: () => void;};-type Options<T> = {- formInputs: Readable<T>;- getCurrentSettings: () => Record<string, any>;+type SettingsPayload = Partial<Settings> & Record<string, unknown>;++type Options<TFormInputs, TSaveData extends SettingsPayload> = {+ formInputs: Readable<TFormInputs>;+ getCurrentSettings: () => TSaveData;+ /**+ * Custom save handler. If provided, this will be called instead of the default+ * settingsService.updateSettings(). Useful for environment-specific settings.+ */+ onSave?: (data: TSaveData) => Promise<void>;};-export class UseSettingsForm<T extends Record<string, { value: any; error: string | null }>> {+export class UseSettingsForm<+ TFormInputs extends Record<string, { value: unknown; error: string | null }>,+ TSaveData extends SettingsPayload+> {#isLoading = $state(false);- #formValues = $state<T | null>(null);+ #formValues = $state<TFormInputs | null>(null);#saveFunction: (() => Promise<void> | void) | null = null;#resetFunction: (() => void) | null = null;private formState: SettingsFormState | undefined;- private getCurrentSettings: () => Record<string, any>;+ private getCurrentSettings: () => TSaveData;+ private customOnSave?: (data: TSaveData) => Promise<void>;- constructor({ formInputs, getCurrentSettings }: Options<T>) {+ constructor({ formInputs, getCurrentSettings, onSave }: Options<TFormInputs, TSaveData>) {this.getCurrentSettings = getCurrentSettings;+ this.customOnSave = onSave;try {this.formState = getContext('settingsFormState') as SettingsFormState | undefined;@@ -55,7 +67,7 @@ export class UseSettingsForm<T extends Record<string, { value: any; error: strinif (!currentFormValues) return false;const settingsToCompare = this.getCurrentSettings();- const keys = Object.keys(currentFormValues) as (keyof T)[];+ const keys = Object.keys(currentFormValues) as (keyof TFormInputs)[];return keys.some((key) => {const input = currentFormValues[key];@@ -66,12 +78,21 @@ export class UseSettingsForm<T extends Record<string, { value: any; error: strin});});- async updateSettings(updatedSettings: Partial<Settings>) {- const result = await tryCatch(settingsService.updateSettings(updatedSettings as any));-- if (result.error) {- console.error('Error updating settings:', result.error);- throw result.error;+ async updateSettings(updatedSettings: Partial<TSaveData>) {+ // Use custom save handler if provided+ if (this.customOnSave) {+ const mergedSettings = {+ ...this.getCurrentSettings(),+ ...updatedSettings+ } as TSaveData;+ await this.customOnSave(mergedSettings);+ } else {+ const result = await tryCatch(settingsService.updateSettings(updatedSettings));++ if (result.error) {+ console.error('Error updating settings:', result.error);+ throw result.error;+ }}await settingsStore.reload();diff --git a/frontend/src/lib/utils/form.utils.ts b/frontend/src/lib/utils/form.utils.tsindex 84f14d987..834428279 100644--- a/frontend/src/lib/utils/form.utils.ts+++ b/frontend/src/lib/utils/form.utils.ts@@ -77,9 +77,11 @@ export function createForm<T extends z.ZodType<any, any>>(schema: T, initialValu// Trim values for submission, but don't mutate the store value in-place.return [key, trimValue(input.value)];})- ) as z.infer<T>;+ );- return values;+ // Parse through schema to apply coercion (e.g., z.coerce.number())+ const result = schema.safeParse(values);+ return (result.success ? result.data : values) as z.infer<T>;}function reset() {diff --git a/frontend/src/lib/utils/settings-form.util.ts b/frontend/src/lib/utils/settings-form.util.tsindex b2e4cdb6a..807f3f9b0 100644--- a/frontend/src/lib/utils/settings-form.util.ts+++ b/frontend/src/lib/utils/settings-form.util.ts@@ -2,15 +2,22 @@ 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 type { Writable } from 'svelte/store';+import type { Settings } from '$lib/types/settings.type';type FormInput<T> = { value: T; error: string | null };type FormInputs<T> = { [K in keyof T]: FormInput<T[K]> };+type SettingsPayload = Partial<Settings> & Record<string, unknown>;-export interface SettingsFormConfig<T extends z.ZodType<any, any>> {+export interface SettingsFormConfig<T extends z.ZodType<SettingsPayload, any>> {schema: T;currentSettings: z.infer<T>;getCurrentSettings?: () => z.infer<T>;+ /**+ * Custom save handler. If provided, this will be called instead of the default+ * settingsService.updateSettings(). Useful for environment-specific settings+ * or other custom save logic.+ */+ onSave?: (data: z.infer<T>) => Promise<void>;onSuccess?: () => void;onReset?: () => void;successMessage?: string;@@ -38,6 +45,7 @@ export function createSettingsForm<T extends z.ZodType<any, any>>(config: Settinschema,currentSettings,getCurrentSettings,+ onSave,onSuccess,onReset,successMessage = 'Settings saved',@@ -48,7 +56,8 @@ export function createSettingsForm<T extends z.ZodType<any, any>>(config: Settinconst settingsForm = new UseSettingsForm({formInputs,- getCurrentSettings: getCurrentSettings ?? (() => currentSettings)+ getCurrentSettings: getCurrentSettings ?? (() => currentSettings),+ onSave});const onSubmit = async () => {@@ -65,7 +74,8 @@ export function createSettingsForm<T extends z.ZodType<any, any>>(config: SettinonSuccess?.();} catch (error) {console.error('Failed to save settings:', error);- toast.error(errorMessage);+ const message = error instanceof Error ? error.message : errorMessage;+ toast.error(message);} finally {settingsForm.setLoading(false);}@@ -84,7 +94,7 @@ export function createSettingsForm<T extends z.ZodType<any, any>>(config: Settin};return {- formInputs: formInputs as Writable<FormInputs<z.infer<T>>>,+ formInputs,form,settingsForm,onSubmit,diff --git a/frontend/src/routes/(app)/environments/[id]/+page.svelte b/frontend/src/routes/(app)/environments/[id]/+page.svelteindex cc6987071..c6d79e8e5 100644--- a/frontend/src/routes/(app)/environments/[id]/+page.svelte+++ b/frontend/src/routes/(app)/environments/[id]/+page.svelte@@ -1,4 +1,5 @@<script lang="ts">+ import { z } from 'zod/v4';import * as Card from '$lib/components/ui/card/index.js';import * as Tabs from '$lib/components/ui/tabs/index.js';import { TabBar, type TabItem } from '$lib/components/tab-bar';@@ -22,6 +23,7 @@import SelectWithLabel from '$lib/components/form/select-with-label.svelte';import TextInputWithLabel from '$lib/components/form/text-input-with-label.svelte';import MobileFloatingFormActions from '$lib/components/form/mobile-floating-form-actions.svelte';+ import { createSettingsForm } from '$lib/utils/settings-form.util';import {ArrowLeftIcon,EnvironmentsIcon,@@ -64,7 +66,6 @@let isRefreshing = $state(false);let isTestingConnection = $state(false);- let isSaving = $state(false);let isSyncing = $state(false);let isRegeneratingKey = $state(false);let showRegenerateDialog = $state(false);@@ -74,30 +75,126 @@let remoteVersion = $state<AppVersionInformation | null>(null);let isLoadingVersion = $state(false);- // Form state- let formName = $state('');- let formEnabled = $state(false);- let formApiUrl = $state('');-- // Settings form state- let formPollingEnabled = $state(false);- let formPollingInterval = $state(60);- let formAutoUpdate = $state(false);- let formAutoUpdateInterval = $state(1440);- let formAutoInjectEnv = $state(false);- let formPruneMode = $state<'all' | 'dangling'>('dangling');- let formDefaultShell = $state('/bin/sh');- let formProjectsDirectory = $state('/app/data/projects');- let formDiskUsagePath = $state('/app/data/projects');- let formMaxImageUploadSize = $state(500);- let formBaseServerUrl = $state('http://localhost');- let formScheduledPruneEnabled = $state(false);- let formScheduledPruneInterval = $state(1440);- let formScheduledPruneContainers = $state(true);- let formScheduledPruneImages = $state(true);- let formScheduledPruneVolumes = $state(false);- let formScheduledPruneNetworks = $state(true);- let formScheduledPruneBuildCache = $state(false);+ // Track current status separately from environment data+ let currentStatus = $state<'online' | 'offline' | 'error' | 'pending'>('offline');++ // Initialize status from environment+ $effect(() => {+ currentStatus = environment.status;+ });++ // Form schema combining environment info and settings+ const formSchema = z.object({+ // Environment basic info+ name: z.string().min(1),+ enabled: z.boolean(),+ apiUrl: z.string(),+ // Settings+ pollingEnabled: z.boolean(),+ pollingInterval: z.coerce.number(),+ autoUpdate: z.boolean(),+ autoUpdateInterval: z.coerce.number(),+ autoInjectEnv: z.boolean(),+ dockerPruneMode: z.enum(['all', 'dangling']),+ defaultShell: z.string(),+ projectsDirectory: z.string(),+ diskUsagePath: z.string(),+ maxImageUploadSize: z.coerce.number(),+ baseServerUrl: z.string(),+ scheduledPruneEnabled: z.boolean(),+ scheduledPruneInterval: z.coerce.number().min(60).max(10080),+ scheduledPruneContainers: z.boolean(),+ scheduledPruneImages: z.boolean(),+ scheduledPruneVolumes: z.boolean(),+ scheduledPruneNetworks: z.boolean(),+ scheduledPruneBuildCache: z.boolean()+ });++ // Build current settings object from environment and settings data+ const currentSettings = $derived({+ name: environment.name,+ enabled: environment.enabled,+ apiUrl: environment.apiUrl,+ pollingEnabled: settings?.pollingEnabled ?? false,+ pollingInterval: settings?.pollingInterval ?? 60,+ autoUpdate: settings?.autoUpdate ?? false,+ autoUpdateInterval: settings?.autoUpdateInterval ?? 1440,+ autoInjectEnv: settings?.autoInjectEnv ?? false,+ dockerPruneMode: (settings?.dockerPruneMode as 'all' | 'dangling') || 'dangling',+ defaultShell: settings?.defaultShell || '/bin/sh',+ projectsDirectory: settings?.projectsDirectory || '/app/data/projects',+ diskUsagePath: settings?.diskUsagePath || '/app/data/projects',+ maxImageUploadSize: settings?.maxImageUploadSize || 500,+ baseServerUrl: settings?.baseServerUrl || 'http://localhost',+ scheduledPruneEnabled: settings?.scheduledPruneEnabled ?? false,+ scheduledPruneInterval: settings?.scheduledPruneInterval ?? 1440,+ scheduledPruneContainers: settings?.scheduledPruneContainers ?? true,+ scheduledPruneImages: settings?.scheduledPruneImages ?? true,+ scheduledPruneVolumes: settings?.scheduledPruneVolumes ?? false,+ scheduledPruneNetworks: settings?.scheduledPruneNetworks ?? true,+ scheduledPruneBuildCache: settings?.scheduledPruneBuildCache ?? false+ });++ // Custom save handler for environment-specific settings+ async function saveEnvironmentSettings(formData: z.infer<typeof formSchema>) {+ const sanitizedScheduledPruneInterval = Math.min(Math.max(formData.scheduledPruneInterval || 0, 60), 10080);++ // Update environment basic info+ await environmentManagementService.update(environment.id, {+ name: formData.name,+ enabled: formData.enabled,+ apiUrl: formData.apiUrl+ });++ // Update environment settings if they exist+ if (settings) {+ await settingsService.updateSettingsForEnvironment(environment.id, {+ pollingEnabled: formData.pollingEnabled,+ pollingInterval: formData.pollingInterval,+ autoUpdate: formData.autoUpdate,+ autoUpdateInterval: formData.autoUpdateInterval,+ autoInjectEnv: formData.autoInjectEnv,+ dockerPruneMode: formData.dockerPruneMode,+ defaultShell: formData.defaultShell,+ projectsDirectory: formData.projectsDirectory,+ diskUsagePath: formData.diskUsagePath,+ maxImageUploadSize: formData.maxImageUploadSize,+ baseServerUrl: formData.baseServerUrl,+ scheduledPruneEnabled: formData.scheduledPruneEnabled,+ scheduledPruneInterval: sanitizedScheduledPruneInterval,+ scheduledPruneContainers: formData.scheduledPruneContainers,+ scheduledPruneImages: formData.scheduledPruneImages,+ scheduledPruneVolumes: formData.scheduledPruneVolumes,+ scheduledPruneNetworks: formData.scheduledPruneNetworks,+ scheduledPruneBuildCache: formData.scheduledPruneBuildCache+ });+ }++ await refreshEnvironment();++ // Update environment store if this is the current environment+ if (currentEnvironment?.id === environment.id) {+ await environmentStore.initialize(+ (+ await environmentManagementService.getEnvironments({+ pagination: { page: 1, limit: 1000 }+ })+ ).data+ );+ }+ }++ let { formInputs, settingsForm, resetForm, onSubmit } = $derived(+ createSettingsForm({+ schema: formSchema,+ currentSettings,+ getCurrentSettings: () => currentSettings,+ onSave: saveEnvironmentSettings,+ successMessage: m.common_update_success({ resource: m.resource_environment_cap() }),+ errorMessage: m.common_update_failed({ resource: m.resource_environment() }),+ onReset: () => toast.info(m.environments_changes_reset())+ })+ );type PollingIntervalMode = 'hourly' | 'daily' | 'weekly' | 'custom';@@ -117,7 +214,10 @@imagePollingOptions.filter((o) => o.value !== 'custom').map((o) => [o.value, o.minutes!])) as Record<Exclude<PollingIntervalMode, 'custom'>, number>;- let pollingIntervalMode = $state<PollingIntervalMode>('custom');+ let pollingIntervalMode = $derived.by((): PollingIntervalMode => {+ if (!settings) return 'custom';+ return imagePollingOptions.find((o) => o.minutes === settings.pollingInterval)?.value ?? 'custom';+ });const pruneModeOptions = [{ value: 'all', label: m.docker_prune_all(), description: m.docker_prune_all_description() },@@ -125,7 +225,7 @@];let pruneModeDescription = $derived(- pruneModeOptions.find((o) => o.value === formPruneMode)?.description ?? m.docker_prune_mode_description()+ pruneModeOptions.find((o) => o.value === $formInputs.dockerPruneMode.value)?.description ?? m.docker_prune_mode_description());const shellOptions = [@@ -135,57 +235,22 @@{ value: '/bin/zsh', label: '/bin/zsh', description: m.docker_shell_zsh_description() }];- let shellSelectValue = $state<string>('custom');-- // Track current status separately from environment data- let currentStatus = $state<'online' | 'offline' | 'error' | 'pending'>('offline');-- // Initialize form values and status- $effect(() => {- formName = environment.name;- formEnabled = environment.enabled;- formApiUrl = environment.apiUrl;- currentStatus = environment.status;-- if (settings) {- formPollingEnabled = settings.pollingEnabled;- formPollingInterval = settings.pollingInterval;- formAutoUpdate = settings.autoUpdate;- formAutoUpdateInterval = settings.autoUpdateInterval;- formAutoInjectEnv = settings.autoInjectEnv;- formPruneMode = settings.dockerPruneMode || 'dangling';- formDefaultShell = settings.defaultShell || '/bin/sh';- formProjectsDirectory = settings.projectsDirectory || '/app/data/projects';- formDiskUsagePath = settings.diskUsagePath || '/app/data/projects';- formMaxImageUploadSize = settings.maxImageUploadSize || 500;- formBaseServerUrl = settings.baseServerUrl || 'http://localhost';- formScheduledPruneEnabled = settings.scheduledPruneEnabled ?? false;- formScheduledPruneInterval = settings.scheduledPruneInterval ?? 1440;- formScheduledPruneContainers = settings.scheduledPruneContainers ?? true;- formScheduledPruneImages = settings.scheduledPruneImages ?? true;- formScheduledPruneVolumes = settings.scheduledPruneVolumes ?? false;- formScheduledPruneNetworks = settings.scheduledPruneNetworks ?? true;- formScheduledPruneBuildCache = settings.scheduledPruneBuildCache ?? false;-- // Initialize derived states- pollingIntervalMode = imagePollingOptions.find((o) => o.minutes === settings.pollingInterval)?.value ?? 'custom';- shellSelectValue = shellOptions.find((o) => o.value === settings.defaultShell)?.value ?? 'custom';- }+ let shellSelectValue = $derived.by((): string => {+ if (!settings) return 'custom';+ return shellOptions.find((o) => o.value === settings.defaultShell)?.value ?? 'custom';});- // Sync polling mode select with form value- $effect(() => {- if (pollingIntervalMode !== 'custom') {- formPollingInterval = presetToMinutes[pollingIntervalMode];+ function handlePollingIntervalModeChange(value: string) {+ if (value !== 'custom') {+ $formInputs.pollingInterval.value = presetToMinutes[value as Exclude<PollingIntervalMode, 'custom'>];}- });+ }- // Sync shell select with form value- $effect(() => {- if (shellSelectValue !== 'custom') {- formDefaultShell = shellSelectValue;+ function handleShellSelectChange(value: string) {+ if (value !== 'custom') {+ $formInputs.defaultShell.value = value;}- });+ }// Fetch version when environment is online$effect(() => {@@ -205,68 +270,12 @@}}- // Track changes- let hasChanges = $derived(- formName !== environment.name ||- formEnabled !== environment.enabled ||- (environment.id !== '0' && formApiUrl !== environment.apiUrl) ||- (settings &&- (formPollingEnabled !== settings.pollingEnabled ||- formPollingInterval !== settings.pollingInterval ||- formAutoUpdate !== settings.autoUpdate ||- formAutoUpdateInterval !== settings.autoUpdateInterval ||- formAutoInjectEnv !== settings.autoInjectEnv ||- formPruneMode !== (settings.dockerPruneMode || 'dangling') ||- formDefaultShell !== (settings.defaultShell || '/bin/sh') ||- formProjectsDirectory !== (settings.projectsDirectory || '/app/data/projects') ||- formDiskUsagePath !== (settings.diskUsagePath || '/app/data/projects') ||- formMaxImageUploadSize !== (settings.maxImageUploadSize || 500) ||- formBaseServerUrl !== (settings.baseServerUrl || 'http://localhost') ||- formScheduledPruneEnabled !== (settings.scheduledPruneEnabled ?? false) ||- formScheduledPruneInterval !== (settings.scheduledPruneInterval ?? 1440) ||- formScheduledPruneContainers !== (settings.scheduledPruneContainers ?? true) ||- formScheduledPruneImages !== (settings.scheduledPruneImages ?? true) ||- formScheduledPruneVolumes !== (settings.scheduledPruneVolumes ?? false) ||- formScheduledPruneNetworks !== (settings.scheduledPruneNetworks ?? true) ||- formScheduledPruneBuildCache !== (settings.scheduledPruneBuildCache ?? false)))- );-async function refreshEnvironment() {if (isRefreshing) return;try {isRefreshing = true;await invalidateAll();- // Update form values after refresh- formName = environment.name;- formEnabled = environment.enabled;- formApiUrl = environment.apiUrl;currentStatus = environment.status;-- if (settings) {- formPollingEnabled = settings.pollingEnabled;- formPollingInterval = settings.pollingInterval;- formAutoUpdate = settings.autoUpdate;- formAutoUpdateInterval = settings.autoUpdateInterval;- formAutoInjectEnv = settings.autoInjectEnv;- formPruneMode = settings.dockerPruneMode || 'dangling';- formDefaultShell = settings.defaultShell || '/bin/sh';- formProjectsDirectory = settings.projectsDirectory || '/app/data/projects';- formDiskUsagePath = settings.diskUsagePath || '/app/data/projects';- formMaxImageUploadSize = settings.maxImageUploadSize || 500;- formBaseServerUrl = settings.baseServerUrl || 'http://localhost';- formScheduledPruneEnabled = settings.scheduledPruneEnabled ?? false;- formScheduledPruneInterval = settings.scheduledPruneInterval ?? 1440;- formScheduledPruneContainers = settings.scheduledPruneContainers ?? true;- formScheduledPruneImages = settings.scheduledPruneImages ?? true;- formScheduledPruneVolumes = settings.scheduledPruneVolumes ?? false;- formScheduledPruneNetworks = settings.scheduledPruneNetworks ?? true;- formScheduledPruneBuildCache = settings.scheduledPruneBuildCache ?? false;-- // Initialize derived states- pollingIntervalMode = imagePollingOptions.find((o) => o.minutes === settings.pollingInterval)?.value ?? 'custom';- shellSelectValue = shellOptions.find((o) => o.value === settings.defaultShell)?.value ?? 'custom';- }-// Reset version to trigger re-fetch if onlineremoteVersion = null;} catch (err) {@@ -295,7 +304,7 @@if (isTestingConnection) return;try {isTestingConnection = true;- const customUrl = formApiUrl !== environment.apiUrl ? formApiUrl : undefined;+ const customUrl = $formInputs.apiUrl.value !== environment.apiUrl ? $formInputs.apiUrl.value : undefined;const result = await environmentManagementService.testConnection(environment.id, customUrl);// Update current status based on test result@@ -321,93 +330,6 @@}}- async function handleSave() {- if (!hasChanges || isSaving) return;-- try {- isSaving = true;- const sanitizedScheduledPruneInterval = Math.min(Math.max(formScheduledPruneInterval || 0, 60), 10080);- formScheduledPruneInterval = sanitizedScheduledPruneInterval;-- // Update environment basic info- await environmentManagementService.update(environment.id, {- name: formName,- enabled: formEnabled,- apiUrl: formApiUrl- });-- // Update environment settings if they exist- if (settings) {- await settingsService.updateSettingsForEnvironment(environment.id, {- pollingEnabled: formPollingEnabled,- pollingInterval: formPollingInterval,- autoUpdate: formAutoUpdate,- autoUpdateInterval: formAutoUpdateInterval,- autoInjectEnv: formAutoInjectEnv,- dockerPruneMode: formPruneMode,- defaultShell: formDefaultShell,- projectsDirectory: formProjectsDirectory,- diskUsagePath: formDiskUsagePath,- maxImageUploadSize: formMaxImageUploadSize,- baseServerUrl: formBaseServerUrl,- scheduledPruneEnabled: formScheduledPruneEnabled,- scheduledPruneInterval: sanitizedScheduledPruneInterval,- scheduledPruneContainers: formScheduledPruneContainers,- scheduledPruneImages: formScheduledPruneImages,- scheduledPruneVolumes: formScheduledPruneVolumes,- scheduledPruneNetworks: formScheduledPruneNetworks,- scheduledPruneBuildCache: formScheduledPruneBuildCache- });- }-- toast.success(m.common_update_success({ resource: m.resource_environment_cap() }));- await refreshEnvironment();-- // Update environment store if this is the current environment- if (currentEnvironment?.id === environment.id) {- await environmentStore.initialize(- (- await environmentManagementService.getEnvironments({- pagination: { page: 1, limit: 1000 }- })- ).data- );- }- } catch (error) {- console.error('Failed to save environment:', error);- const message = error instanceof Error ? error.message : undefined;- toast.error(message ?? m.common_update_failed({ resource: m.resource_environment() }));- } finally {- isSaving = false;- }- }-- function handleReset() {- formName = environment.name;- formEnabled = environment.enabled;- formApiUrl = environment.apiUrl;-- if (settings) {- formPollingEnabled = settings.pollingEnabled;- formPollingInterval = settings.pollingInterval;- formAutoUpdate = settings.autoUpdate;- formAutoUpdateInterval = settings.autoUpdateInterval;- formAutoInjectEnv = settings.autoInjectEnv;- formPruneMode = settings.dockerPruneMode || 'dangling';- formDefaultShell = settings.defaultShell || '/bin/sh';- formProjectsDirectory = settings.projectsDirectory || '/app/data/projects';- formDiskUsagePath = settings.diskUsagePath || '/app/data/projects';- formMaxImageUploadSize = settings.maxImageUploadSize || 500;- formBaseServerUrl = settings.baseServerUrl || 'http://localhost';-- // Initialize derived states- pollingIntervalMode = imagePollingOptions.find((o) => o.minutes === settings.pollingInterval)?.value ?? 'custom';- shellSelectValue = shellOptions.find((o) => o.value === settings.defaultShell)?.value ?? 'custom';- }-- toast.info(m.environments_changes_reset());- }-async function handleRegenerateApiKey() {try {isRegeneratingKey = true;@@ -453,27 +375,27 @@<div class="flex flex-wrap items-center gap-2"><div class="hidden items-center gap-2 sm:flex">- {#if hasChanges}+ {#if settingsForm.hasChanges}<span class="text-xs text-orange-600 dark:text-orange-400">{m.environments_unsaved_changes()}</span>{:else}<span class="text-xs text-green-600 dark:text-green-400">{m.environments_all_changes_saved()}</span>{/if}- {#if hasChanges}+ {#if settingsForm.hasChanges}<ArcaneButtonaction="restart"tone="outline"- onclick={handleReset}- disabled={isSaving}+ onclick={resetForm}+ disabled={settingsForm.isLoading}customLabel={m.common_reset()}/>{/if}<ArcaneButtonaction="save"- onclick={handleSave}- disabled={!hasChanges || isSaving}- loading={isSaving}+ onclick={onSubmit}+ disabled={!settingsForm.hasChanges || settingsForm.isLoading}+ loading={settingsForm.isLoading}customLabel={m.common_save()}loadingLabel={m.common_saving()}/>@@ -550,10 +472,13 @@<Inputid="env-name"type="text"- bind:value={formName}- class="mt-1.5 w-full"+ bind:value={$formInputs.name.value}+ class="mt-1.5 w-full {$formInputs.name.error ? 'border-destructive' : ''}"placeholder={m.environments_name_placeholder()}/>+ {#if $formInputs.name.error}+ <p class="text-destructive mt-1 text-[0.8rem] font-medium">{$formInputs.name.error}</p>+ {/if}</div><div>@@ -565,7 +490,7 @@<Inputid="api-url"type="url"- bind:value={formApiUrl}+ bind:value={$formInputs.apiUrl.value}class="w-full font-mono"placeholder={m.environments_api_url_placeholder()}disabled={true}@@ -580,7 +505,7 @@<Inputid="api-url"type="url"- bind:value={formApiUrl}+ bind:value={$formInputs.apiUrl.value}class="w-full font-mono"placeholder={m.environments_api_url_placeholder()}required@@ -608,14 +533,14 @@{#if environment.id === '0'}<ArcaneTooltip.Root><ArcaneTooltip.Trigger>- <Switch id="env-enabled" disabled={true} bind:checked={formEnabled} />+ <Switch id="env-enabled" disabled={true} bind:checked={$formInputs.enabled.value} /></ArcaneTooltip.Trigger><ArcaneTooltip.Content><p>{m.environments_local_setting_disabled()}</p></ArcaneTooltip.Content></ArcaneTooltip.Root>{:else}- <Switch id="env-enabled" bind:checked={formEnabled} />+ <Switch id="env-enabled" bind:checked={$formInputs.enabled.value} />{/if}</div>@@ -697,7 +622,8 @@<TextInputWithLabelid="projects-directory"label={m.general_projects_directory_label()}- bind:value={formProjectsDirectory}+ bind:value={$formInputs.projectsDirectory.value}+ error={$formInputs.projectsDirectory.error}helpText={m.general_projects_directory_help()}/></div>@@ -705,7 +631,8 @@<TextInputWithLabelid="disk-usage-path"label={m.disk_usage_settings()}- bind:value={formDiskUsagePath}+ bind:value={$formInputs.diskUsagePath.value}+ error={$formInputs.diskUsagePath.error}helpText={m.disk_usage_settings_description()}/></div>@@ -713,7 +640,8 @@<TextInputWithLabelid="base-server-url"label={m.general_base_url_label()}- bind:value={formBaseServerUrl}+ bind:value={$formInputs.baseServerUrl.value}+ error={$formInputs.baseServerUrl.error}helpText={m.general_base_url_help()}/></div>@@ -722,7 +650,8 @@id="max-upload-size"type="number"label={m.docker_max_upload_size_label()}- bind:value={formMaxImageUploadSize}+ bind:value={$formInputs.maxImageUploadSize.value}+ error={$formInputs.maxImageUploadSize.error}helpText={m.docker_max_upload_size_description()}/></div>@@ -737,15 +666,16 @@<Label for="polling-enabled" class="text-sm font-medium">{m.docker_enable_polling_label()}</Label><div class="text-muted-foreground text-xs">{m.docker_enable_polling_description()}</div></div>- <Switch id="polling-enabled" bind:checked={formPollingEnabled} />+ <Switch id="polling-enabled" bind:checked={$formInputs.pollingEnabled.value} /></div>- {#if formPollingEnabled}+ {#if $formInputs.pollingEnabled.value}<div class="space-y-3 pt-2"><SelectWithLabelid="pollingIntervalMode"name="pollingIntervalMode"bind:value={pollingIntervalMode}+ onValueChange={handlePollingIntervalModeChange}label={m.docker_polling_interval_label()}placeholder={m.docker_polling_interval_placeholder_select()}options={imagePollingOptions.map(({ value, label, description }) => ({@@ -757,7 +687,8 @@{#if pollingIntervalMode === 'custom'}<TextInputWithLabel- bind:value={formPollingInterval}+ bind:value={$formInputs.pollingInterval.value}+ error={$formInputs.pollingInterval.error}label={m.custom_polling_interval()}placeholder={m.docker_polling_interval_placeholder()}helpText={m.docker_polling_interval_description()}@@ -765,7 +696,7 @@/>{/if}- {#if formPollingInterval < 30}+ {#if $formInputs.pollingInterval.value < 30}<divclass="flex items-start gap-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-amber-900 dark:text-amber-200">@@ -787,13 +718,18 @@<Label for="auto-update" class="text-sm font-medium">{m.docker_auto_update_label()}</Label><div class="text-muted-foreground text-xs">{m.docker_auto_update_description()}</div></div>- <Switch id="auto-update" bind:checked={formAutoUpdate} disabled={!formPollingEnabled} />+ <Switch+ id="auto-update"+ bind:checked={$formInputs.autoUpdate.value}+ disabled={!$formInputs.pollingEnabled.value}+ /></div>- {#if formAutoUpdate && formPollingEnabled}+ {#if $formInputs.autoUpdate.value && $formInputs.pollingEnabled.value}<div class="pt-2"><TextInputWithLabel- bind:value={formAutoUpdateInterval}+ bind:value={$formInputs.autoUpdateInterval.value}+ error={$formInputs.autoUpdateInterval.error}label={m.docker_auto_update_interval_label()}placeholder={m.docker_auto_update_interval_placeholder()}helpText={m.docker_auto_update_interval_description()}@@ -808,12 +744,12 @@<SelectWithLabelid="dockerPruneMode"name="pruneMode"- bind:value={formPruneMode}+ bind:value={$formInputs.dockerPruneMode.value}label={m.docker_prune_action_label()}description={pruneModeDescription}placeholder={m.docker_prune_placeholder()}options={pruneModeOptions}- onValueChange={(v) => (formPruneMode = v as 'all' | 'dangling')}+ onValueChange={(v) => ($formInputs.dockerPruneMode.value = v as 'all' | 'dangling')}/></div>@@ -823,6 +759,7 @@id="shellSelectValue"name="shellSelectValue"bind:value={shellSelectValue}+ onValueChange={handleShellSelectChange}label={m.docker_default_shell_label()}description={m.docker_default_shell_description()}placeholder={m.docker_default_shell_placeholder()}@@ -835,7 +772,8 @@{#if shellSelectValue === 'custom'}<div class="pt-2"><TextInputWithLabel- bind:value={formDefaultShell}+ bind:value={$formInputs.defaultShell.value}+ error={$formInputs.defaultShell.error}label={m.custom()}placeholder={m.docker_shell_custom_path_placeholder()}helpText={m.docker_shell_custom_path_help()}@@ -851,7 +789,7 @@<Label for="auto-inject-env" class="text-sm font-medium">{m.docker_auto_inject_env_label()}</Label><div class="text-muted-foreground text-xs">{m.docker_auto_inject_env_description()}</div></div>- <Switch id="auto-inject-env" bind:checked={formAutoInjectEnv} />+ <Switch id="auto-inject-env" bind:checked={$formInputs.autoInjectEnv.value} /></div></div></div>@@ -865,15 +803,16 @@{m.scheduled_prune_description()}</div></div>- <Switch bind:checked={formScheduledPruneEnabled} />+ <Switch bind:checked={$formInputs.scheduledPruneEnabled.value} /></div>- {#if formScheduledPruneEnabled}+ {#if $formInputs.scheduledPruneEnabled.value}<div class="space-y-4 pt-2"><TextInputWithLabelid="scheduled-prune-interval"label={m.scheduled_prune_interval_label()}- bind:value={formScheduledPruneInterval}+ bind:value={$formInputs.scheduledPruneInterval.value}+ error={$formInputs.scheduledPruneInterval.error}placeholder="1440"helpText={m.scheduled_prune_interval_description()}type="number"@@ -885,39 +824,39 @@<Label class="text-sm font-medium">{m.scheduled_prune_containers_label()}</Label><p class="text-muted-foreground text-xs">{m.scheduled_prune_containers_description()}</p></div>- <Switch bind:checked={formScheduledPruneContainers} />+ <Switch bind:checked={$formInputs.scheduledPruneContainers.value} /></div><div class="flex items-start justify-between rounded-lg border p-3"><div class="space-y-0.5"><Label class="text-sm font-medium">{m.scheduled_prune_images_label()}</Label><p class="text-muted-foreground text-xs">{m.scheduled_prune_images_description()}</p></div>- <Switch bind:checked={formScheduledPruneImages} />+ <Switch bind:checked={$formInputs.scheduledPruneImages.value} /></div><div class="flex items-start justify-between rounded-lg border p-3"><div class="space-y-0.5"><Label class="text-sm font-medium">{m.scheduled_prune_volumes_label()}</Label><p class="text-muted-foreground text-xs">{m.scheduled_prune_volumes_description()}</p></div>- <Switch bind:checked={formScheduledPruneVolumes} />+ <Switch bind:checked={$formInputs.scheduledPruneVolumes.value} /></div><div class="flex items-start justify-between rounded-lg border p-3"><div class="space-y-0.5"><Label class="text-sm font-medium">{m.scheduled_prune_networks_label()}</Label><p class="text-muted-foreground text-xs">{m.scheduled_prune_networks_description()}</p></div>- <Switch bind:checked={formScheduledPruneNetworks} />+ <Switch bind:checked={$formInputs.scheduledPruneNetworks.value} /></div><div class="flex items-start justify-between rounded-lg border p-3"><div class="space-y-0.5"><Label class="text-sm font-medium">{m.scheduled_prune_build_cache_label()}</Label><p class="text-muted-foreground text-xs">{m.scheduled_prune_build_cache_description()}</p></div>- <Switch bind:checked={formScheduledPruneBuildCache} />+ <Switch bind:checked={$formInputs.scheduledPruneBuildCache.value} /></div></div>- {#if formScheduledPruneVolumes}+ {#if $formInputs.scheduledPruneVolumes.value}<divclass="flex items-start gap-3 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-amber-900 dark:text-amber-200">@@ -1026,4 +965,9 @@</AlertDialog.Root></div>-<MobileFloatingFormActions {hasChanges} isLoading={isSaving} onSave={handleSave} onReset={handleReset} />+<MobileFloatingFormActions+ hasChanges={settingsForm.hasChanges}+ isLoading={settingsForm.isLoading}+ onSave={onSubmit}+ onReset={resetForm}+/>