Roles is newsdesk's feed: rail, feed and reader, with read state and tags

The Roles tab takes newsdesk's shell, ported from its index.html and
app.css rather than rewritten: a filter rail (Show read, Best first or
Newest first, first seen, tag chips with counts, the old filters behind a
disclosure), the feed in newsdesk's row layout (score gutter, title,
company, place, badges, age, tags, the summary as excerpt, judge buttons)
and the reader as a third column that replaces the list on a phone. The
router pushes /roles/{uid}, which the server also renders with the reader
open, so the separate read page and role.js go. j/k, u/n/d, S, Enter,
Escape, o, /, f and c work as in newsdesk. The phone rules come with their
comments.

Two things the row lacked: roles.read_at, stamped when the reader opens a
role or a vote is cast, behind include_read on /api/roles; and role_tags,
written by summarise alongside the summary and served with counts by
/api/filters, filtered in SQL before LIMIT. Migration 5.

PyCharm run configurations in .run/ for serve, pull, seed and pytest.
core.autocrlf=input is set locally so a Windows-side checkout commits LF.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 12:37:45 +02:00
1 parent 515d2250fc
commit a9290a6926
23 files changed
+2252 -715

No files matched your search

+29 -1
View File
@@ -1,4 +1,4 @@
/* ▲ ● ▼ ★ for one role: the feed row and the read page share them.
/* ▲ ● ▼ ★ for one role: the feed row and the reader bar share them.
*
* news's `voteButtons`, `starButton` and `vote()`, adapted. Three stances and
* no stance is four states from three buttons; pressing the stance a role
@@ -14,6 +14,13 @@
* Both are optimistic: the button changes before the request and changes back
* if it fails. `api()` has already toasted the failure by then.
*
* One role can have two sets of these on screen at once, its feed row's and
* the reader bar's, each bound to its own copy of the role. A change in one is
* echoed to every other set for the same uid (`echo`), which copies the vote
* and the read mark across and repaints it, so the row never shows a stance
* the reader has taken back. A vote marks the role read on the server, and the
* answer's `read_at` is copied onto the role with the vote.
*
* await loadTracked();
* container.append(judgeButtons(role, (role) => row.classList.toggle(...)));
*/
@@ -32,6 +39,22 @@
return tracked;
}
/** Every set of buttons made, so a change in one repaints the others for
the same role. A set whose buttons have left the document is dropped the
next time a change is echoed. */
const groups = new Set();
function echo(from) {
for (const group of groups) {
if (!group.star.isConnected) { groups.delete(group); continue; }
if (group.role === from || group.role.uid !== from.uid) continue;
group.role.vote = from.vote;
group.role.voted_at = from.voted_at;
if (from.read_at !== undefined) group.role.read_at = from.read_at;
group.paint();
}
}
const STANCES = [
{ value: 1, cls: "up", glyph: "▲", said: "Like" },
{ value: 0, cls: "mid", glyph: "●", said: "Neither way" },
@@ -83,6 +106,7 @@
const clearing = before === value;
role.vote = clearing ? null : value;
paint();
echo(role);
const path = `/api/roles/${encodeURIComponent(role.uid)}/vote`;
try {
const updated = clearing
@@ -90,10 +114,12 @@
: await api(path, { method: "POST", body: { value } });
role.vote = updated.vote;
role.voted_at = updated.voted_at;
if (updated.read_at !== undefined) role.read_at = updated.read_at;
} catch (err) {
role.vote = before;
}
paint();
echo(role);
}
// One request at a time: a second tap while the first is in flight would
@@ -122,8 +148,10 @@
star.disabled = false;
}
paint();
echo(role);
}
groups.add({ role, star, paint });
paint();
return fragment;
}