Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794<!doctype html><!-- aligned.click — the product page. Copyright (C) 2026 Johan Lagerlöf. Licensed under the GNU AGPL v3 or later. See LICENSE. --><html lang="en"><head><meta charset="utf-8"><title>aligned.click</title><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><meta name="theme-color" content="#0f1419"><!-- Served by app/server.py, which sends the CSP as a header. `connect-src 'self' https:` stays open because atproto-post draws each pick live from whichever PDS hosts its author — nothing here stores post text. --><script type="module" src="/shared/atproto-wc.js"></script><link rel="stylesheet" href="/shared/theme.css"><style> :root { --bg: #0f1419; /* terminal ink */ --fg: #c9d1d9; --muted: #8b949e; --dim: #4b5560; --border: #21262d; --accent: #4ade80; /* the cursor / the highlight */ --accent-fill: #12261a; --atproto-accent: var(--accent); --ask-border: #3a4048; color-scheme: dark; } * { box-sizing: border-box; } html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; } body { display: flex; min-height: 100vh; }
/* ---- the left pane -------------------------------------------------- */ nav#pane { flex: 0 0 320px; border-right: 1px solid var(--border); padding: 18px 0; overflow-y: auto; position: sticky; top: 0; height: 100vh; } nav#pane .brand { display: block; width: 100%; text-align: left; cursor: pointer; font: inherit; color: var(--fg); background: none; border: 0; padding: 6px 20px; font-weight: 700; letter-spacing: 0.02em; } nav#pane .brand .dot { color: var(--accent); } nav#pane .me { display: flex; align-items: center; gap: 8px; padding: 6px 20px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); margin-bottom: 4px; } nav#pane .me .mehandle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } nav#pane .me button { font-size: 12px; padding: 2px 8px; margin-left: auto; } nav#pane .grp { font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); margin: 18px 20px 4px; } nav#pane .trow { position: relative; display: flex; align-items: flex-start; } nav#pane button.topic { flex: 1; min-width: 0; display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left; font: inherit; color: var(--fg); background: none; border: 0; padding: 6px 20px; cursor: pointer; } nav#pane button.topic:hover { background: #161b22; } nav#pane button.topic .marker { color: var(--accent); flex: none; } nav#pane button.topic .name { flex: 1; min-width: 0; overflow-wrap: anywhere; } nav#pane button.topic .n { color: var(--dim); flex: none; font-size: 12px; margin-left: 6px; } nav#pane button.topic.active .name { color: var(--accent); } nav#pane button.topic.busy .name { color: var(--muted); font-style: italic; } nav#pane button.dots { flex: none; border: 0; background: none; color: var(--dim); cursor: pointer; font-size: 14px; padding: 6px 10px; } nav#pane button.dots:hover { color: var(--accent); } nav#pane .tmenu { position: absolute; right: 8px; top: 100%; z-index: 5; background: #161b22; border: 1px solid var(--border); border-radius: 4px; padding: 4px; } nav#pane .tmenu button { display: block; width: 100%; text-align: left; border: 0; background: none; color: #f85149; padding: 6px 14px; font-size: 13px; cursor: pointer; } nav#pane .tmenu button:hover { background: #21262d; } nav#pane .status { font-size: 12px; color: var(--dim); margin: 0 20px 8px 44px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } nav#pane .sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
/* ---- the ask --------------------------------------------------------- */ main { flex: 1; padding: 22px 28px 96px; max-width: 820px; } .prompt { display: flex; gap: 10px; align-items: center; } .prompt .dollar { color: var(--accent); font-weight: 700; flex: none; } #q { flex: 1; font: inherit; color: var(--fg); background: transparent; border: 0; padding: 8px 0; outline: none; caret-color: var(--accent); /* A multi-line ask: long wishes wrap instead of overflowing off-screen. The box auto-grows to its content; the typing animation reserves the full example's height up-front so wrapping a second line in does not shift the caret or the page as it types. */ resize: none; line-height: 1.4; overflow-y: hidden; } .askrow { display: flex; gap: 10px; margin-top: 8px; justify-content: flex-end; } button { font: inherit; border: 1px solid var(--border); border-radius: 4px; padding: 6px 14px; cursor: pointer; background: var(--bg); color: var(--fg); } button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); } button:disabled { color: var(--dim); cursor: default; } #login { border-color: var(--ask-border); } .error { color: #f85149; margin-top: 10px; white-space: pre-wrap; }
/* ---- the feed -------------------------------------------------------- */ #result { margin-top: 26px; } h2.feedhead { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); margin: 0 0 12px; } h2.feedhead .dash { color: var(--accent); } .batch { display: grid; gap: 18px; } .pick { border-top: 1px solid var(--border); padding-top: 12px; } .pick atproto-post { display: block; } .pick .attrline { font-size: 13px; color: var(--muted); margin-top: 8px; } .pick .attrline .who { color: var(--accent); } .pick .attrline .topic { color: var(--fg); } .pick .foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 8px; } .pick .acts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; } /* a reply's parent — the dimmed thread context above the reply, like bsky */ .parentline { opacity: 0.72; border-left: 2px solid var(--border); padding-left: 10px; margin-bottom: 4px; } .plus { font-size: 13px; padding: 3px 12px; border-radius: 4px; flex: none; } .plus.voted { border-color: var(--accent); color: var(--accent); } .plus .n { margin-left: 4px; color: var(--muted); } .plus.voted .n { color: var(--accent); } .act { font-size: 12px; padding: 3px 9px; border-radius: 4px; flex: none; } .act.on { border-color: var(--accent); color: var(--accent); } a.act.link { text-decoration: none; } /* members' fit/no-fit verdict on a post inside a topic — private ground truth for the judge, shown only in topic view */ .fitrow { display: inline-flex; gap: 4px; align-items: center; } button.fit { font-size: 12px; padding: 3px 10px; border-radius: 4px; flex: none; } button.fit.on { border-color: var(--accent); color: var(--accent); } button.fit.nofit.on { border-color: #f85149; color: #f85149; } .fitrow .sep { color: var(--dim); margin: 0 2px; } .topichead { margin: -6px 0 14px; } .empty { color: var(--muted); padding: 10px 0; } .more { color: var(--dim); text-align: center; padding: 8px 0; }
/* ---- mobile: the pane becomes a slide-in overlay -------------------- */ /* The toggle button is hidden on wide screens and only appears on narrow ones, where the left pane is off-canvas until opened. */ .pane-toggle { display: none; } @media (max-width: 720px) { body { display: block; } nav#pane { position: fixed; top: 0; left: 0; bottom: 0; width: 300px; height: 100vh; z-index: 20; background: var(--bg); transform: translateX(-100%); transition: transform 0.2s ease; } nav#pane.open { transform: translateX(0); box-shadow: 0 0 24px rgba(0, 0, 0, 0.5); } main { max-width: none; padding: 18px 16px 96px; } .pane-toggle { display: block; position: fixed; left: 0; top: 50%; transform: translateY(-50%); z-index: 30; border: 1px solid var(--border); border-left: 0; border-radius: 0 6px 6px 0; background: var(--bg); color: var(--accent); padding: 10px 5px; font-size: 14px; } .pane-toggle:hover:not(:disabled) { border-color: var(--accent); } .pane-toggle.open { left: 300px; border-left: 1px solid var(--border); } }</style></head><body><nav id="pane"> <button class="brand" id="brand">aligned<span class="dot">.</span>click</button> <div class="me" id="me"></div> <div id="groups"></div></nav>
<main> <button id="paneToggle" class="pane-toggle" aria-label="show or hide the topics pane">❯</button> <header class="ask"> <div class="prompt"> <span class="dollar">$</span> <textarea id="q" rows="1" autocomplete="off" autocapitalize="off" spellcheck="false" maxlength="300" aria-label="what do you want to see more of"></textarea> </div> <div class="askrow"> <button id="run" disabled>add topic</button> </div> <div class="error" id="error" hidden></div> </header>
<main id="result"> <h2 class="feedhead"><span class="dash">──</span> the feed</h2> <div class="empty">The pool is still growing — posts appear as the worker finds and judges them.</div> </main></main>
<script> const Q = document.getElementById("q"); const RUN = document.getElementById("run"); const ME = document.getElementById("me"); const ERROR = document.getElementById("error"); const RESULT = document.getElementById("result"); const GROUPS = document.getElementById("groups"); const PAGE = 10; const EXAMPLES = [ "about community gardens", "experiences of local economies", "about urban beekeeping", "about repairing and mending things", "about loading big things on bicycles", "about open source mechanical design", ]; const BASE = "I want to see more content ";
let me = null; // {did, handle} once logged in let view = null; // {kind: "all"} | {kind: "topic", rkey}
function esc(s) { return String(s ?? "").replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'", }[c])); }
function showError(msg) { ERROR.textContent = msg; ERROR.hidden = !msg; }
// ---- the ask: typing animation ------------------------------------------- // "I want to see more content " stays fixed; only the example after it is // typed and deleted. The box auto-grows to fit a topic of any length, but // during the animation the full example's height is reserved up-front so the // box does not grow a line at a time (which would jump the caret and page).
let animTimer = null; let focused = false;
// Fit the box to its current content. Minus the vertical padding so the text // sits inside rather than forcing a scrollbar. function fitQ() { Q.style.height = "auto"; Q.style.height = Q.scrollHeight + "px"; }
// Set the box to the height its content would need, without changing text. // Used to reserve space for a whole example before typing starts. function fitText(text) { const was = Q.value; Q.style.height = "auto"; Q.value = text; Q.style.height = Q.scrollHeight + "px"; Q.value = was; }
function stopAnim() { if (animTimer) { clearTimeout(animTimer); animTimer = null; } }
function typeLoop(i) { if (focused) return; const example = EXAMPLES[i % EXAMPLES.length]; let pos = 0; // Reserve the full example's height now, so wrapping a second line in as // it types does not grow the box and shift the caret/page. fitText(BASE + example); const type = () => { if (focused) return; pos++; Q.value = BASE + example.slice(0, pos); animTimer = pos < example.length ? setTimeout(type, 42) : setTimeout(erase, 1700); }; const erase = () => { if (focused) return; pos--; Q.value = BASE + example.slice(0, pos); animTimer = pos > 0 ? setTimeout(erase, 22) : setTimeout(() => typeLoop(i + 1), 350); }; type(); }
Q.addEventListener("focus", () => { focused = true; stopAnim(); Q.value = BASE; fitQ(); Q.setSelectionRange(Q.value.length, Q.value.length); });
// The "I want to see more content " prefix is fixed — it reads like the // product's sentence, so the reader must not be able to erase or rewrite // it and hand back a bare or rephrased wish. Guard every edit path: the // caret can't cross the prefix boundary and any edit that would break the // prefix is undone. const PRE = BASE.length; function guardPrefix() { // Strip any number of leading prefixes, then re-add exactly one — a paste // that already carried the prefix must not double it ("I want to see more // content I want to see more content <wish>"). let v = Q.value; while (v.startsWith(BASE)) v = v.slice(BASE.length); Q.value = BASE + v; const at = Q.selectionStart ?? PRE; if (at < PRE) Q.setSelectionRange(PRE, PRE); } Q.addEventListener("keydown", (e) => { const at = Q.selectionStart ?? PRE; const end = Q.selectionEnd ?? at; const touching = at < PRE || (e.key === "Backspace" && at <= PRE) || (e.key === "Delete" && end <= PRE); if (touching) { e.preventDefault(); Q.setSelectionRange(PRE, Math.max(PRE, end)); } }); Q.addEventListener("input", () => { guardPrefix(); fitQ(); updateAuth(); }); Q.addEventListener("select", guardPrefix); Q.addEventListener("keyup", guardPrefix); Q.addEventListener("click", guardPrefix); Q.addEventListener("cut", () => { setTimeout(guardPrefix, 0); }); Q.addEventListener("paste", () => { setTimeout(guardPrefix, 0); });
// ---- auth ----------------------------------------------------------------
function updateAuth() { RUN.disabled = !(me && me.did) || !Q.value.trim(); if (me && me.did) { const handle = me.handle || me.did; ME.innerHTML = `<span class="mehandle">@${esc(handle)}</span> <button id="logout">log out</button>`; document.getElementById("logout").addEventListener("click", () => { localStorage.removeItem("aligned_me"); me = null; updateAuth(); location.href = "/logout"; }); } else { ME.innerHTML = `<button id="login">log in</button>`; // Login is the proxy's flow: it owns the OAuth session, serves the // sign-in page at /login (atproto account intro, account-creation // options like Eurosky, then the handle form), and comes back here. document.getElementById("login").addEventListener("click", () => { location.href = "/login"; }); } }
// ---- the feed ------------------------------------------------------------
function feedUrl(offset) { const q = new URLSearchParams({ limit: PAGE }); if (offset) q.set("offset", offset); return `/api/feeds?${q}`; }
function topicUrl(rkey, offset) { const q = new URLSearchParams({ limit: PAGE }); if (offset) q.set("offset", offset); return `/api/topic/${encodeURIComponent(rkey)}?${q}`; }
function postCard(p) { const attrs = (p.topics || []).map(t => `<div class="attrline"><span class="who">@${esc(t.handle || "?")}</span> wants to see more content <span class="topic">${esc(t.text)}</span></div>`).join("\n"); const plus = view && view.kind === "topic" ? "" // the topic view endorses the topic itself, not each post : `<button class="plus ${p.voted ? "voted" : ""}" data-uri="${esc(p.uri)}"> ${p.voted ? "✓" : "+1"}<span class="n">${p.votes || 0}</span></button>`; // Members judge fit inside a topic — the ground truth the judge prompt // will learn from. Topic view only; the main feed's union has no single // topic to attach a verdict to. const fitrow = view && view.kind === "topic" && me && me.member ? `<span class="fitrow"> <button class="fit ${p.fitVerdict === "fit" ? "on" : ""}" data-fit="fit" data-uri="${esc(p.uri)}" data-topic="${esc(view.rkey)}" title="this post fits the topic">fit</button> <span class="sep">/</span> <button class="fit nofit ${p.fitVerdict === "no-fit" ? "on" : ""}" data-fit="no-fit" data-uri="${esc(p.uri)}" data-topic="${esc(view.rkey)}" title="this post does not fit the topic">no-fit</button> </span>` : ""; const url = bskyPostUrl(p.uri); // A reply is shown with the post it replies to, like on bsky — the // compact parent card draws the thread context above the reply itself. const parent = p.replyTo ? `<div class="parentline"><atproto-post src="${esc(p.replyTo)}" compact no-counts></atproto-post></div>` : ""; return `<article class="pick"> ${parent} <atproto-post src="${esc(p.uri)}"></atproto-post> <div class="acts"> ${fitrow} <button class="act ${p.liked ? "on" : ""}" data-kind="like" data-uri="${esc(p.uri)}" title="like on Bluesky">♥ ${p.liked ? "liked" : "like"}</button> <button class="act ${p.reposted ? "on" : ""}" data-kind="repost" data-uri="${esc(p.uri)}" title="repost on Bluesky">↻ ${p.reposted ? "reposted" : "repost"}</button> <a class="act link" href="${esc(url)}" target="_blank" rel="noopener noreferrer" title="reply on bsky.app">↩ reply</a> <a class="act link" href="${esc(url)}" target="_blank" rel="noopener noreferrer" title="quote on bsky.app">❝ quote</a> </div> ${(attrs || plus) ? `<div class="foot">${attrs ? `<div>${attrs}</div>` : ""}${plus}</div>` : ""} </article>`; }
function bskyPostUrl(uri) { // at://did:plc:…/app.bsky.feed.post/<rkey> -> bsky.app thread URL. // The DID's colons are real path separators on bsky.app, so encode each // part separately — encoding the whole DID turns the colons into %3A and // bsky.app 404s on the mangled profile. const m = /^at:\/\/([^/]+)\/app\.bsky\.feed\.post\/([^/]+)$/.exec(uri || ""); if (!m) return "https://bsky.app"; const profile = m[1].split(":").map(encodeURIComponent).join(":"); return `https://bsky.app/profile/${profile}/post/${encodeURIComponent(m[2])}`; }
let feedState = null; // {batch, offset, hasMore} for the current view let loading = false;
function renderMain(d) { const posts = d.main || []; const head = `<h2 class="feedhead"><span class="dash">──</span> the feed</h2>`; if (posts.length === 0) { RESULT.innerHTML = head + '<div class="empty">The pool is still growing — ' + 'posts appear as the worker finds and judges them.</div>'; feedState = { batch: 0, offset: 0, hasMore: false }; return; } let cards = '<div class="batch">'; for (const p of posts) cards += postCard(p); cards += `<div class="more" id="more">…</div></div>`; RESULT.innerHTML = head + cards; feedState = { batch: 1, offset: d.offset, hasMore: d.hasMore }; bindActs(); maybeMore(); }
function appendPosts(posts) { const batch = RESULT.querySelector(".batch") || document.createElement("div"); if (!batch.classList.contains("batch")) batch.classList.add("batch"); if (!batch.parentNode) RESULT.appendChild(batch); batch.querySelector("#more")?.remove(); for (const p of posts) batch.insertAdjacentHTML("beforeend", postCard(p)); if (feedState && feedState.hasMore) { batch.insertAdjacentHTML("beforeend", '<div class="more" id="more">…</div>'); } bindActs(); }
function loadMore() { if (!feedState || !feedState.hasMore || loading) return; loading = true; const url = view && view.kind === "topic" ? topicUrl(view.rkey, feedState.offset) : feedUrl(feedState.offset); fetch(url, { headers: { Accept: "application/json" } }) .then(r => r.json()) .then(d => { const posts = view && view.kind === "topic" ? (d.posts || []) : (d.main || []); appendPosts(posts); feedState.batch++; feedState.offset = d.offset; feedState.hasMore = d.hasMore; maybeMore(); }) .catch(() => { feedState.hasMore = false; }) .finally(() => { loading = false; }); }
function maybeMore() { const sentinel = document.getElementById("more"); if (feedState && feedState.hasMore && sentinel) { const r = sentinel.getBoundingClientRect(); if (r.top < window.innerHeight * 1.4) loadMore(); } }
// bindActs re-runs after every append and every re-render; a button must get // its listener exactly once, or a second page load stacks a handler on the // first page's buttons and a click fires twice (the verdict set-then-clears). const boundActs = new Set();
function bindActs() { for (const btn of RESULT.querySelectorAll(".plus[data-topic]")) { if (boundActs.has(btn)) continue; boundActs.add(btn); btn.addEventListener("click", async () => { if (!(me && me.did)) { showError("log in to +1 topics"); return; } showError(""); const uri = btn.dataset.topic; const r = await fetch("/api/vote", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ uri }) }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); btn.classList.add("voted"); btn.firstChild.textContent = "✓"; btn.querySelector(".n").textContent = d.count; }); } for (const btn of RESULT.querySelectorAll(".plus:not([data-topic])")) { if (boundActs.has(btn)) continue; boundActs.add(btn); btn.addEventListener("click", async () => { if (!(me && me.did)) { showError("log in to +1 posts"); return; } showError(""); const uri = btn.dataset.uri; const r = await fetch("/api/vote", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ uri }) }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); btn.classList.add("voted"); btn.firstChild.textContent = "✓"; btn.querySelector(".n").textContent = d.count; }); } for (const btn of RESULT.querySelectorAll("button.fit")) { if (boundActs.has(btn)) continue; boundActs.add(btn); btn.addEventListener("click", async () => { if (!(me && me.did)) { showError("log in to judge fit"); return; } showError(""); const uri = btn.dataset.uri, topic = btn.dataset.topic; const label = btn.dataset.fit; try { const r = await fetch("/api/fit", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ uri, topic, label }) }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); // The server's verdict is authoritative; the row re-reads from it, // so state persists across reloads and re-renders. const row = btn.closest(".fitrow"); for (const b of row.querySelectorAll("button.fit")) b.classList.remove("on"); if (d.verdict) { const hit = row.querySelector(`button[data-fit="${d.verdict}"]`); if (hit) hit.classList.add("on"); } } catch (e) { showError(e.message); } }); } for (const btn of RESULT.querySelectorAll("button.act")) { if (boundActs.has(btn)) continue; boundActs.add(btn); btn.addEventListener("click", async () => { if (!(me && me.did)) { showError(`log in to ${btn.dataset.kind}`); return; } showError(""); const uri = btn.dataset.uri; const kind = btn.dataset.kind; const r = await fetch("/api/engage", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ uri, kind }) }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); if (d.engaged) { btn.classList.add("on"); btn.textContent = (kind === "like" ? "♥ liked" : "↻ reposted"); } else { btn.classList.remove("on"); btn.textContent = (kind === "like" ? "♥ like" : "↻ repost"); } }); } }
async function loadTopic(rkey) { view = { kind: "topic", rkey }; try { const r = await fetch(topicUrl(rkey), { headers: { Accept: "application/json" } }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); const posts = d.posts || []; const t = d.topic || {}; const title = t.handle ? `@${esc(t.handle)} wants to see more content ${esc(t.text)}` : esc(t.text || rkey); const topicPlus = t.uri ? `<button class="plus ${t.voted ? "voted" : ""}" data-topic="${esc(t.uri)}" title="+1 this topic">${t.voted ? "✓" : "+1"}<span class="n">${t.votes || 0}</span></button>` : ""; let head = `<h2 class="feedhead"><span class="dash">──</span> ${title}</h2> <div class="topichead">${topicPlus}</div>`; if (posts.length === 0) { RESULT.innerHTML = head + '<div class="empty">No posts fit this topic yet — the worker ' + 'keeps judging new candidates in its region.</div>'; feedState = { batch: 0, offset: 0, hasMore: false }; return; } let cards = '<div class="batch">'; for (const p of posts) cards += postCard(p); cards += `<div class="more" id="more">…</div></div>`; RESULT.innerHTML = head + cards; feedState = { batch: 1, offset: d.offset, hasMore: d.hasMore }; bindActs(); maybeMore(); } catch (e) { showError(`could not load topic: ${e}`); loadMain(); } }
function loadMain() { view = { kind: "all" }; fetch(feedUrl(), { headers: { Accept: "application/json" } }) .then(r => r.json()) .then(renderMain) .catch(() => renderMain({ main: [], offset: 0, hasMore: false })); }
// ---- the pane: feeds -----------------------------------------------------
// On narrow screens the pane is an off-canvas overlay, toggled with the // chevron button. `>❯` opens it; `❮` (shown while open) closes it. const PANE = document.getElementById("pane"); const PANE_TOGGLE = document.getElementById("paneToggle"); const MOBILE = window.matchMedia("(max-width: 720px)"); let paneOpen = false;
function setPane(open) { paneOpen = open; PANE.classList.toggle("open", open); PANE_TOGGLE.classList.toggle("open", open); PANE_TOGGLE.textContent = open ? "❮" : "❯"; } PANE_TOGGLE.addEventListener("click", () => setPane(!paneOpen)); // Leaving a narrow viewport (or shrinking past it) resets the overlay so a // desktop reload doesn't inherit a half-open pane. MOBILE.addEventListener("change", () => setPane(false));
async function loadPane() { try { const r = await fetch(`/api/topics`, { headers: { Accept: "application/json" } }); const d = await r.json(); renderPane(d.topics || []); } catch (e) { /* the next poll retries */ } }
function renderPane(topics) { const mine = topics.filter(t => t.mine); const liked = topics.filter(t => !t.mine && t.liked); const rest = topics.filter(t => !t.mine && !t.liked); let html = ""; if (mine.length) html += grp("your feeds", mine); if (liked.length) html += grp("feeds you like", liked); if (rest.length) html += grp("other feeds", rest); GROUPS.innerHTML = html; for (const b of GROUPS.querySelectorAll("button.topic")) { b.addEventListener("click", () => { setPane(false); location.hash = encodeURIComponent(b.dataset.rkey); }); } for (const b of GROUPS.querySelectorAll("button.dots")) { b.addEventListener("click", (e) => { e.stopPropagation(); const menu = GROUPS.querySelector(`#tmenu-${CSS.escape(b.dataset.rkey)}`); if (menu) menu.hidden = !menu.hidden; const menus = GROUPS.querySelectorAll(".tmenu"); for (const m of menus) if (m !== menu) m.hidden = true; }); } for (const b of GROUPS.querySelectorAll("button.del")) { b.addEventListener("click", (e) => { e.stopPropagation(); deleteTopic(b.dataset.rkey); }); } document.addEventListener("click", () => { for (const m of GROUPS.querySelectorAll(".tmenu")) m.hidden = true; }); document.getElementById("brand").classList.toggle("active", !(view && view.kind === "topic")); for (const b of GROUPS.querySelectorAll("button.topic")) { b.classList.toggle("active", view && view.kind === "topic" && b.dataset.rkey === view.rkey); } }
function topicTitle(t) { return `${t.handle || "someone"} wants to see more content ${t.text}`; }
function grp(title, topics) { return `<div class="grp">${esc(title)}</div>` + topics.map(t => ` <div class="trow"> <button class="topic ${t.processed ? "" : "busy"}" data-rkey="${esc(t.rkey)}"> <span class="marker">${t.mine ? "❯" : "·"}</span> <span class="name">${esc(topicTitle(t))}</span> <span class="n">${t.posts || ""}</span> </button> ${t.mine ? `<button class="dots" data-rkey="${esc(t.rkey)}" aria-label="topic menu" title="topic menu">⋯</button>` : ""} <div class="tmenu" id="tmenu-${esc(t.rkey)}" hidden> <button class="del" data-rkey="${esc(t.rkey)}">delete</button> </div> </div> ${t.status ? `<div class="status">${esc(t.status)}</div>` : ""}`).join(""); }
async function deleteTopic(rkey) { try { const r = await fetch(`/api/topic/${encodeURIComponent(rkey)}`, { method: "DELETE" }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); if (view && view.kind === "topic" && view.rkey === rkey) { location.hash = "top"; loadMain(); } loadPane(); } catch (e) { showError(`could not delete the topic: ${e}`); } }
// ---- add ---------------------------------------------------------------
async function add() { const text = Q.value.trim(); if (!(me && me.did)) { showError("log in to add a topic"); return; } if (!text) return; showError(""); RUN.disabled = true; RUN.textContent = "adding…"; try { const r = await fetch("/api/request", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text }), }); const d = await r.json(); if (!r.ok) throw new Error(d.error || `HTTP ${r.status}`); Q.value = BASE; fitQ(); updateAuth(); loadPane(); loadMain(); } catch (e) { showError(`could not add the topic: ${e}`); } finally { RUN.disabled = false; RUN.textContent = "add topic"; } }
RUN.addEventListener("click", add); Q.addEventListener("keydown", e => { if (e.key === "Enter") add(); }); document.getElementById("brand").addEventListener("click", () => { setPane(false); location.hash = "top"; }); window.addEventListener("hashchange", () => { const rkey = decodeURIComponent((location.hash || "").slice(1)); if (rkey && rkey !== "top") { loadTopic(rkey); } else { loadMain(); } loadPane(); }); let scrollT = null; window.addEventListener("scroll", () => { if (scrollT) clearTimeout(scrollT); scrollT = setTimeout(maybeMore, 120); }, { passive: true }); setInterval(loadPane, 3000);
(async function init() { const saved = localStorage.getItem("aligned_me"); if (saved) { try { me = JSON.parse(saved); } catch (e) { me = null; } } // Always ask the server who we are: the member flag (fit/no-fit buttons) // and the handle live there, and a stale cache should not outlive a // session. try { const r = await fetch("/api/me", { headers: { Accept: "application/json" } }); const d = await r.json(); if (d.did) { me = { did: d.did, handle: d.handle || d.did, member: !!d.member }; localStorage.setItem("aligned_me", JSON.stringify(me)); } else { me = null; } } catch (e) { /* stay with the cache */ } updateAuth(); typeLoop(0); const initial = decodeURIComponent((location.hash || "").slice(1)); if (initial && initial !== "top") { loadTopic(initial); } else { loadMain(); } loadPane(); })();</script></body></html>