feat: add server URL input to profile bar
Type URL + Enter or click Set. Persisted via localStorage. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,31 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import { getProfiles } from "$lib/api";
|
import { getProfiles, setServer, getServer } from "$lib/api";
|
||||||
import { profile, subprofiles } from "$lib/stores";
|
import { profile, subprofiles, serverUrl } from "$lib/stores";
|
||||||
|
import { saveSettings } from "$lib/settings";
|
||||||
|
|
||||||
let profiles = $state<string[]>([]);
|
let profiles = $state<string[]>([]);
|
||||||
|
let serverInput = $state(getServer());
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
serverInput = getServer();
|
||||||
|
try {
|
||||||
profiles = await getProfiles();
|
profiles = await getProfiles();
|
||||||
if (profiles.length && !profiles.includes($profile)) {
|
if (profiles.length && !profiles.includes($profile)) {
|
||||||
$profile = profiles[0];
|
$profile = profiles[0];
|
||||||
}
|
}
|
||||||
|
} catch { /* server not reachable yet */ }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function applyServer() {
|
||||||
|
const url = serverInput.replace(/\/+$/, "");
|
||||||
|
setServer(url);
|
||||||
|
$serverUrl = url;
|
||||||
|
saveSettings();
|
||||||
|
// Reload profiles from new server
|
||||||
|
getProfiles().then(p => { profiles = p; }).catch(() => {});
|
||||||
|
}
|
||||||
|
|
||||||
function addSubprofile() {
|
function addSubprofile() {
|
||||||
const name = prompt("Subprofile suffix:");
|
const name = prompt("Subprofile suffix:");
|
||||||
if (name && !$subprofiles.includes(name)) {
|
if (name && !$subprofiles.includes(name)) {
|
||||||
@@ -25,6 +39,15 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="profile-bar">
|
<div class="profile-bar">
|
||||||
|
<input
|
||||||
|
class="server-input"
|
||||||
|
type="text"
|
||||||
|
bind:value={serverInput}
|
||||||
|
onkeydown={(e) => { if (e.key === "Enter") applyServer(); }}
|
||||||
|
placeholder="http://host:8000"
|
||||||
|
/>
|
||||||
|
<button onclick={applyServer}>Set</button>
|
||||||
|
|
||||||
<select bind:value={$profile}>
|
<select bind:value={$profile}>
|
||||||
{#each profiles as p}
|
{#each profiles as p}
|
||||||
<option value={p}>{p}</option>
|
<option value={p}>{p}</option>
|
||||||
@@ -49,6 +72,14 @@
|
|||||||
padding: 4px;
|
padding: 4px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
.server-input {
|
||||||
|
width: 180px;
|
||||||
|
background: #2d2d2d;
|
||||||
|
color: #e0e0e0;
|
||||||
|
border: 1px solid #444;
|
||||||
|
padding: 2px 4px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
select { background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
|
select { background: #2d2d2d; color: #e0e0e0; border: 1px solid #444; }
|
||||||
.subs { display: flex; gap: 4px; align-items: center; }
|
.subs { display: flex; gap: 4px; align-items: center; }
|
||||||
.sub-tag {
|
.sub-tag {
|
||||||
|
|||||||
Reference in New Issue
Block a user