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 Avatar from '../atoms/Avatar.svelte';
import Handle from '../atoms/Handle.svelte';
import Icon from '../atoms/Icon.svelte';
import { handleText, type Actor } from '../model';
import { signOut, switchAccount, XrpcError } from '../xrpc';
/**
* The account menu, at the end of the tab bar, its button the face of
* whoever is signed in: them, checked, then the other accounts this
* browser is signed in to, each switching the whole page to it; another
* to add (`onadd`, the sign-in dialog), signing out, which goes on as
* the account used last, if any, and at its foot deleting their HUD data
* (`ondelete`, its dialog). On a phone it is a sheet.
*/
let {
open = $bindable(false),
me,
accounts,
onadd,
ondelete
}: {
open?: boolean;
me: Actor;
/** The other accounts this browser is signed in to, the one used last first. */
accounts: Actor[];
onadd: () => void;
/** Delete everything HUD keeps for them. */
ondelete: () => void;
} = $props();
let switching = $state(false);
/** Why switching did not work, said in the menu. */
let problem = $state('');
async function switchTo(did: string) {
switching = true;
problem = '';
try {
await switchAccount(did);
} catch (error) {
problem = error instanceof XrpcError ? error.message : 'Switching did not work. Try again.';
switching = false;
}
}
</script>
<details class="popover sheet end account" bind:open>
<summary class="face" title="Account: {handleText(me.did, me.handle)}" aria-label="Account"><Avatar did={me.did} handle={me.handle} /></summary>
<div class="menu">
<p class="menu-head">Accounts</p>
<div class="menu-item current" aria-current="true">
<Avatar did={me.did} handle={me.handle} />
<span class="who"><Handle did={me.did} handle={me.handle} /></span>
<Icon name="check" label="Signed in" />
</div>
{#each accounts as other (other.did)}
<button type="button" class="menu-item" title="Switch to {handleText(other.did, other.handle)}" disabled={switching} onclick={() => void switchTo(other.did)}>
<Avatar did={other.did} handle={other.handle} />
<span class="who"><Handle did={other.did} handle={other.handle} /></span>
</button>
{/each}
{#if problem}<p class="problem" role="alert">{problem}</p>{/if}
<button
type="button"
class="menu-item"
onclick={() => {
open = false;
onadd();
}}><Icon name="addAccount" />Add account</button
>
<hr />
<button type="button" class="menu-item" disabled={switching} onclick={() => void signOut()}><Icon name="signOut" />Sign out</button>
<hr />
<button
type="button"
class="menu-item danger"
disabled={switching}
onclick={() => {
open = false;
ondelete();
}}><Icon name="deleteData" />Delete your HUD data</button
>
</div>
</details>
<style>
.face {
display: inline-grid;
place-items: center;
width: var(--control-sm);
height: var(--control-sm);
border-radius: var(--radius-full);
cursor: pointer;
}
.face:hover,
.account[open] .face {
background: var(--hover);
}
/* Who is signed in, marked, then the others to switch to. */
.current {
cursor: default;
}
.current:hover {
background: none;
}
.who {
flex: 1;
min-width: 0;
}
.problem {
padding: var(--space-1) var(--space-3);
}
/* Deleting their data: the danger's colour, its icon too. */
.danger,
.danger :global(.i) {
color: var(--danger);
}
</style>