~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

The console's acts are sent in place, keeping the reader where they are

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:ui/forms-in-place
.claude/skills/ui/SKILL.md+9−0
@@ -173,6 +173,15 @@ controls.
editing what is already there field by field (a group's profile, who
sees it) is a form in place, and finding (a search box) is never a
dialog. A handle is typed into `HandleInput`, wherever it is asked for.
- *In place.* An act on the page you are on keeps you where you are:
its form is sent with `use:enhance`, by `inPlace` from
`#lib/forms.ts`, and `FormDialog` and `ConfirmDialog` send theirs by
`inDialog`. Done, the page is drawn again where it was, and a dialog
closes. Refused, a dialog stays open with what was typed and says why
inside it; elsewhere the page's notice says why, scrolled to. Never
a plain post that reloads the page at its top. Only a form that goes
somewhere else (signing out, starting a group, approving an app) may
post plainly.
- *Confirming.* An act that cannot be undone (leaving, removing
someone, deleting a rule or role, removing a key, revoking,
disconnecting) opens a `ConfirmDialog`: its title the question
harness/e2e/flows.spec.mjs+16−4
@@ -193,9 +193,10 @@ test('inviting someone from the dialog', async () => {
await expect(dialog.getByText("They'll see it the next time they sign in, here or in any app that shows invites.")).toBeVisible()
await dialog.getByRole('combobox', { name: 'Their handle' }).fill('nobody.test')
await dialog.getByRole('button', { name: 'Send invite' }).click()
await expect(page.getByText("We can't find nobody.test.")).toBeVisible()
// Refused, it stays open, saying why, with what was typed.
await expect(dialog.getByText("We can't find nobody.test.")).toBeVisible()
await expect(dialog.getByRole('combobox', { name: 'Their handle' })).toHaveValue('nobody.test')
// Cancelled, it sends nothing.
await invite.click()
await dialog.getByRole('button', { name: 'Cancel' }).click()
await expect(dialog).toBeHidden()
await expect(page.locator('.invites')).toHaveCount(0)
@@ -272,8 +273,13 @@ test('giving roles, and putting someone out', async () => {
await row().getByRole('button', { name: "Change bob.test's roles" }).click()
const roles = page.getByRole('dialog', { name: 'Change roles' }).filter({ visible: true })
await expect(roles.getByRole('checkbox', { name: 'member' })).toBeChecked()
// Saved in place: the dialog closes, and the page stays where it was.
const at = await page.evaluate(() => scrollY)
expect(at).toBeGreaterThan(0)
await roles.getByRole('button', { name: 'Save' }).click()
await expect(roles).toBeHidden()
await expect(row()).toContainText('member')
expect(await page.evaluate(() => scrollY)).toBe(at)
// Removed, once she is sure.
await row().getByRole('button', { name: 'Remove bob.test' }).click()
const sure = page.getByRole('dialog', { name: 'Remove this member?' }).filter({ visible: true })
@@ -406,7 +412,11 @@ test("giving a group a picture, and taking it away", async () => {
await page.goto(url('/g/hikers.groups.test/settings'))
await page.getByRole('button', { name: 'Add the avatar' }).click()
await page.getByLabel('Avatar', { exact: true }).setInputFiles({ name: 'face.png', mimeType: 'image/png', buffer: PIXEL })
await page.getByRole('dialog', { name: 'Add the avatar' }).getByRole('button', { name: 'Add the avatar' }).click()
const adding = page.getByRole('dialog', { name: 'Add the avatar' })
await adding.getByRole('button', { name: 'Add the avatar' }).click()
// Sent in place: done, the dialog closes and the page offers to remove it.
await expect(adding).toBeHidden()
await expect(page.getByRole('button', { name: 'Remove the avatar' })).toBeVisible()
// Drawn on its page, from the host, as the image it is: one pixel wide.
await page.goto(url('/g/hikers.groups.test'))
const avatar = page.locator('.identity img.av')
@@ -414,6 +424,7 @@ test("giving a group a picture, and taking it away", async () => {
await expect.poll(() => avatar.evaluate((img) => img.naturalWidth)).toBe(1)
await page.goto(url('/g/hikers.groups.test/settings'))
await page.getByRole('button', { name: 'Remove the avatar' }).click()
await expect(page.getByRole('button', { name: 'Add the avatar' })).toBeVisible()
await page.goto(url('/g/hikers.groups.test'))
await expect(page.locator('.identity img.av')).toHaveCount(0)
})
@@ -551,7 +562,8 @@ test('moderating: a label, and the queue', async () => {
await page.getByRole('navigation', { name: 'The queue' }).getByRole('link', { name: 'Escalated' }).click()
await expect(page.locator('.subject', { hasText: who.bob.did }).locator('.events')).toContainText('Escalated: Asked him to stop')
await page.locator('.subject', { hasText: who.bob.did }).getByRole('button', { name: 'Resolve' }).click()
await page.getByRole('dialog', { name: 'Resolve or escalate' }).filter({ visible: true }).getByRole('button', { name: 'Resolve' }).click()
await resolving.getByRole('button', { name: 'Resolve' }).click()
await expect(resolving).toHaveCount(0)
await page.goto(url('/g/hikers.groups.test/moderation?status=resolved'))
await expect(page.locator('.subject', { hasText: who.bob.did }).locator('.events')).toContainText('Resolved')
})
web/src/lib/molecules/ConfirmDialog.svelte+6−2
@@ -1,6 +1,8 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import { enhance } from '$app/forms';
import Dialog from '#lib/molecules/Dialog.svelte';
import { inDialog } from '#lib/forms.ts';
/**
* Asking to be sure of what cannot be undone, opened by a button whose
* `popovertarget` is `id`: `children`, what will happen, in a sentence;
@@ -14,11 +16,13 @@
fields = {},
children
}: { id: string; title: string; action: string; confirm: string; fields?: Record<string, string>; children: Snippet } = $props();
let failed = $state<string | null>(null);
</script>
<Dialog {id} {title}>
<Dialog {id} {title} onclose={() => (failed = null)}>
<p class="mute">{@render children()}</p>
<form method="post" {action} class="actions">
{#if failed}<p class="danger">{failed}</p>{/if}
<form method="post" {action} class="actions" use:enhance={inDialog(id, (why) => (failed = why))}>
{#each Object.entries(fields) as [name, value] (name)}<input type="hidden" {name} {value} />{/each}
<button class="quiet" type="button" popovertarget={id} popovertargetaction="hide">Cancel</button>
<button class="danger" type="submit">{confirm}</button>
web/src/lib/molecules/Dialog.svelte+9−3
@@ -1,15 +1,21 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import { empty } from '#lib/forms.ts';
/**
* A dialog over the dimmed page, opened by a button whose
* `popovertarget` is its `id`: its `title`, a
* button to close it, then `children`. Light dismiss closes it too, as a
* popover does, with no script. `wide` for one with much in it.
* popover does, with no script. `wide` for one with much in it. Closed,
* however it closes, what was typed into it goes, and `onclose` is told.
*/
let { id, title, wide = false, children }: { id: string; title: string; wide?: boolean; children: Snippet } = $props();
let { id, title, wide = false, onclose, children }: { id: string; title: string; wide?: boolean; onclose?: () => void; children: Snippet } = $props();
// Opened, the first thing to fill in is the one being typed into.
function toggled(e: ToggleEvent) {
if (e.newState !== 'open') return;
if (e.newState !== 'open') {
(e.currentTarget as HTMLElement).querySelectorAll('form').forEach(empty);
onclose?.();
return;
}
const into = (e.currentTarget as HTMLElement).querySelector<HTMLInputElement>('input:not([type=hidden]),textarea');
into?.focus();
}
web/src/lib/molecules/FormDialog.svelte+8−3
@@ -1,11 +1,14 @@
<script lang="ts">
import type { Snippet } from 'svelte';
import { enhance } from '$app/forms';
import Dialog from '#lib/molecules/Dialog.svelte';
import { inDialog } from '#lib/forms.ts';
/**
* An act that asks for input, in a dialog opened by a button whose
* `popovertarget` is `id`: `intro`, a line on what it does; the form,
* sent to `action`, its fields `children`; then Cancel, and `submit`,
* the act. `wide` for a form with much in it.
* the act. `wide` for a form with much in it. Sent in place: done, it
* closes; refused, it stays open, saying why.
*/
let {
id,
@@ -17,12 +20,14 @@
wide = false,
children
}: { id: string; title: string; action: string; submit: string; intro?: Snippet; multipart?: boolean; wide?: boolean; children: Snippet } = $props();
let failed = $state<string | null>(null);
</script>
<Dialog {id} {title} {wide}>
<Dialog {id} {title} onclose={() => (failed = null)} {wide}>
{#if intro}<p class="mute">{@render intro()}</p>{/if}
<form class="stack" method="post" {action} enctype={multipart ? 'multipart/form-data' : undefined}>
<form class="stack" method="post" {action} enctype={multipart ? 'multipart/form-data' : undefined} use:enhance={inDialog(id, (why) => (failed = why))}>
{@render children()}
{#if failed}<p class="danger">{failed}</p>{/if}
<div class="actions">
<button class="quiet" type="button" popovertarget={id} popovertargetaction="hide">Cancel</button>
<button type="submit">{submit}</button>
web/src/lib/organisms/Invitations.svelte+4−2
@@ -1,4 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { inPlace } from '#lib/forms.ts';
import Empty from '#lib/molecules/Empty.svelte';
import GroupRow from '#lib/molecules/GroupRow.svelte';
import { image } from '#lib/images.ts';
@@ -16,8 +18,8 @@
<li>
<GroupRow name={i.group.displayName ?? i.group.handle} handle={i.group.handle} avatar={image(i.group.did, i.group.avatar)} note={i.message} />
<span class="row-actions">
<form method="post" action="?/decline"><input type="hidden" name="group" value={i.group.did} /><button class="quiet small" type="submit">Decline</button></form>
<form method="post" action="?/accept">
<form method="post" action="?/decline" use:enhance={inPlace}><input type="hidden" name="group" value={i.group.did} /><button class="quiet small" type="submit">Decline</button></form>
<form method="post" action="?/accept" use:enhance={inPlace}>
<input type="hidden" name="group" value={i.group.did} /><button class="small" type="submit" aria-label={`Join ${i.group.displayName ?? i.group.handle}`}>Join</button>
</form>
</span>
web/src/lib/organisms/Invites.svelte+3−1
@@ -1,4 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { inPlace } from '#lib/forms.ts';
import Empty from '#lib/molecules/Empty.svelte';
import MemberRow from '#lib/molecules/MemberRow.svelte';
/** The invites the group has sent that are still waiting, each to cancel. */
@@ -10,7 +12,7 @@
{#each invites as i (i.uri)}
<li>
<MemberRow actor={i.actor ?? { did: i.invitee }}>
<form method="post" action="?/uninvite"><input type="hidden" name="uri" value={i.uri} /><button class="quiet small" type="submit">Cancel invite</button></form>
<form method="post" action="?/uninvite" use:enhance={inPlace}><input type="hidden" name="uri" value={i.uri} /><button class="quiet small" type="submit">Cancel invite</button></form>
</MemberRow>
</li>
{/each}
web/src/lib/organisms/JoinPanel.svelte+7−5
@@ -1,4 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { inPlace } from '#lib/forms.ts';
/**
* How the person looking gets into the group, as its join policy says
* and as they stand: in at once by an invite, whatever the policy,
@@ -25,24 +27,24 @@
<h2>You're invited</h2>
<p class="mute">Someone in {name} invited you to join.</p>
<div class="choices">
<form method="post" action="?/decline"><button class="quiet" type="submit">Decline</button></form>
<form method="post" action="?/join"><button type="submit">Join</button></form>
<form method="post" action="?/decline" use:enhance={inPlace}><button class="quiet" type="submit">Decline</button></form>
<form method="post" action="?/join" use:enhance={inPlace}><button type="submit">Join</button></form>
</div>
{:else if asked}
<h2>Your request is waiting</h2>
<p class="mute">You'll be a member once someone approves it.</p>
<form method="post" action="?/cancel"><button class="quiet" type="submit">Cancel request</button></form>
<form method="post" action="?/cancel" use:enhance={inPlace}><button class="quiet" type="submit">Cancel request</button></form>
{:else if policy === 'open'}
<h2>Join {name}</h2>
<p class="mute">Anyone can join.</p>
<form method="post" action="?/join"><button type="submit">Join</button></form>
<form method="post" action="?/join" use:enhance={inPlace}><button type="submit">Join</button></form>
{:else if policy === 'invite'}
<h2>Joining is by invite</h2>
<p class="mute">Ask someone in {name} to invite you. Your invite will show up here.</p>
{:else}
<h2>Ask to join</h2>
<p class="mute">Someone in {name} reviews each request.</p>
<form class="stack" method="post" action="?/join">
<form class="stack" method="post" action="?/join" use:enhance={inPlace}>
<label class="field">A note to them, if you like <textarea name="message" rows="3" maxlength="2000"></textarea></label>
<button type="submit">Send request</button>
</form>
web/src/lib/organisms/JoinRequests.svelte+4−2
@@ -1,4 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { inPlace } from '#lib/forms.ts';
import Empty from '#lib/molecules/Empty.svelte';
import MemberRow from '#lib/molecules/MemberRow.svelte';
/** The requests waiting to join, for a member whose roles admit people: each with its note, approved or declined. */
@@ -10,8 +12,8 @@
{#each requests as r (r.member)}
<li>
<MemberRow actor={r.actor ?? { did: r.member }} note={r.message}>
<form method="post" action="?/deny"><input type="hidden" name="did" value={r.member} /><button class="quiet small" type="submit">Decline</button></form>
<form method="post" action="?/admit"><input type="hidden" name="did" value={r.member} /><button class="small" type="submit">Approve</button></form>
<form method="post" action="?/deny" use:enhance={inPlace}><input type="hidden" name="did" value={r.member} /><button class="quiet small" type="submit">Decline</button></form>
<form method="post" action="?/admit" use:enhance={inPlace}><input type="hidden" name="did" value={r.member} /><button class="small" type="submit">Approve</button></form>
</MemberRow>
</li>
{/each}
web/src/lib/organisms/LinksEditor.svelte+3−1
@@ -1,4 +1,6 @@
<script lang="ts">
import { enhance } from '$app/forms';
import { inPlace } from '#lib/forms.ts';
import Empty from '#lib/molecules/Empty.svelte';
import FormDialog from '#lib/molecules/FormDialog.svelte';
/**
@@ -15,7 +17,7 @@
{#each links as l, i (i)}
<li>
<span class="row-main"><strong>{l.title ?? shown(l.url)}</strong><span class="what">{l.url}</span></span>
<form class="row-actions" method="post" action="?/unlink">
<form class="row-actions" method="post" action="?/unlink" use:enhance={inPlace}>
<input type="hidden" name="index" value={i} />
<button class="quiet small" type="submit" aria-label={`Remove ${l.title ?? shown(l.url)}`}>Remove</button>
</form>
web/src/lib/organisms/ModerationQueue.svelte+7−2
web/src/lib/organisms/ProfileForm.svelte+3−1
web/src/lib/organisms/ProfilePictures.svelte+3−1
web/src/lib/organisms/Visibility.svelte+3−1
web/src/lib/forms.tsnew+72−0
AGENTS.md+2−0