feat(EMBEDDINGS-0001): add save feedback banners and fix Svelte 5 runes compliance
Replace onMount with $effect for initial config loading. Add auto-dismissing green success banner (3 s) and persistent red error banner after save attempts. Remove inline status text in favour of full-width banners with icons. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import StatBadge from '$lib/components/StatBadge.svelte';
|
import StatBadge from '$lib/components/StatBadge.svelte';
|
||||||
import { onMount } from 'svelte';
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Provider presets
|
// Provider presets
|
||||||
@@ -49,38 +48,56 @@
|
|||||||
let loading = $state(true);
|
let loading = $state(true);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Load current config on mount
|
// Load current config + probe local provider on mount (Svelte 5 $effect)
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
onMount(async () => {
|
$effect(() => {
|
||||||
try {
|
let cancelled = false;
|
||||||
const res = await fetch('/api/v1/settings/embedding');
|
|
||||||
if (res.ok) {
|
|
||||||
const data = await res.json();
|
|
||||||
provider = data.provider ?? 'none';
|
|
||||||
if (data.openai) {
|
|
||||||
baseUrl = data.openai.baseUrl ?? baseUrl;
|
|
||||||
model = data.openai.model ?? model;
|
|
||||||
dimensions = data.openai.dimensions ?? dimensions;
|
|
||||||
// apiKey is intentionally not returned by the server; leave blank
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Non-fatal — fall back to defaults
|
|
||||||
} finally {
|
|
||||||
loading = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Probe whether the local provider is available
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/v1/settings/embedding/test', {
|
const res = await fetch('/api/v1/settings/embedding');
|
||||||
method: 'POST',
|
if (!cancelled && res.ok) {
|
||||||
headers: { 'Content-Type': 'application/json' },
|
const data = await res.json();
|
||||||
body: JSON.stringify({ provider: 'local' })
|
provider = data.provider ?? 'none';
|
||||||
});
|
if (data.openai) {
|
||||||
localAvailable = res.ok;
|
baseUrl = data.openai.baseUrl ?? baseUrl;
|
||||||
} catch {
|
model = data.openai.model ?? model;
|
||||||
localAvailable = false;
|
dimensions = data.openai.dimensions ?? dimensions;
|
||||||
|
// apiKey is intentionally not returned by the server; leave blank
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Non-fatal — fall back to defaults
|
||||||
|
} finally {
|
||||||
|
if (!cancelled) loading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Probe whether the local provider is available
|
||||||
|
try {
|
||||||
|
const res = await fetch('/api/v1/settings/embedding/test', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ provider: 'local' })
|
||||||
|
});
|
||||||
|
if (!cancelled) localAvailable = res.ok;
|
||||||
|
} catch {
|
||||||
|
if (!cancelled) localAvailable = false;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Auto-dismiss save success banner after 3 seconds
|
||||||
|
$effect(() => {
|
||||||
|
if (saveStatus === 'ok') {
|
||||||
|
const timer = setTimeout(() => {
|
||||||
|
saveStatus = 'idle';
|
||||||
|
}, 3000);
|
||||||
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -292,14 +309,49 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- Save row -->
|
<!-- Save feedback banners -->
|
||||||
<div class="mt-6 flex items-center justify-end gap-3">
|
{#if saveStatus === 'ok'}
|
||||||
{#if saveStatus === 'ok'}
|
<div
|
||||||
<span class="text-sm text-green-600">Settings saved.</span>
|
class="mt-4 flex items-center gap-2 rounded-lg border border-green-200 bg-green-50 px-4 py-3 text-sm font-medium text-green-700"
|
||||||
{:else if saveStatus === 'error'}
|
>
|
||||||
<span class="text-sm text-red-600">{saveError}</span>
|
<svg
|
||||||
{/if}
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
class="h-4 w-4 shrink-0"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
fill="currentColor"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
Settings saved successfully.
|
||||||
|
</div>
|
||||||
|
{:else if saveStatus === 'error'}
|
||||||
|
<div
|
||||||
|
class="mt-4 flex items-center gap-2 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm font-medium text-red-700"
|
||||||
|
>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
class="h-4 w-4 shrink-0"
|
||||||
|
viewBox="0 0 20 20"
|
||||||
|
fill="currentColor"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
{saveError}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<!-- Save row -->
|
||||||
|
<div class="mt-4 flex items-center justify-end">
|
||||||
<button
|
<button
|
||||||
onclick={save}
|
onclick={save}
|
||||||
disabled={saving}
|
disabled={saving}
|
||||||
|
|||||||
Reference in New Issue
Block a user