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

+51 -6
View File
@@ -62,6 +62,24 @@ def unvote_role(uid: str, store: StoreDep) -> Role:
raise HTTPException(404, f"no such role: {uid}") from None
@router.post("/roles/{uid}/read")
def read_role(uid: str, store: StoreDep) -> Role:
"""Mark a role read. Never hides it; a vote does this too, see `vote_role`."""
try:
return store.set_read(uid, True)
except KeyError:
raise HTTPException(404, f"no such role: {uid}") from None
@router.delete("/roles/{uid}/read")
def unread_role(uid: str, store: StoreDep) -> Role:
"""Unread again: what pressing the state a role already has does."""
try:
return store.set_read(uid, False)
except KeyError:
raise HTTPException(404, f"no such role: {uid}") from None
class RolesPage(BaseModel):
"""One page of roles, and how many the same filters match in all."""
@@ -79,6 +97,9 @@ def list_roles(
remote: str = "",
days: int | None = None,
show_muted: bool = False,
include_read: bool = True,
tags: list[str] = Query(default=[]),
tag_mode: Literal["any", "all"] = "any",
agent: int | None = None,
gated: bool = False,
judged: Literal["", "liked", "unjudged", "passed"] = "",
@@ -88,21 +109,45 @@ def list_roles(
"""Open roles, newest first, `limit` of them from `offset`, with the
total. See `Store.roles` for what each filter does.
A muted company's roles are left out unless `show_muted` is set. With
`agent`, ordered by that agent's score moved by the role's vote, and
carrying `score` and `gated_reason`; a gated role only with `gated=1`.
`judged` keeps the liked, the unjudged or the passed."""
A muted company's roles are left out unless `show_muted` is set.
`include_read` set false hides a role already marked read. `tags` is
`?tags=a&tags=b`, kept to a role with any of them or, with
`tag_mode=all`, every one. With `agent`, ordered by that agent's score
moved by the role's vote, and carrying `score` and `gated_reason`; a
gated role only with `gated=1`. `judged` keeps the liked, the unjudged
or the passed."""
if agent is not None and store.agent(agent) is None:
raise HTTPException(404, f"no such agent: {agent}")
filters: dict[str, Any] = {
"q": q or None, "company": company or None, "place": place or None,
"function": function or None, "remote": remote or None, "days": days,
"hide_muted": not show_muted, "agent": agent, "gated": gated,
"judged": judged or None}
"hide_muted": not show_muted, "include_read": include_read, "tags": tags,
"tag_mode": tag_mode, "agent": agent, "gated": gated, "judged": judged or None}
return RolesPage(items=store.roles(limit=limit, offset=offset, **filters),
total=store.count_roles(**filters))
class TagCount(BaseModel):
"""One tag as the filter row offers it: how many open roles carry it and
how many of those are unread."""
tag: str
count: int
unread: int
class FiltersOut(BaseModel):
tags: list[TagCount]
@router.get("/filters")
def list_filters(store: StoreDep, show_muted: bool = False) -> FiltersOut:
"""The tag vocabulary for the feed's filter row, most-used first. A muted
company's roles are left out unless `show_muted`, matching `/api/roles`."""
return FiltersOut(tags=[TagCount(tag=tag, count=count, unread=unread)
for tag, count, unread in store.tag_counts(show_muted)])
# ------------------------------------------------- roles: text and summary
#: What the read page toasts when a posting page gave nothing readable, by