[web] Domi UI: the web UI on @domi/ui v1.0.0 (fonts, roles, Button, TextField with seals, Checkbox, Select, Segmented)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
// Handoff §8.3: Settings with General, API (⚙ → API → New token = 3 clicks, Copy token the
|
||||
// accepted 4th), Share links and About.
|
||||
import { onMount } from "svelte";
|
||||
import { DomiError, TextField } from "@domi/ui";
|
||||
import { Banner, Button, Dialog, Segmented } from "@ianitor/ui";
|
||||
import { ApiError, call, del, get, newKey, patch, post, sentence } from "../lib/api";
|
||||
import { app, navigate, toast } from "../lib/app.svelte";
|
||||
@@ -92,23 +93,30 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Renames the new token now (its field's seal) or when the dialog closes. False when the name was refused.
|
||||
async function rename(): Promise<boolean> {
|
||||
if (!made || !tokenName.trim() || tokenName.trim() === made.name) return true;
|
||||
nameErr = null;
|
||||
try {
|
||||
await patch(`/tokens/${encodeURIComponent(made.id)}`, { name: tokenName.trim() });
|
||||
made.name = tokenName.trim();
|
||||
toast("Renamed.");
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === "token.name") {
|
||||
nameErr = e.body.message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function closeToken(force = false) {
|
||||
if (!made) return;
|
||||
if (!tokenCopied && !force) {
|
||||
askClose = true;
|
||||
return;
|
||||
}
|
||||
if (tokenName.trim() && tokenName !== made.name) {
|
||||
try {
|
||||
await patch(`/tokens/${encodeURIComponent(made.id)}`, { name: tokenName.trim() });
|
||||
toast("Renamed.");
|
||||
} catch (e) {
|
||||
if (e instanceof ApiError && e.code === "token.name") {
|
||||
nameErr = e.body.message;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(await rename())) return;
|
||||
// The token leaves memory with the dialog.
|
||||
made = null;
|
||||
tokenName = "";
|
||||
@@ -169,7 +177,7 @@
|
||||
<p>{settings?.watch_seconds ?? app.overview?.site?.watch_seconds ?? 60} seconds</p>
|
||||
<p class="ia-label">Signed in</p>
|
||||
<p>{viewer ? (viewer.via === "authelia" ? `${viewer.name} through Authelia` : `API token "${viewer.name}"`) : "Through Authelia"}</p>
|
||||
{#if app.overview?.site?.auth_logout_url}<p><a class="domi-btn link" href={app.overview.site.auth_logout_url}>Sign out</a></p>{/if}
|
||||
{#if app.overview?.site?.auth_logout_url}<p><a class="ia-link" href={app.overview.site.auth_logout_url}>Sign out</a></p>{/if}
|
||||
{:else if tab === "api"}
|
||||
<div class="row">
|
||||
<h2 class="ia-h3">API tokens</h2>
|
||||
@@ -236,7 +244,7 @@
|
||||
<p>Ianitor Domi 0.1.0</p>
|
||||
<p>MPL-2.0</p>
|
||||
<p>Built, tested and signed by Fabrica Domi</p>
|
||||
<p><a class="domi-btn link" href="https://gitea.marek-novak.cz/mnovak/Ianitor" rel="noreferrer">Source on Gitea</a></p>
|
||||
<p><a class="ia-link" href="https://gitea.marek-novak.cz/mnovak/Ianitor" rel="noreferrer">Source on Gitea</a></p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -246,12 +254,9 @@
|
||||
<p class="ia-text2">Ianitor cannot show it again; if it is lost, make a new one and revoke this one.</p>
|
||||
<input class="ia-secret" readonly value={made.token} aria-label="New API token" onfocus={(e) => (e.currentTarget as HTMLInputElement).select()} />
|
||||
<div class="grid">
|
||||
<div class="domi-field">
|
||||
<label class="domi-field-label" for="token-name">Name</label>
|
||||
<input id="token-name" class="domi-input" bind:value={tokenName} aria-invalid={nameErr ? "true" : undefined} />
|
||||
{#if nameErr}<p class="domi-error">{nameErr}</p>{/if}
|
||||
<p class="ia-hint">Rename it now or later, so you know what uses it.</p>
|
||||
</div>
|
||||
<TextField id="token-name" label="Name" bind:value={tokenName} autocomplete="off" action="save" actionLabel="Rename the token"
|
||||
onsend={async () => { if (!(await rename())) throw new DomiError(nameErr ?? "That name was not accepted."); }}
|
||||
error={nameErr ?? undefined} hint="Rename it now or later, so you know what uses it." />
|
||||
<Button variant={tokenCopied ? "quiet" : "primary"} icon="copy" onclick={copyToken} data-autofocus>{tokenCopied ? "Copy again" : "Copy token"}</Button>
|
||||
</div>
|
||||
{#if tokenCopied}<p role="status">Copied. Paste it into Custos now. Ianitor cannot show it again.</p>{/if}
|
||||
@@ -266,15 +271,15 @@
|
||||
|
||||
<style>
|
||||
.tabs { display: flex; gap: 4px; overflow-x: auto; }
|
||||
.tabs [role="tab"] { min-height: 44px; padding: 0 1rem; border-radius: var(--radius-sm); border: 0; background: none; color: var(--text-2); font-weight: 600; cursor: pointer; }
|
||||
.tabs [role="tab"][aria-selected="true"] { background: var(--surface-2); color: var(--text); }
|
||||
.tabs [role="tab"] { min-height: 44px; padding: 0 1rem; border-radius: var(--radius-sm); border: 0; background: none; color: var(--domi-fg-2); font-weight: 600; cursor: pointer; }
|
||||
.tabs [role="tab"][aria-selected="true"] { background: var(--domi-hover); color: var(--domi-fg); }
|
||||
.panel { display: flex; flex-direction: column; gap: 10px; }
|
||||
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
|
||||
.rows { list-style: none; margin: 0; padding: 0; }
|
||||
.rows li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-height: 44px; padding: 8px 0; border-top: 1px solid var(--hairline); }
|
||||
.rows li { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-height: 44px; padding: 8px 0; border-top: 1px solid var(--domi-line); }
|
||||
.grow { flex: 1 1 200px; min-width: 0; }
|
||||
.tname { font-weight: 600; }
|
||||
.struck { text-decoration: line-through; color: var(--muted); }
|
||||
.struck { text-decoration: line-through; color: var(--domi-muted); }
|
||||
.grid { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; }
|
||||
@media (max-width: 719.98px) { .grid { grid-template-columns: 1fr; } }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user