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">
|
||||
import StatBadge from '$lib/components/StatBadge.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Provider presets
|
||||
@@ -49,13 +48,16 @@
|
||||
let loading = $state(true);
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Load current config on mount
|
||||
// Load current config + probe local provider on mount (Svelte 5 $effect)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
onMount(async () => {
|
||||
$effect(() => {
|
||||
let cancelled = false;
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/v1/settings/embedding');
|
||||
if (res.ok) {
|
||||
if (!cancelled && res.ok) {
|
||||
const data = await res.json();
|
||||
provider = data.provider ?? 'none';
|
||||
if (data.openai) {
|
||||
@@ -68,7 +70,7 @@
|
||||
} catch {
|
||||
// Non-fatal — fall back to defaults
|
||||
} finally {
|
||||
loading = false;
|
||||
if (!cancelled) loading = false;
|
||||
}
|
||||
|
||||
// Probe whether the local provider is available
|
||||
@@ -78,9 +80,24 @@
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ provider: 'local' })
|
||||
});
|
||||
localAvailable = res.ok;
|
||||
if (!cancelled) localAvailable = res.ok;
|
||||
} catch {
|
||||
localAvailable = false;
|
||||
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>
|
||||
{/if}
|
||||
|
||||
<!-- Save row -->
|
||||
<div class="mt-6 flex items-center justify-end gap-3">
|
||||
<!-- Save feedback banners -->
|
||||
{#if saveStatus === 'ok'}
|
||||
<span class="text-sm text-green-600">Settings saved.</span>
|
||||
<div
|
||||
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"
|
||||
>
|
||||
<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="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'}
|
||||
<span class="text-sm text-red-600">{saveError}</span>
|
||||
<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
|
||||
onclick={save}
|
||||
disabled={saving}
|
||||
|
||||
Reference in New Issue
Block a user