57 lines
1.8 KiB
Svelte
57 lines
1.8 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from 'svelte';
|
|
import { page } from '$app/stores';
|
|
import SectionHeader from '$ui/components/primitives/SectionHeader.svelte';
|
|
import SettingsEditor from '$ui/components/SettingsEditor.svelte';
|
|
import Button from '$ui/components/primitives/Button.svelte';
|
|
import { validateFleetSettings, type FleetSettings } from '$lib/fleet-settings.js';
|
|
let settings = $state<FleetSettings | null>(null);
|
|
let loading = $state(true);
|
|
let error = $state('');
|
|
onMount(() => {
|
|
void loadSettings();
|
|
});
|
|
|
|
async function loadSettings() {
|
|
loading = true;
|
|
error = '';
|
|
try {
|
|
const response = await fetch('/api/settings');
|
|
if (!response.ok) throw new Error('Could not load fleet settings.');
|
|
settings = validateFleetSettings(await response.json());
|
|
} catch (cause) {
|
|
error = cause instanceof Error ? cause.message : 'Could not load fleet settings.';
|
|
} finally {
|
|
loading = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<svelte:head><title>Settings · Electric Cherry</title></svelte:head>
|
|
<section class="page">
|
|
<SectionHeader
|
|
title="Settings"
|
|
subtitle="Shared fleet limits and history retention. Changes apply without restarting."
|
|
/>
|
|
{#if loading}<p role="status">Loading fleet settings…</p>
|
|
{:else if settings}<SettingsEditor
|
|
initial={settings}
|
|
readOnly={$page.data.user?.role !== 'admin'}
|
|
/>
|
|
{:else}<div>
|
|
<p class="ui-error" role="alert">{error}</p>
|
|
<Button onclick={loadSettings}>Retry loading</Button>
|
|
</div>{/if}
|
|
</section>
|
|
|
|
<style>
|
|
.page {
|
|
display: grid;
|
|
gap: var(--space-4);
|
|
}
|
|
p {
|
|
font-size: var(--text-sm);
|
|
color: var(--text-secondary);
|
|
}
|
|
</style>
|