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 Icon from '../atoms/Icon.svelte';
import Person from '../molecules/Person.svelte';
import { memberText, type Canvas, type Role } from '../model';
/**
* Who a canvas is shared with, and who of them is on it now. Its owner
* invites someone by handle as an editor or a viewer, changes a
* member's role, and removes them; an invitation waits, said, until it
* is accepted. Everyone else sees the members and can leave.
*/
type Members = {
invite: (actor: string, role: Exclude<Role, 'owner'>) => Promise<void>;
role: (did: string, role: Exclude<Role, 'owner'>) => Promise<void>;
remove: (did: string) => Promise<void>;
leave: () => Promise<void>;
};
let { me, canvas, here, members, onclose }: { me: string; canvas: Canvas; here: Set<string>; members: Members; onclose: () => void } = $props();
let dialog: HTMLDialogElement | undefined = $state();
let error = $state<string | null>(null);
let busy = $state(false);
let actor = $state('');
let role = $state<Exclude<Role, 'owner'>>('editor');
const owns = $derived(canvas.role === 'owner');
/** The owner first, then the others as the server lists them. */
const listed = $derived([...canvas.members].sort((a, b) => Number(b.role === 'owner') - Number(a.role === 'owner')));
async function run(change: () => Promise<void>) {
busy = true;
error = null;
try {
await change();
return true;
} catch (failed) {
error = failed instanceof Error ? failed.message : String(failed);
return false;
} finally {
busy = false;
}
}
async function invite(event: SubmitEvent) {
event.preventDefault();
const who = actor.trim().replace(/^@/, '');
if (!who) return;
if (await run(() => members.invite(who, role))) actor = '';
}
async function leave() {
if (!window.confirm(`Leave “${canvas.name}”? You’ll need a new invitation to come back.`)) return;
if (await run(members.leave)) dialog?.close();
}
const roleWords: Record<Role, string> = { owner: 'Owner', editor: 'Can edit', viewer: 'Can view' };
/** What is said under a member: their role, unless their select beside it says it, and whether they have joined, or are here now. */
function about(member: Canvas['members'][number]) {
const said = [owns && member.role !== 'owner' ? null : roleWords[member.role], member.pending ? 'invited, not yet joined' : here.has(member.did) ? 'here now' : null].filter(Boolean).join(' · ');
return said ? `${said[0].toUpperCase()}${said.slice(1)}` : null;
}
onMount(() => dialog?.showModal());
</script>
<dialog bind:this={dialog} class="dialog share" aria-labelledby="share-title" {onclose}>
<h2 id="share-title">{owns ? 'Share' : 'Members of'} “{canvas.name}”</h2>
<button type="button" class="icon-button close" aria-label="Close" onclick={() => dialog?.close()}><Icon name="close" /></button>
<p class="mute">{owns ? 'You own this canvas.' : `Owned by ${memberText(canvas, canvas.owner)}; you can ${canvas.role === 'editor' ? 'edit' : 'view'} it.`} Members open it as a tab and see who is here.</p>
{#if owns}
<form class="invite" onsubmit={invite}>
<input class="input" type="text" bind:value={actor} placeholder="Handle, as alice.bsky.social" aria-label="Handle to invite" autocomplete="off" spellcheck="false" required />
<select class="input" bind:value={role} aria-label="Role">
<option value="editor">Can edit</option>
<option value="viewer">Can view</option>
</select>
<button type="submit" class="btn primary" disabled={busy}>Invite</button>
</form>
{/if}
{#if error}<p class="problem" role="alert">{error}</p>{/if}
<ul class="members">
{#each listed as member (member.did)}
<li>
<Person did={member.did} handle={member.handle ?? undefined} you={member.did === me} here={here.has(member.did)} about={about(member)} />
{#if owns && member.role !== 'owner'}
<select
class="input"
value={member.role}
aria-label="Role of {memberText(canvas, member.did)}"
disabled={busy}
onchange={(event) => void run(() => members.role(member.did, event.currentTarget.value as Exclude<Role, 'owner'>))}
>
<option value="editor">Can edit</option>
<option value="viewer">Can view</option>
</select>
<button type="button" class="icon-button" title="Remove" aria-label="Remove {memberText(canvas, member.did)}" disabled={busy} onclick={() => void run(() => members.remove(member.did))}>
<Icon name="close" />
</button>
{/if}
</li>
{/each}
</ul>
<div class="actions">
{#if !owns}
<button type="button" class="btn danger" disabled={busy} onclick={() => void leave()}>Leave canvas</button>
{/if}
<span class="grow"></span>
<button type="button" class="btn" onclick={() => dialog?.close()}>Done</button>
</div>
</dialog>
<style>
.share {
position: fixed;
}
.share > p {
margin-top: var(--space-1);
font-size: var(--text-sm);
}
.invite {
display: flex;
gap: var(--space-2);
margin-top: var(--space-4);
}
.invite input {
flex: 1;
}
.problem {
margin-top: var(--space-2);
}
.members {
display: flex;
flex-direction: column;
margin: var(--space-4) 0 0;
padding: 0;
list-style: none;
}
.members li {
display: flex;
align-items: center;
gap: var(--space-2);
padding: var(--space-2) 0;
border-top: var(--border);
}
.members li:first-child {
border-top: 0;
}
.grow {
flex: 1;
}
.actions {
margin-top: var(--space-4);
}
/* On a phone, a sheet: the handle has a row of its own, and the
buttons read at the size the fields must be (16px, or iOS zooms in),
so a row's controls are of one scale. */
@media (max-width: 640px) {
.invite {
flex-wrap: wrap;
}
.invite input {
flex-basis: 100%;
}
.invite select {
flex: 1;
}
.share .btn {
font-size: var(--text-field);
}
}
</style>