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 { ATMO, atmoLogo } from '../atmo';
import Dialog from '../molecules/Dialog.svelte';
import HandleInput from '../molecules/HandleInput.svelte';
import { signIn, signUp, XrpcError } from '../xrpc';
/**
* Signing in with an Atmosphere account: the handle, then the account's
* own server to approve it on, which sends the browser back to the
* workspace. Picking an account the field offers signs in as it at once.
* Signed in already, it adds another account beside this one, to switch
* between. As knotless's.
*/
let { onclose }: { onclose: () => void } = $props();
let handle = $state('');
let problem = $state('');
// What is under way: signing in, or opening the sign-up PDS's page.
let busy = $state<'' | 'login' | 'create'>('');
// The handle has the focus, once the dialog is open (its first button had it).
onMount(() => document.getElementById('sign-in-handle')?.focus());
function submit(event: SubmitEvent) {
event.preventDefault();
void go();
}
async function go() {
if (busy || !handle.trim()) return;
await away('login', () => signIn(handle.trim()), 'Signing in did not work. Try again.');
}
async function create() {
if (busy) return;
await away('create', signUp, 'Creating an account did not work. Try again.');
}
async function away(what: 'login' | 'create', url: () => Promise<string>, fallback: string) {
busy = what;
problem = '';
try {
location.assign(await url());
} catch (error) {
problem = error instanceof XrpcError ? error.message : fallback;
busy = '';
}
}
</script>
<Dialog id="sign-in" title="Sign in with your Atmosphere account" class="sign-in" held={!!busy} {onclose}>
<!-- Apps on the Atmosphere, any of whose accounts signs in here: a row of their logos running past, twice over so it wraps without a seam. -->
<div class="apps" aria-hidden="true">
<div class="run">
{#each [...ATMO, ...ATMO] as app, i (i)}
<img src={atmoLogo(app)} alt="" width="40" height="40" loading="lazy" decoding="async" />
{/each}
</div>
</div>
<p class="what"><a href="https://atmosphereaccount.com/" target="_blank" rel="noopener noreferrer">What is an Atmosphere account?</a></p>
<form onsubmit={submit}>
<label for="sign-in-handle">Handle</label>
<HandleInput id="sign-in-handle" bind:value={handle} onpick={() => void go()} />
{#if problem}<p class="problem" role="alert">{problem}</p>{/if}
<p class="agree">By signing in you agree to the <a href="/terms">terms</a>, <a href="/privacy">privacy policy</a> and <a href="/guidelines">community guidelines</a>.</p>
<div class="actions">
<button type="button" class="btn" disabled={!!busy} onclick={onclose}>Cancel</button>
<button type="submit" class="btn primary" disabled={!!busy} aria-busy={busy === 'login'}>{busy === 'login' ? 'Signing in…' : 'Sign in'}</button>
</div>
</form>
<p class="create">Don't have an account? <button type="button" disabled={!!busy} aria-busy={busy === 'create'} onclick={() => void create()}>{busy === 'create' ? 'Opening…' : 'Create one'}</button></p>
</Dialog>
<style>
/* As narrow as knotless's; the field's list drops down over the dialog's foot, and past it. */
:global(.dialog.sign-in) {
width: min(var(--dialog-narrow), calc(100vw - 2 * var(--space-4)));
overflow: visible;
}
.apps {
overflow: hidden;
margin-top: var(--space-4);
mask-image: linear-gradient(90deg, transparent, var(--fg) var(--space-6), var(--fg) calc(100% - var(--space-6)), transparent);
}
.run {
display: flex;
gap: var(--space-3);
width: max-content;
}
@media (prefers-reduced-motion: no-preference) {
.run {
animation: run var(--apps-run) linear infinite;
}
}
@keyframes run {
to {
transform: translateX(calc(-50% - var(--space-3) / 2));
}
}
img {
flex: none;
width: var(--app-icon);
height: var(--app-icon);
border-radius: var(--radius-lg);
object-fit: cover;
}
.what {
margin-top: var(--space-3);
font-size: var(--text-sm);
text-align: center;
}
.what a {
color: var(--fg);
text-decoration: underline;
text-decoration-color: var(--link-line);
text-underline-offset: var(--underline-offset);
}
.agree a,
.create button {
color: var(--fg);
text-decoration: underline;
text-decoration-color: var(--link-line);
text-underline-offset: var(--underline-offset);
}
.agree,
.create {
color: var(--mute);
font-size: var(--text-sm);
}
.create {
margin-top: var(--space-4);
text-align: center;
}
.create button {
padding: 0;
border: 0;
background: none;
font: inherit;
cursor: pointer;
}
.create button:disabled {
cursor: default;
}
form {
display: flex;
flex-direction: column;
gap: var(--space-2);
margin-top: var(--space-4);
}
label {
font-size: var(--text-sm);
font-weight: var(--weight-medium);
}
</style>