Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(create-prompt,compare): land the prompt builder and comparison page work from this worktree

nirholas556ea247a04e
diff --git a/pages/compare.html b/pages/compare.html
index ef5b46af8..8cde54340 100644
--- a/pages/compare.html
+++ b/pages/compare.html
@@ -21,7 +21,7 @@
<title data-i18n="compare.meta_title">Compare Coins · three.ws</title>
<meta
name="description"
- content="Compare cryptocurrencies side by side — overlay price performance and line up market cap, volume, supply, and all-time-high stats for up to four coins at once."
+ content="Compare cryptocurrencies side by side: overlay price performance and line up market cap, volume, supply, and all-time-high stats for up to four coins at once."
data-i18n-attr="content:compare.meta_description"/>
<meta property="og:type" content="website" />
<meta property="og:site_name" content="three.ws" />
@@ -60,7 +60,7 @@
<link rel="canonical" href="https://three.ws/compare" />
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1" />
<meta property="og:locale" content="en_US" />
- <meta property="og:image:alt" content="Compare Crypto Side by Side — three.ws" />
+ <meta property="og:image:alt" content="Compare Crypto Side by Side - three.ws" />
<script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"Compare Crypto Side by Side","description":"Compare cryptocurrencies head to head - overlay normalized price performance and line up market cap, volume, FDV, supply, and all-time-high stats for up to four coins at once. The selection is saved to the URL so any matchup is shareable.","url":"https://three.ws/compare","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"},"primaryImageOfPage":"https://three.ws/api/page-og?s=crypto&t=Compare+Crypto+Side+by+Side&d=Compare+cryptocurrencies+head+to+head+-+overlay+normalized+price+performance+and+line+up+market+cap%2C+volume%2C+FDV%2C+supply%2C+and+all-time-high+stats+for+up+to+four&p=%2Fcompare"}]}</script>
</head>
diff --git a/pages/concierge.html b/pages/concierge.html
index 5d4bf7d44..72c1347d4 100644
--- a/pages/concierge.html
+++ b/pages/concierge.html
@@ -245,6 +245,17 @@
.cl-links { display: flex; gap: var(--space-md); flex-wrap: wrap; }
.cl-links a { color: var(--accent); text-decoration: none; font-size: var(--text-sm); }
.cl-links a:hover { text-decoration: underline; }
+
+ /* Site-wide focus tokens rather than the UA default ring, so keyboard
+ focus on this page reads the same as every other surface. */
+ .cl-btn:focus-visible,
+ .cl-tab:focus-visible,
+ .cl-copy:focus-visible,
+ .cl-links a:focus-visible,
+ .cl-code pre:focus-visible {
+ outline: var(--focus-ring-width) solid var(--focus-ring-color);
+ outline-offset: var(--focus-ring-offset);
+ }
</style>
<meta property="og:image:alt" content="Concierge: AI Chat Widget — three.ws">
@@ -411,22 +422,59 @@ concierge.ask('What does the Pro plan cost?');</code></pre>
// Install-tab switcher + copy buttons (no framework, matches site style).
const tabs = [...document.querySelectorAll('.cl-tab')];
const panels = [...document.querySelectorAll('.cl-panel')];
+
+ // Roving tabindex: the tablist is ONE tab stop, and Left/Right/Home/End
+ // move between the tabs inside it, per the WAI-ARIA tabs pattern. Without
+ // this the role="tab" markup promises a keyboard behavior the page did
+ // not implement, which is worse for a screen-reader user than plain
+ // buttons would have been.
+ function selectTab(tab, { focus = false } = {}) {
+ for (const t of tabs) {
+ const on = t === tab;
+ t.setAttribute('aria-selected', String(on));
+ t.tabIndex = on ? 0 : -1;
+ }
+ for (const p of panels) p.hidden = p.dataset.panel !== tab.dataset.panel;
+ if (focus) tab.focus();
+ }
+
for (const tab of tabs) {
- tab.addEventListener('click', () => {
- for (const t of tabs) t.setAttribute('aria-selected', String(t === tab));
- for (const p of panels) p.hidden = p.dataset.panel !== tab.dataset.panel;
+ tab.addEventListener('click', () => selectTab(tab));
+ tab.addEventListener('keydown', (e) => {
+ const i = tabs.indexOf(tab);
+ let next = null;
+ if (e.key === 'ArrowRight') next = tabs[(i + 1) % tabs.length];
+ else if (e.key === 'ArrowLeft') next = tabs[(i - 1 + tabs.length) % tabs.length];
+ else if (e.key === 'Home') next = tabs[0];
+ else if (e.key === 'End') next = tabs[tabs.length - 1];
+ if (!next) return;
+ e.preventDefault();
+ selectTab(next, { focus: true });
});
}
+
for (const btn of document.querySelectorAll('[data-copy]')) {
+ const idle = btn.textContent;
btn.addEventListener('click', async () => {
const code = btn.parentElement.querySelector('code')?.textContent || '';
try {
await navigator.clipboard.writeText(code);
btn.textContent = 'copied';
- setTimeout(() => (btn.textContent = 'copy'), 1400);
+ setTimeout(() => (btn.textContent = idle), 1400);
} catch {
+ // Clipboard is blocked (insecure origin, denied permission).
+ // Select the snippet so the visitor can still press Ctrl+C,
+ // instead of only being told to do it by hand.
+ const el = btn.parentElement.querySelector('code');
+ if (el) {
+ const range = document.createRange();
+ range.selectNodeContents(el);
+ const sel = window.getSelection();
+ sel.removeAllRanges();
+ sel.addRange(range);
+ }
btn.textContent = 'select + copy';
- setTimeout(() => (btn.textContent = 'copy'), 1800);
+ setTimeout(() => (btn.textContent = idle), 1800);
}
});
}
diff --git a/pages/create-prompt.html b/pages/create-prompt.html
index ce6f8dd2a..474c4af5c 100644
--- a/pages/create-prompt.html
+++ b/pages/create-prompt.html
@@ -728,7 +728,10 @@
</div>
<div class="done-tags" id="done-tags"></div>
<div class="done-actions">
- <a class="btn-primary" id="open-editor">
+ <!-- href is rewritten to /avatars/<id>/edit the moment a build
+ finishes; the static value keeps it a real, focusable link
+ instead of a bare <a> with no destination. -->
+ <a class="btn-primary" id="open-editor" href="/dashboard">
Open in editor
<svg
width="14"
diff --git a/public/locales/en.json b/public/locales/en.json
index 0156f3055..cfdf5ff0e 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -2711,13 +2711,13 @@
"compare": "Compare",
"compare_coins": "Compare Coins",
"markets": "Markets",
- "meta_description": "Compare cryptocurrencies side by side — overlay price performance and line up market cap, volume, supply, and all-time-high stats for up to four coins at once.",
+ "meta_description": "Compare cryptocurrencies side by side: overlay price performance and line up market cap, volume, supply, and all-time-high stats for up to four coins at once.",
"meta_og_description": "Overlay price performance and line up market cap, volume, supply, and ATH stats for up to four coins at once.",
"meta_og_title": "Compare Coins · three.ws",
"meta_title": "Compare Coins · three.ws",
"meta_twitter_description": "Overlay price performance and line up market cap, volume, supply, and ATH stats for up to four coins at once.",
"meta_twitter_title": "Compare Coins · three.ws",
- "put_up_to_four_coins_head_to": "Put up to four coins head to head — overlay how they've performed and line up the numbers that matter. Add coins with the search box; the URL updates so you can share the matchup."
+ "put_up_to_four_coins_head_to": "Put up to four coins head to head: overlay how they've performed and line up the numbers that matter. Add coins with the search box; the URL updates so you can share the matchup."
},
"compose": {
"accessory": "Accessory",
diff --git a/src/club.js b/src/club.js
index 37302c167..c0e0a4d94 100644
--- a/src/club.js
+++ b/src/club.js
@@ -2446,6 +2446,15 @@ renderPoles();
// unpaid_atomics so the user can watch the value drain as the payout cron
// sweeps. Polling pauses when the tab is hidden to spare RPC budget.
const LB_REFRESH_MS = 30_000;
+// Empty copy is per window: "no tips yet" is only true of the all-time board.
+// On 24h or 1h the club has simply been quiet, and telling a visitor there has
+// never been a tip here when the all-time board is full reads as broken.
+const LB_EMPTY_COPY = {
+ hour: 'Quiet hour so far. Tip a dancer and take the top spot.',
+ day: 'No tips in the last 24 hours. Tip a dancer and take the top spot.',
+ week: 'No tips this week. Tip a dancer and take the top spot.',
+ all: 'No tips yet. Be the first to tip a dancer!',
+};
let lbWindow = 'day';
let lbTimer = null;
let lbInflight = false;
diff --git a/src/communities.js b/src/communities.js
index 58ec886b3..59f2ee961 100644
--- a/src/communities.js
+++ b/src/communities.js
@@ -21,6 +21,7 @@ const nameInput = $('name-input');
const avatarRow = $('avatar-row');
const avatarUrlInput = $('avatar-url-input');
const avatarUrlError = $('avatar-url-error');
+const avatarHint = $('avatar-hint');
const coinGrid = $('coin-grid');
const searchInput = $('coin-search');
const mintInput = $('mint-input');
@@ -122,10 +123,22 @@ async function initAvatars() {
if (saved && saved.kind) selectedAvatar = saved;
} catch {}
- // Signed-in users get their real avatars to pick from.
+ // Signed-in users get their real avatars to pick from. /api/auth/me answers
+ // 200 with `{ user: null }` when signed out, so probing it first costs one
+ // clean request and skips a roster read that could only 401 (which lands as a
+ // red console error on a page most visitors reach signed out).
+ let signedIn = false;
+ let rosterFailed = false;
+ let ownedCount = 0;
try {
- const res = await fetch('/api/avatars?limit=24', { credentials: 'include' });
- if (res.ok) {
+ const me = await fetch('/api/auth/me', { credentials: 'include', headers: { accept: 'application/json' } });
+ signedIn = me.ok && !!(await me.json())?.user;
+ } catch { /* offline: treat as signed out, default + paste still work */ }
+
+ if (signedIn) {
+ try {
+ const res = await fetch('/api/avatars?limit=24', { credentials: 'include', headers: { accept: 'application/json' } });
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json();
const avatars = data?.avatars ?? [];
for (const a of avatars) {
@@ -137,9 +150,13 @@ async function initAvatars() {
});
chip.dataset.value = a.id;
avatarRow.appendChild(chip);
+ ownedCount++;
}
+ } catch (err) {
+ rosterFailed = true;
+ log.warn('[communities] avatar roster', err?.message ?? err);
}
- } catch { /* not signed in / offline — default + paste still work */ }
+ }
// "Create one" shortcut so an empty-handed user has a path to their own avatar.
const create = document.createElement('a');
@@ -148,9 +165,28 @@ async function initAvatars() {
create.innerHTML = `<span class="avatar-thumb"><span class="avatar-glyph">+</span></span><span class="avatar-name">Create</span>`;
avatarRow.appendChild(create);
+ renderAvatarHint({ signedIn, rosterFailed, ownedCount });
markSelectedAvatar();
}
+// A row holding only "Default" and "Create" looks broken unless it says why.
+function renderAvatarHint({ signedIn, rosterFailed, ownedCount }) {
+ if (!avatarHint) return;
+ if (rosterFailed) {
+ avatarHint.innerHTML = 'Your saved avatars could not be loaded. The default avatar and a pasted URL still work.';
+ return;
+ }
+ if (!signedIn) {
+ avatarHint.innerHTML = '<a href="/login">Sign in</a> to pick from your saved avatars, or walk in with the default.';
+ return;
+ }
+ if (!ownedCount) {
+ avatarHint.innerHTML = 'No saved avatars yet. <a href="/create">Create one</a> and it shows up here.';
+ return;
+ }
+ avatarHint.textContent = '';
+}
+
// Paste a direct GLB / VRM / Ready Player Me URL.
function setAvatarUrlMessage(text, ok = false) {
if (!avatarUrlError) return;
@@ -400,8 +436,11 @@ function fmtAge(ts) {
function shortAddr(a) { return a ? `${a.slice(0, 4)}…${a.slice(-4)}` : ''; }
-async function loadCoinProfile(mint) {
- if (_coinProfileMint === mint) return;
+async function loadCoinProfile(mint, { force = false } = {}) {
+ // Retry re-requests the mint the page is already showing, so the
+ // already-loaded guard has to yield to an explicit retry or the button is
+ // dead on exactly the failure it exists for.
+ if (_coinProfileMint === mint && !force) return;
_coinProfileMint = mint;
$('coin-profile-skeleton').hidden = false;
@@ -436,7 +475,7 @@ async function loadCoinProfile(mint) {
setPageTitle('Couldn’t load coin · three.ws');
if (retryBtn) {
retryBtn.hidden = false;
- retryBtn.onclick = () => loadCoinProfile(mint);
+ retryBtn.onclick = () => loadCoinProfile(mint, { force: true });
}
} else {
releaseI18n($('coin-profile-empty-msg'));
diff --git a/src/create-prompt.js b/src/create-prompt.js
index 5856d8309..529cd3a43 100644
--- a/src/create-prompt.js
+++ b/src/create-prompt.js
@@ -123,6 +123,10 @@ $('#back-btn').addEventListener('click', () => {
generateBtn.addEventListener('click', start);
+// Bound once at module scope, not inside renderDone: re-binding it per finished
+// build stacked a fresh listener on the same button every time.
+$('#make-another').addEventListener('click', () => resetToCompose());
+
// ── Submit + poll ────────────────────────────────────────────────────────────
function nameFromPrompt(prompt) {
@@ -366,7 +370,7 @@ function setProgressWidth(pct) {
// ── Done ─────────────────────────────────────────────────────────────────────
-async function renderDone(avatarId) {
+async function renderDone(avatarId, run) {
let avatar = null;
try {
const res = await fetch(`/api/avatars/${encodeURIComponent(avatarId)}`, { credentials: 'include' });
@@ -375,10 +379,11 @@ async function renderDone(avatarId) {
} catch (err) {
log.warn('[create-prompt] could not fetch finished avatar', err);
}
+ // The avatar fetch is another await the user can cancel across.
+ if (isStale(run)) return;
const editorUrl = `/avatars/${encodeURIComponent(avatarId)}/edit`;
$('#open-editor').setAttribute('href', editorUrl);
- $('#make-another').addEventListener('click', () => resetToCompose());
// Private avatars (the default for this flow) have a null public model_url;
// the owner's GET response carries a short-lived presigned `url` instead.
@@ -428,6 +433,9 @@ async function renderDone(avatarId) {
}
function resetToCompose() {
+ // Burn the current build token: whatever run was in flight can no longer
+ // write to the screen the user just came back to.
+ _runId++;
_submitting = false;
stopElapsed();
setError(composeError, '');
@@ -483,11 +491,13 @@ function prefersReducedMotion() {
}
}
-// Cancel button on the building screen — and Escape as a keyboard equivalent.
+// Cancel button on the building screen, with Escape as a keyboard equivalent.
+// Both defer the "is there anything to cancel?" test to cancelBuild so the two
+// entry points can never disagree about when cancelling is allowed.
const cancelBtn = document.getElementById('cancel-build');
cancelBtn?.addEventListener('click', cancelBuild);
document.addEventListener('keydown', (e) => {
- if (e.key === 'Escape' && _submitting) cancelBuild();
+ if (e.key === 'Escape') cancelBuild();
});
// Deep link: /create/prompt?prompt=<text> prefills the composer, so "copy
diff --git a/src/scene-compose.js b/src/scene-compose.js
index b227f2b61..b9fc49c7d 100644
--- a/src/scene-compose.js
+++ b/src/scene-compose.js
@@ -1149,67 +1149,119 @@ async function loadAvatar(url, name = 'Avatar', record = null) {
})();
// ── Avatar prompt UI ──────────────────────────────────────────────────────────
-btnLoadUrl.addEventListener('click', () => {
- const url = avatarUrlInput.value.trim();
- if (!url) return;
- loadAvatar(url, 'Avatar');
+btnLoadUrl.addEventListener('click', async () => {
+ const value = avatarUrlInput.value.trim();
+ if (!value) { showAvatarError('Paste a GLB URL or an avatar ID first.'); avatarUrlInput.focus(); return; }
+ clearAvatarError();
+ showLoading('Resolving avatar…');
+ try {
+ const { url, name, record } = await resolveAvatarInput(value);
+ await loadAvatar(url, name, record);
+ } catch (err) {
+ hideLoading();
+ showAvatarError(`${err.message}. Paste a public .glb URL, or browse your avatars below.`);
+ avatarUrlInput.focus();
+ }
});
avatarUrlInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') btnLoadUrl.click(); });
-btnSkip.addEventListener('click', () => { avatarPrompt.classList.add('h'); canvasHint.classList.remove('h'); hideLoading(); });
-btnLoadAvSmall.addEventListener('click', () => avatarPrompt.classList.remove('h'));
+avatarUrlInput.addEventListener('input', clearAvatarError);
+btnSkip.addEventListener('click', () => { avatarPrompt.classList.add('h'); clearAvatarError(); canvasHint.classList.remove('h'); hideLoading(); });
+btnLoadAvSmall.addEventListener('click', () => { avatarPrompt.classList.remove('h'); setScenePanel(false); avatarUrlInput.focus(); });
btnBrowseAv.addEventListener('click', openAvatarModal);
avatarModalClose.addEventListener('click', closeAvatarModal);
avatarModal.addEventListener('click', (e) => { if (e.target === avatarModal) closeAvatarModal(); });
+function avatarModalMessage(text, { error = false, retry = false, link = null } = {}) {
+ avatarModalBody.innerHTML = '';
+ const box = document.createElement('div');
+ box.className = 'ame' + (error ? ' err' : '');
+ box.append(text);
+ if (link) {
+ const a = document.createElement('a');
+ a.href = link.href; a.textContent = link.label;
+ box.append(' ', a);
+ }
+ if (retry) {
+ const btn = document.createElement('button');
+ btn.type = 'button';
+ btn.className = 'geb';
+ btn.textContent = 'Try again';
+ btn.addEventListener('click', () => loadAvatarChoices());
+ box.append(document.createElement('br'), btn);
+ }
+ avatarModalBody.appendChild(box);
+}
+
async function openAvatarModal() {
- avatarModal.hidden = false;
- avatarModalBody.innerHTML = '<div style="grid-column:1/-1;text-align:center;padding:24px;color:#52525b;font-size:12px;">Loading…</div>';
+ openDialog(avatarModal, avatarModalClose);
+ await loadAvatarChoices();
+}
+
+async function loadAvatarChoices() {
+ avatarModalBody.setAttribute('aria-busy', 'true');
+ avatarModalMessage('Loading avatars…');
try {
- const res = await fetch('/api/explore?type=avatar&limit=24');
+ // source=avatar&only3d=1, not the invented type=avatar: /api/explore has no
+ // `type` param, so the old call returned a mixed on-chain-agent feed whose
+ // rows mostly carry no model at all, and the picker silently dropped them.
+ const res = await fetch('/api/explore?source=avatar&only3d=1&limit=24');
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json().catch(() => ({}));
- const avatars = data.avatars || data.items || [];
- avatarModalBody.innerHTML = '';
+ const avatars = (data.items || data.avatars || []).filter((a) => a.glbUrl || a.glb_url);
if (!avatars.length) {
- avatarModalBody.innerHTML = '<div style="grid-column:1/-1;text-align:center;padding:24px;color:#52525b;font-size:12px;">No avatars found. <a href="/forge" style="color:#a5b4fc;">Forge one first.</a></div>';
+ avatarModalMessage('No public avatars are available yet.', { link: { href: '/create', label: 'Create one →' } });
return;
}
+ avatarModalBody.innerHTML = '';
for (const av of avatars) {
const glbUrl = av.glbUrl || av.glb_url;
- if (!glbUrl) continue;
- const card = document.createElement('div');
- card.style.cssText = 'aspect-ratio:1;border-radius:8px;overflow:hidden;cursor:pointer;background:#111120;border:1px solid rgba(255,255,255,.07);position:relative;transition:border-color .12s,transform .1s;';
- card.addEventListener('mouseenter', () => { card.style.borderColor='rgba(99,102,241,.5)'; card.style.transform='scale(1.03)'; });
- card.addEventListener('mouseleave', () => { card.style.borderColor=''; card.style.transform=''; });
- const thumb = av.thumbnailUrl || av.thumbnail_url;
+ const name = av.name || 'Avatar';
+ const card = document.createElement('button');
+ card.type = 'button';
+ card.className = 'amcard';
+ card.title = name;
+ // /api/explore returns the avatar thumbnail as `image`; the old
+ // thumbnailUrl/thumbnail_url read never matched, so every card fell
+ // through to the placeholder glyph.
+ const thumb = av.image || av.thumbnailUrl || av.thumbnail_url;
if (thumb) {
const img = document.createElement('img');
- img.src = thumb; img.alt = av.name || 'Avatar';
- img.style.cssText = 'width:100%;height:100%;object-fit:cover;';
+ img.src = thumb; img.alt = ''; img.loading = 'lazy';
+ img.addEventListener('error', () => { img.replaceWith(placeholderGlyph()); });
card.appendChild(img);
} else {
- card.style.display = 'flex'; card.style.alignItems = 'center'; card.style.justifyContent = 'center';
- card.innerHTML = '<span style="font-size:28px;opacity:.3;">◉</span>';
+ card.appendChild(placeholderGlyph());
}
- const lbl = document.createElement('div');
- lbl.style.cssText = 'position:absolute;bottom:0;left:0;right:0;padding:4px 6px;background:rgba(0,0,0,.65);font-size:10px;color:#fff;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;';
- lbl.textContent = av.name || 'Avatar';
+ const lbl = document.createElement('span');
+ lbl.className = 'amlb';
+ lbl.textContent = name;
card.appendChild(lbl);
// /api/explore names the avatar record `avatarId`; carrying it through
// is what lets "Save outfit" write back to the browsed avatar.
const recordId = av.avatarId || av.id || null;
card.addEventListener('click', () => {
closeAvatarModal();
- loadAvatar(glbUrl, av.name || 'Avatar', recordId ? { id: recordId } : null);
+ loadAvatar(glbUrl, name, recordId ? { id: recordId } : null);
});
avatarModalBody.appendChild(card);
}
- } catch {
- avatarModalBody.innerHTML = '<div style="grid-column:1/-1;text-align:center;padding:24px;color:#f87171;font-size:12px;">Failed to load avatars</div>';
+ } catch (err) {
+ avatarModalMessage(`Could not load avatars: ${err.message}.`, { error: true, retry: true });
+ } finally {
+ avatarModalBody.setAttribute('aria-busy', 'false');
}
}
-function closeAvatarModal() { avatarModal.hidden = true; }
+function placeholderGlyph() {
+ const span = document.createElement('span');
+ span.className = 'amph';
+ span.setAttribute('aria-hidden', 'true');
+ span.textContent = '◉';
+ return span;
+}
+
+function closeAvatarModal() { closeDialog(avatarModal); }
// ── Intent chips + suggested prompts ─────────────────────────────────────────
function updateSuggestions() {
@@ -1367,43 +1419,81 @@ function promptGradient(str) {
return `linear-gradient(135deg,hsl(${hue},28%,14%),hsl(${(hue+40)%360},22%,10%))`;
}
+function galleryMessage(text, { retry = false } = {}) {
+ creationsList.innerHTML = '';
+ const box = document.createElement('div');
+ box.className = 'ge';
+ box.append(text);
+ if (retry) {
+ const btn = document.createElement('button');
+ btn.type = 'button';
+ btn.className = 'geb';
+ btn.textContent = 'Try again';
+ btn.addEventListener('click', () => loadGallery());
+ box.append(document.createElement('br'), btn);
+ }
+ creationsList.appendChild(box);
+}
+
+async function fetchCreations(query) {
+ const res = await fetch(`/api/forge-gallery?${query}`, { headers: CH });
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const data = await res.json().catch(() => ({}));
+ return (data.creations || []).filter((c) => c.glb_url);
+}
+
async function loadGallery() {
+ creationsList.setAttribute('aria-busy', 'true');
+ galleryMessage('Loading…');
try {
- const res = await fetch('/api/forge-gallery?limit=24', { headers: CH });
- const data = await res.json().catch(() => ({}));
- const items = data.creations || [];
+ let items = await fetchCreations('limit=24');
+ let mine = true;
if (!items.length) {
- creationsList.innerHTML = '<div class="ge">Forge your first item above</div>';
+ // A first-time visitor has no creations of their own, and an empty strip
+ // left the fastest path into the composer (drop a real model into the
+ // scene) behind a multi-minute generation. The community showcase is a
+ // live public feed, so seed the strip from that instead.
+ mine = false;
+ items = await fetchCreations('scope=community&limit=24');
+ }
+ creationsHead.textContent = mine ? 'Recent Creations' : 'Fresh from the Forge';
+ if (!items.length) {
+ galleryMessage('No creations yet. Describe an item above and press Forge to make the first one.');
return;
}
creationsList.innerHTML = '';
for (const c of items) {
- if (!c.glb_url) continue;
- const card = document.createElement('div');
+ const label = c.prompt || 'Forged item';
+ const card = document.createElement('button');
+ card.type = 'button';
card.className = 'gc';
- card.title = c.prompt || 'Forged item';
+ card.title = label;
+ card.setAttribute('aria-label', `Add to scene: ${label}`);
if (c.preview_image_url) {
const img = document.createElement('img');
- img.src = c.preview_image_url; img.alt = c.prompt || ''; img.loading = 'lazy';
- img.onerror = () => { img.remove(); addGradient(card, c.prompt); };
+ img.src = c.preview_image_url; img.alt = ''; img.loading = 'lazy';
+ img.addEventListener('error', () => { img.remove(); addGradient(card, c.prompt); });
card.appendChild(img);
} else {
addGradient(card, c.prompt);
}
- const ov = document.createElement('div');
+ // Spans, not divs: a <button> may only contain phrasing content.
+ const ov = document.createElement('span');
ov.className = 'gco';
- ov.innerHTML = `<div class="gcp">${escHtml(c.prompt || 'Forged item')}</div><div class="gca">+ Add to scene</div>`;
+ ov.innerHTML = `<span class="gcp">${escHtml(label)}</span><span class="gca">+ Add to scene</span>`;
card.appendChild(ov);
card.addEventListener('click', () => loadGalleryItem(c));
creationsList.appendChild(card);
}
- } catch {
- creationsList.innerHTML = '<div class="ge">Could not load creations</div>';
+ } catch (err) {
+ galleryMessage(`Could not load creations: ${err.message}.`, { retry: true });
+ } finally {
+ creationsList.setAttribute('aria-busy', 'false');
}
}
function addGradient(card, prompt) {
- const d = document.createElement('div');
+ const d = document.createElement('span');
d.className = 'gcg'; d.textContent = prompt || 'Forged item';
d.style.background = promptGradient(prompt);
card.prepend(d);