Skip to content

Commit ce2f9d1

Browse files
committed
feat: Refactors settings dialog with Svelte runes
Migrates the settings dialog to use Svelte 5 runes for improved state management and reactivity. It also replaces the previous settings management with a new `settings.svelte.ts` store, leveraging runes for reactive configuration updates, persistence, and theme management. This simplifies the settings logic and ensures consistent behavior across the application.
1 parent 8908088 commit ce2f9d1

File tree

6 files changed

+207
-152
lines changed

6 files changed

+207
-152
lines changed

tools/server/webui/src/lib/components/app/ServerStatus.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
<Server class="mr-1 h-3 w-3" />
4444
{model || 'Unknown Model'}
4545
</Badge>
46-
{#if serverData.n_ctx}
46+
{#if serverData.default_generation_settings.n_ctx}
4747
<Badge variant="secondary" class="text-xs">
48-
ctx: {serverData.n_ctx.toLocaleString()}
48+
ctx: {serverData.default_generation_settings.n_ctx.toLocaleString()}
4949
</Badge>
5050
{/if}
5151
{/if}

tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettingsContent.svelte

Lines changed: 0 additions & 44 deletions
This file was deleted.

tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettingsDialog.svelte

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<script lang="ts">
2-
import { Button } from '$lib/components/ui/button';
32
import { Checkbox } from '$lib/components/ui/checkbox';
43
import * as Dialog from '$lib/components/ui/dialog';
54
import { Input } from '$lib/components/ui/input';
65
import { ScrollArea } from '$lib/components/ui/scroll-area';
76
import { Textarea } from '$lib/components/ui/textarea';
87
import { Settings, Filter, Hand, MessageSquare, Plus, Beaker } from '@lucide/svelte';
9-
import type { FieldConfig } from '$lib/types/settings';
8+
import { SETTING_CONFIG_DEFAULT } from '$lib/constants/settings-config';
9+
import { type SettingsConfigType, type FieldConfig } from '$lib/types/settings';
1010
import {
11-
getConfig,
12-
setConfig,
13-
resetConfig,
14-
CONFIG_DEFAULT,
15-
type ConfigType
16-
} from '$lib/utils/settings';
11+
config,
12+
updateMultipleConfig,
13+
resetConfig
14+
} from '$lib/stores/settings.svelte';
1715
import ChatSettingsFooter from './ChatSettingsFooter.svelte';
1816
import ChatSettingsSection from './ChatSettingsSection.svelte';
1917
@@ -24,22 +22,26 @@
2422
2523
let { onOpenChange, open = false }: Props = $props();
2624
27-
// Load configuration from localStorage
28-
let config: ConfigType = $state(getConfig());
25+
let localConfig: SettingsConfigType = $state({ ...config() });
2926
30-
// Use CONFIG_DEFAULT for placeholders to avoid state reference issues
31-
const defaultConfig = CONFIG_DEFAULT;
27+
$effect(() => {
28+
if (open) {
29+
localConfig = { ...config() };
30+
}
31+
});
32+
33+
const defaultConfig = SETTING_CONFIG_DEFAULT;
3234
3335
function handleSave() {
34-
// Save configuration to localStorage
35-
setConfig(config);
36-
console.log('Settings saved to localStorage');
36+
updateMultipleConfig(localConfig);
37+
3738
onOpenChange?.(false);
3839
}
3940
4041
function handleReset() {
41-
// Reset to default configuration
42-
config = resetConfig();
42+
resetConfig();
43+
44+
localConfig = { ...SETTING_CONFIG_DEFAULT };
4345
}
4446
4547
function handleClose() {
@@ -136,7 +138,7 @@
136138
}
137139
];
138140
139-
const currentSection = $derived(
141+
let currentSection = $derived(
140142
settingSections.find((section) => section.title === activeSection) || settingSections[0]
141143
);
142144
</script>
@@ -175,9 +177,9 @@
175177

176178
<Input
177179
id={field.key}
178-
value={String(config[field.key] || '')}
180+
value={String(localConfig[field.key] || '')}
179181
onchange={(e) =>
180-
(config[field.key] = e.currentTarget.value)}
182+
(localConfig[field.key] = e.currentTarget.value)}
181183
placeholder={`Default: ${defaultConfig[field.key] || 'none'}`}
182184
class="max-w-md"
183185
/>
@@ -193,9 +195,9 @@
193195

194196
<Textarea
195197
id={field.key}
196-
value={String(config[field.key] || '')}
198+
value={String(localConfig[field.key] || '')}
197199
onchange={(e) =>
198-
(config[field.key] = e.currentTarget.value)}
200+
(localConfig[field.key] = e.currentTarget.value)}
199201
placeholder={`Default: ${defaultConfig[field.key] || 'none'}`}
200202
class="min-h-[100px] max-w-2xl"
201203
/>
@@ -208,9 +210,9 @@
208210
<div class="flex items-start space-x-3">
209211
<Checkbox
210212
id={field.key}
211-
checked={Boolean(config[field.key])}
213+
checked={Boolean(localConfig[field.key])}
212214
onCheckedChange={(checked) =>
213-
(config[field.key] = checked)}
215+
(localConfig[field.key] = checked)}
214216
class="mt-1"
215217
/>
216218

tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettingsField.svelte

Lines changed: 0 additions & 82 deletions
This file was deleted.

tools/server/webui/src/lib/components/app/chat/ChatSettings/ChatSettingsSidebar.svelte

Whitespace-only changes.

0 commit comments

Comments
 (0)