chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.4.0 Latest 5 packages
0
0
<script lang="ts">
import { onMount } from 'svelte';
import type * as deleteAccountData from '../lexicons/place/hud/deleteAccountData.defs.ts';
import type * as getAccountData from '../lexicons/place/hud/getAccountData.defs.ts';
import type { Actor } from '../model';
import Dialog from '../molecules/Dialog.svelte';
import { procedure, SignedOut, xrpc, XrpcError, type Answer } from '../xrpc';
/**
* Deleting everything HUD keeps for `me`, as knotless's: what there is,
* read as the dialog opens, the canvases they own named, those shared
* with others marked, as they go for everyone in them; then, once their
* handle is typed, one call deletes it all and signs them out
* everywhere, and the page is read again as the server left this
* browser: the next account it holds, else signed out.
*/
let { me, onclose }: { me: Actor; onclose: () => void } = $props();
const id = 'delete-data';
/** What they type to confirm: their handle, else their DID. */
const handle = $derived(me.handle?.replace(/^@/, '') ?? me.did);
let held = $state<Answer<typeof getAccountData.main> | null>(null);
let typed = $state('');
let problem = $state('');
let reading = $state(true);
let busy = $state(false);
/** `count` of a thing, as a person reads it. */
const n = (count: number, one: string, many: string) => (count === 1 ? `1 ${one}` : `${count.toLocaleString('en-US')} ${many}`);
/** What goes, each part as the summary says it. */
const parts = $derived(
held
? [
held.canvases.length ? n(held.canvases.length, 'canvas you own', 'canvases you own') : '',
held.shared ? `your place in ${n(held.shared, 'canvas of others', 'canvases of others')}` : '',
held.invitations ? n(held.invitations, 'invitation', 'invitations') : '',
held.themes ? n(held.themes, 'theme you published', 'themes you published') : '',
held.chosenTheme ? 'your theme choice' : ''
].filter(Boolean)
: []
);
const summary = $derived(`This deletes ${parts.length > 1 ? `${parts.slice(0, -1).join(', ')} and ${parts.at(-1)}` : parts[0]}, for good.`);
const shared = $derived(held?.canvases.some((canvas) => canvas.members > 0) ?? false);
onMount(() => void read());
async function read() {
try {
held = await xrpc<typeof getAccountData.main>('place.hud.getAccountData', {});
} catch (error) {
if (!(error instanceof SignedOut)) problem = error instanceof XrpcError ? error.message : 'Reading what HUD holds did not work. Try again.';
}
reading = false;
}
async function remove(event: SubmitEvent) {
event.preventDefault();
if (busy || typed.trim().replace(/^@/, '') !== handle) return;
busy = true;
problem = '';
try {
await procedure<typeof deleteAccountData.main>('place.hud.deleteAccountData', { did: me.did as deleteAccountData.$InputBody['did'] });
location.reload();
} catch (error) {
problem = `${error instanceof XrpcError ? error.message : 'Deleting did not work.'} What is deleted stays deleted: try again to carry on.`;
busy = false;
}
}
</script>
<Dialog {id} title="Delete your HUD data" class="delete-data" held={busy} {onclose}>
<p class="hint">
Everything HUD keeps for you goes for good: the canvases you own, for everyone in them, your place in others’ canvases and the tiles you put there, your invitations, your tabs, the
themes you published and your theme choice. You’re then signed out everywhere. Your atproto account, and what other apps keep in it, stay.
</p>
{#if reading}
<p class="hint" role="status" data-loading>Reading what HUD holds for you…</p>
{:else if held && !parts.length}
<p class="hint">HUD holds no data for you.</p>
{:else if held}
<p class="summary">{summary}</p>
{#if held.canvases.length}
<h3>Canvases you own</h3>
{#if shared}<p class="hint">A canvas shared with others goes for them too.</p>{/if}
<ul class="canvases">
{#each held.canvases as canvas (canvas.canvas)}
<li>
<span class="name">{canvas.name}</span>
{#if canvas.members}<span class="mute">{`Shared with ${n(canvas.members, 'other', 'others')}`}</span>{/if}
</li>
{/each}
</ul>
{/if}
<form onsubmit={remove}>
<label for="{id}-typed">{`To confirm, type ${handle}`}</label>
<input id="{id}-typed" class="input" name="confirm" autocapitalize="none" autocomplete="off" spellcheck="false" disabled={busy} bind:value={typed} />
{#if problem}<p class="problem" role="alert">{problem}</p>{/if}
<button class="btn danger solid" type="submit" disabled={busy || typed.trim().replace(/^@/, '') !== handle} aria-busy={busy}>{busy ? 'Deleting…' : 'Delete all my HUD data'}</button>
</form>
{/if}
{#if problem && !held}<p class="problem" role="alert">{problem}</p>{/if}
</Dialog>
<style>
:global(.dialog.delete-data) {
display: flex;
flex-direction: column;
gap: var(--space-3);
max-height: min(80vh, 40rem);
}
.hint {
color: var(--mute);
font-size: var(--text-sm);
}
.summary {
font-size: var(--text-sm);
}
h3 {
font-size: var(--text-sm);
font-weight: var(--weight-semibold);
}
/* The canvases, each a row: its name, cut short, then whom it is shared with. */
.canvases {
display: flex;
flex-direction: column;
min-height: 0;
margin: 0;
padding: 0;
overflow-y: auto;
border: var(--border);
border-radius: var(--radius-md);
font-size: var(--text-sm);
list-style: none;
}
.canvases li {
display: flex;
align-items: baseline;
gap: var(--space-2);
padding: var(--space-2) var(--space-3);
}
.canvases li + li {
border-top: var(--border);
}
.name {
flex: 1;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.canvases .mute {
flex: none;
}
form {
display: flex;
flex-direction: column;
gap: var(--space-2);
margin-top: var(--space-1);
}
label {
font-size: var(--text-sm);
font-weight: var(--weight-medium);
}
.btn.solid {
justify-content: center;
border-color: var(--danger);
background: var(--danger);
color: var(--on-solid);
}
.btn.solid:hover:not(:disabled) {
opacity: 0.85;
}
</style>