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

chadtmiller.com/hud

A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts

0
0

A feed in the web shell pages as it is scrolled

Merged chadtmiller.com asked to merge into main from chadtmiller.com/hud:web/auto-page
.changeset/a_feed_pages_as_it_is_scrolled.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: patch
---
# A feed in the web shell pages as it is scrolled
A screen with a `next` loads its next page itself as its foot comes within a screen of view, as HUDKit's and the Android kit's lists do: one page at a time, on the screen in front alone, stopping at an error until Try again, and never where the browser asks to save data. Its Load more button stays, for the keyboard, screen readers and pages drawn with no script. `LoadMore` takes `auto` for a host to page so.
docs/views.md+12−0
@@ -1503,6 +1503,18 @@ out, forms aren't offered: a `Compose` with a count shows as that count. An `Act
or deletes a record (a ♡, a Follow) goes to sign in when it's pressed, as Grain's web asks, rather
than failing.
A screen whose tree has a `next` pages as you scroll, as HUDKit's and the Android kit's lists do.
Its foot is a Load more button, and once the page has hydrated, the shell loads the next page itself
as that foot comes within a screen of the screen's own scroll (an `IntersectionObserver`, `auto` on
the renderer's `LoadMore`). Each page appends to the tree's page list (a `List`, `Covers`,
`Gallery` or `Player`) below what's in view, so the scroll doesn't move, and the list lets go of
items far from view as it grows ([Memory](memory.md)). It loads one page at a time, and only on the
screen in front (not one under another, under a pager or in a tab not on show, nor while its call
is made again). A page that fails shows its error with Try again and loads nothing more until it's
pressed. Where the browser asks to save data (`navigator.connection.saveData`), the button alone
pages. The button stays in every case, for the keyboard, screen readers and a page drawn with no
script. A `Messages` conversation loads its earlier messages by its own button at its top.
A screen whose own `Tabs` strip selects it and offers a destination's root too is that root's
swap, as choosing it in the strip makes it. Grain's Following, Recent or a pinned feed, each a
choice of Home's strip, are like this. Its URL is drawn as that destination's root level, with its
web/renderer/src/view/window.ts+1−1
@@ -48,7 +48,7 @@ const key = (item: unknown) => (typeof item === 'object' && item !== null ? item
const indexOf = (element: Element) => Number((element as HTMLElement).dataset.index);
/** The nearest ancestor of `element` that scrolls up and down, or null for the page. */
function scroller(element: Element): Element | null {
export function scroller(element: Element): Element | null {
for (let at = element.parentElement; at; at = at.parentElement) {
const { overflowY } = getComputedStyle(at);
if (overflowY === 'auto' || overflowY === 'scroll') return at;
web/renderer/src/LoadMore.svelte+32−2
@@ -1,10 +1,40 @@
<script lang="ts">
// The foot of a list with more after it: a button that asks for the next
// page, which says so while it comes, and what went wrong if it failed.
let { onload, loading, error }: { onload: () => void; loading: boolean; error: string | null } = $props();
// With `auto`, it asks itself as it comes within a screen of the view of
// its scroller, as a native list pages on scroll; the button stays, for a
// keyboard, a screen reader, a page drawn with no script and an error,
// which stops it until pressed. It watches only in the browser, once
// drawn (the page a server drew is the page hydrated), never while a page
// comes, nor where the browser asks to save data, and each page it is
// drawn after watches afresh, so a page too short to fill the view brings
// the next.
import { scroller } from './view/window';
let { onload, loading, error, auto = false }: { onload: () => void; loading: boolean; error: string | null; auto?: boolean } = $props();
let foot: HTMLElement | undefined = $state();
const saving = () => (navigator as Navigator & { connection?: { saveData?: boolean } }).connection?.saveData === true;
$effect(() => {
const at = foot;
if (!at || !auto || loading || error || saving()) return;
// A screen's height past the scroller's foot, the margin a percentage of the scroller's own.
const watch = new IntersectionObserver(
(seen) => {
if (!seen.some((each) => each.isIntersecting) || at.closest('[inert]')) return;
watch.disconnect();
onload();
},
{ root: scroller(at), rootMargin: '0px 0px 100% 0px' }
);
watch.observe(at);
return () => watch.disconnect();
});
</script>
<div class="more">
<div class="more" bind:this={foot}>
{#if error}
<p class="error" role="alert">{error}</p>
{/if}
web/shell/src/Stack.svelte+4−1
@@ -240,6 +240,9 @@
/** Whether a level draws what its own call answered (not, while a tab's call is on its way, the call before's). */
const current = (level: Level) => level.entry?.call != null && (level.entry.call === level.call || same(level.entry.call, level.call));
/** Whether a level is in front and settled, so its list pages as it is scrolled to its foot: the sheet's while one is open, else the stack's top with no pager over it, in the tab on show, and not drawn as it was while its call is made again (refreshing, or swapped for another). */
const inFront = (level: Level) => active && !level.refreshing && (sheet ? sheet.id === level.id : !pager && top?.id === level.id);
/** Make a level's call (opening its form the first time, where it does), and draw what it answers in it, while it is still on the stack (or the sheet) drawing that call; past `SKELETON_DELAY`, it is `slow`, unless it draws its last tree meanwhile. */
async function load(level: Level) {
const made = level.call;
@@ -681,7 +684,7 @@
{@const paged = nextPage(entry)}
{@render treeOf(level, entry, level.entry.view.ui, 'apart')}
{#if paged && !ownsPaging(entry) && current(level)}
<LoadMore onload={() => loadMore(level)} loading={level.more.loading} error={level.more.error} />
<LoadMore onload={() => loadMore(level)} loading={level.more.loading} error={level.more.error} auto={inFront(level)} />
{/if}
{:else}
<ErrorMessage message={level.entry.view.message} onretry={() => void load(level)} />
web/shell/test/ssr.mjs+100−1
@@ -34,7 +34,10 @@
// pushed from a link and gone back from (and forward to, and back), where
// focus does not move into it and back to the link, where the screen under
// it is not inert or is aria-hidden, or where its pictures loading after it
// is let go warn (Svelte's derived_inert). Both builds go to a
// is let go warn (Svelte's derived_inert); and a long feed, its foot shown
// to a fake IntersectionObserver: where it does not load its next page
// once, loads one under a screen over it (inert), or loads again after a
// page failed until Try again is pressed. Both builds go to a
// directory of their own in the system's temporary directory, taken away
// after. In the same world, a strip of stories opening a pager: it fails
// where another's story tapped opens one's own page's form (read ahead
@@ -616,10 +619,27 @@ try {
{ c: 'Link', p: { label: 'My profile', open: { call: { name: 'describe_app', args: { domain: 'app.test', actor: 'did:plc:me' } } } } },
{ c: 'Link', p: { label: 'Their post', open: { call: THEIR_POST } } },
{ c: 'Link', p: { label: 'Their gallery', open: { call: THEIR_GALLERY } } },
{ c: 'Link', p: { label: 'A long feed', open: { call: PAGED } } },
STRIP
]
}
});
// A feed of three pages, five items each, its foot a "Load more" that pages as it comes into view; a link on it opens a screen over it.
const PAGED = query('test.paged');
/** Whether the feed's pages fail, as a server down does. */
let pagesFail = false;
const pagedOf = (cursor) => ({
v: 1,
trusted: true,
root: {
c: 'Stack',
k: [
{ c: 'Link', p: { label: 'Their post', open: { call: THEIR_POST } } },
{ c: 'List', p: { page: true }, items: Array.from({ length: 5 }, (_, i) => ({ k: [{ c: 'Text', p: { runs: [{ text: `Item ${cursor}.${i}` }], style: 'body' } }] })) }
]
},
...(cursor < 2 ? { next: query('test.paged', { cursor: cursor + 1 }) } : {})
});
const calls = [];
const answer = ({ name, args }) => {
if (name === 'apply_writes') return { structuredContent: { results: [{ uri: POST, cid: 'c' }] } };
@@ -627,6 +647,11 @@ try {
const author = args.params.post.startsWith('at://did:plc:them/') ? { author: { did: 'did:plc:them', handle: 'them.test' } } : {};
return { structuredContent: author, _meta: { ui: { v: 1, trusted: true, root: { c: 'Text', p: { runs: [{ text: `The post ${args.params.post}` }], style: 'body' } } } } };
}
if (args.method === 'test.paged') {
const cursor = args.params.cursor ?? 0;
if (cursor > 0 && pagesFail) return { isError: true, content: [{ type: 'text', text: 'The feed is down.' }] };
return { _meta: { ui: pagedOf(cursor) } };
}
if (args.method === 'test.getGallery')
return { _meta: { ui: { v: 1, trusted: true, root: { c: 'Stack', k: [{ c: 'Bar', p: { title: 'Their gallery' } }, { c: 'Gallery', p: { style: 'stack' }, items: [picture(1), picture(2)] }] } } } };
if (args.method === 'test.story.get') return { _meta: { ui: storiesOf(args), viewer: { did: 'did:plc:me', handle: 'me.test' } } };
@@ -726,6 +751,80 @@ try {
for (const said of warned) problems.push(`a screen pushed and gone back from: ${said}`);
say('a screen pushed and gone back from: focus moved into it and back, the screen under was inert, its pictures loading late warned nothing');
// A long feed pages itself as its foot comes within a screen of view, once a page, and never while a screen is over it or after a
// page failed, until Try again is pressed. The browser's IntersectionObserver a fake here, its foot shown when the test says.
{
const watching = new Set();
const Observer = globalThis.IntersectionObserver;
globalThis.IntersectionObserver = class {
constructor(seen, options) {
Object.assign(this, { seen, options, watched: new Set() });
}
observe(element) {
this.watched.add(element);
watching.add(this);
}
unobserve(element) {
this.watched.delete(element);
}
disconnect() {
this.watched.clear();
watching.delete(this);
}
takeRecords() {
return [];
}
};
/** The feed's foot, scrolled within a screen of view: each observer watching it told so. */
const footShown = () => {
for (const observer of [...watching])
for (const element of [...observer.watched]) if (element.classList.contains('more')) observer.seen([{ target: element, isIntersecting: true }], observer);
};
const pages = (cursor) => calls.filter((call) => call.args.method === 'test.paged' && (call.args.params.cursor ?? 0) === cursor).length;
const foot = () => target.querySelector('.stack:not([hidden]) > section.level:last-child .more');
const drawn = (text) => target.querySelector('.stack:not([hidden]) > section.level:last-child')?.textContent.includes(text);
try {
[...target.querySelectorAll('.stack:not([hidden]) :is(a, button)')].find((each) => each.textContent.includes('A long feed')).click();
await until(() => levels() === 2 && drawn('Item 0.4') && foot(), 'the long feed opened');
await settle();
if (pages(1)) problems.push('the long feed asked for its second page before its foot was in view');
const watcher = [...watching].find((observer) => [...observer.watched].includes(foot()));
if (!watcher || !/100%/.test(watcher.options.rootMargin)) problems.push(`the long feed's foot is watched ${watcher ? `with the margin ${watcher.options.rootMargin}` : 'by nothing'}, not a screen ahead`);
footShown();
footShown();
await until(() => drawn('Item 1.4'), 'its second page, as its foot came into view');
await settle();
if (pages(1) !== 1) problems.push(`its foot shown twice, the long feed asked for its second page ${pages(1)} times, not once`);
[...target.querySelectorAll('.stack:not([hidden]) > section.level:last-child a')].find((each) => each.textContent.includes('Their post')).click();
await until(() => levels() === 3, 'their post opened over the long feed');
await settle();
footShown();
await settle();
if (pages(2)) problems.push('under their post, inert, the long feed asked for its third page');
history.go(-1);
await until(() => levels() === 2 && !target.querySelector('.stack:not([hidden]) > section.level[aria-busy="true"]'), 'back at the long feed');
await settle();
pagesFail = true;
footShown();
await until(() => foot()?.querySelector('[role="alert"]'), 'its third page failed');
await settle();
footShown();
await settle();
const button = foot().querySelector('button');
if (pages(2) !== 1 || !foot().textContent.includes('The feed is down.') || button.textContent.trim() !== 'Try again') problems.push(`a page failed, the long feed asked for it ${pages(2)} times and drew ${foot().textContent.trim()}`);
pagesFail = false;
button.click();
await until(() => drawn('Item 2.4') && !foot(), 'its third page, Try again pressed, and no foot after the last');
history.go(-1);
await until(() => levels() === 1, 'back from the long feed, Home');
} finally {
globalThis.IntersectionObserver = Observer;
}
say('a long feed paged as its foot came into view, once a page, never under a screen or after a page failed until Try again');
}
// Another's story tapped: its pager has no page of one's own, which opens at a form (Your story's `compose`), a page only of the pager it opens itself.
const pager = () => target.querySelector('.pager');
const tap = (words) => [...target.querySelectorAll('.stack:not([hidden]) li.item')].find((el) => el.textContent.includes(words)).querySelector('.open').click();