chadtmiller.com/hud
A remote MCP server that shows atproto records as interactive UI inside MCP Apps hosts
place.hud.hudkit 0.3.1 Latest 5 packages
0
0
<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.
// 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" bind:this={foot}>
{#if error}
<p class="error" role="alert">{error}</p>
{/if}
<button type="button" onclick={onload} disabled={loading} aria-busy={loading}>
{loading ? 'Loading…' : error ? 'Try again' : 'Load more'}
</button>
</div>
<style>
p {
margin: 0;
}
.more {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--hud-space-2);
padding: var(--hud-space-4) 0 var(--hud-space-2);
}
.error {
color: var(--color-text-danger);
font-size: var(--font-text-sm-size);
text-align: center;
overflow-wrap: anywhere;
}
button {
min-width: 9rem;
padding: var(--hud-space-2) var(--hud-space-4);
border: var(--border-width-regular) solid var(--color-border-primary);
border-radius: var(--border-radius-md);
background: var(--color-background-secondary);
color: var(--color-text-primary);
font: inherit;
font-size: var(--font-text-sm-size);
font-weight: var(--font-weight-medium);
cursor: pointer;
}
button:hover:not(:disabled) {
background: var(--color-background-tertiary);
}
button:disabled {
color: var(--color-text-secondary);
cursor: progress;
}
</style>