Roles as a feed, a read page, votes that move the rank, unstar
The Roles tab is news's feed row: the title opens /roles/{uid}, company,
place and age under it, the badges, a one-line excerpt (summary, else the
description's opening), and ▲ ● ▼ ★ on the right, under the text at 640px.
The company affinity control leaves the row. A passed role and a hidden
company's are dimmed and stay. The filter bar is one row: order, search and
a Filters <details> holding the rest, with a judged select and "Show hidden
companies". The list loads 60 and appends on an IntersectionObserver
sentinel; back from a read page restores the filters, rows and scroll.
GET /api/roles takes offset, defaults to 60 and answers {items, total}.
judged= is a WHERE on roles.vote. Under a ranking the served score and the
order are the stored score moved by the vote (x0.5 pass, x1.2 like, capped
at 1), so a vote shows at once without a rescore. POST and DELETE
/api/roles/{uid}/vote set and clear it; pressing the pressed stance clears.
★ saves; pressed again it calls DELETE /api/applications/{id}, which drops
the application while it is still saved and answers 409 after. save_role no
longer writes the placeholder next step.
The read page (role.html, role.js) is news's reader: a bar with back,
▲ ● ▼ ★ and ↗, the company with its affinity control, place, badges, salary,
summary, the text (fetched posting, else description) and the link out.
It offers Fetch the posting for a teaser and Summarise without a summary,
against the /text and /summarise routes B4 adds. The vote and star buttons
are judge.js, shared by the feed and the reader.
Applications: titles open the read page, the Next column is gone, a Saved
column instead, and the lede says what the page is for.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
7d31cca394
commit
09c5dde113
13 files changed
+1216
-192
No files matched your search
+88
-11
@@ -48,6 +48,23 @@ GIVE_UP_AFTER = 3
|
||||
_EXTRACT_WAITING = (f"extracted_at IS NULL AND closed_at IS NULL "
|
||||
f"AND extract_tries < {GIVE_UP_AFTER}")
|
||||
|
||||
#: What a vote may be: 1 like, 0 neither way, -1 pass, None unjudged.
|
||||
VOTES = (-1, 0, 1, None)
|
||||
|
||||
#: The `judged` filter of `Store.roles`, as a `WHERE` on `roles.vote`. A
|
||||
#: neutral vote is judged, and is neither liked nor passed.
|
||||
JUDGED: dict[str, str] = {
|
||||
"liked": "roles.vote = 1",
|
||||
"unjudged": "roles.vote IS NULL",
|
||||
"passed": "roles.vote = -1",
|
||||
}
|
||||
|
||||
#: A ranking's score as `Store.roles` serves and orders it: halved by a pass,
|
||||
#: lifted a fifth by a like, capped at 1. Applied at read time, so a vote
|
||||
#: moves the role at once and the stored score stays what `score` computed.
|
||||
_VOTED_SCORE = ("MIN(1.0, s.score * CASE roles.vote WHEN -1 THEN 0.5 "
|
||||
"WHEN 1 THEN 1.2 ELSE 1 END)")
|
||||
|
||||
_COMPANY_FIELDS = ("name", "domain", "affinity", "status", "careers_url", "notes")
|
||||
_SUBSCRIPTION_FIELDS = ("label", "company", "board", "params", "subscribed", "fetch",
|
||||
"show", "target_id")
|
||||
@@ -267,18 +284,35 @@ class Store:
|
||||
row = self._row("SELECT * FROM roles WHERE uid=?", (uid,))
|
||||
return Role.from_row(row) if row else None
|
||||
|
||||
def set_vote(self, uid: str, value: int | None) -> Role:
|
||||
"""Judge one role: 1 like, 0 neither way, -1 pass, None unjudged again.
|
||||
Stamps `voted_at`, or clears it with the vote. A vote never hides a
|
||||
role; it moves it in a ranking (see `roles`). Raises ValueError for
|
||||
another value and KeyError for an unknown uid."""
|
||||
if isinstance(value, bool) or value not in VOTES:
|
||||
raise ValueError(f"a vote is -1, 0 or 1, not {value!r}")
|
||||
stamp = None if value is None else self.now()
|
||||
if not self._write("UPDATE roles SET vote=?, voted_at=? WHERE uid=?",
|
||||
(value, stamp, uid)):
|
||||
raise KeyError(uid)
|
||||
role = self.role(uid)
|
||||
assert role is not None
|
||||
return role
|
||||
|
||||
def roles(self, limit: int = 100, company: str | None = None,
|
||||
place: str | None = None, open_only: bool = True,
|
||||
q: str | None = None, function: str | None = None,
|
||||
remote: str | None = None, days: int | None = None,
|
||||
hide_muted: bool = False, agent: int | None = None,
|
||||
gated: bool = False) -> list[ScoredRole]:
|
||||
gated: bool = False, judged: str | None = None,
|
||||
offset: int = 0) -> list[ScoredRole]:
|
||||
"""Newest first by `first_seen`. `company` and `place` are
|
||||
case-insensitive substrings of the columns a board wrote — not the
|
||||
key, so a search does not have to know the exact slug a company folds
|
||||
to. `q` is matched word by word against `title`; a role must match
|
||||
every word. `function` and `remote` match a gate column exactly.
|
||||
`days` keeps only roles first seen within that many days of now.
|
||||
`judged` is a key of `JUDGED`: liked, unjudged or passed.
|
||||
|
||||
`hide_muted` excludes a muted company's roles before `limit` is
|
||||
applied, in SQL rather than after the fact: a company that has
|
||||
@@ -290,8 +324,47 @@ class Store:
|
||||
|
||||
`agent` orders by that agent's score instead, highest first, and
|
||||
carries `score` and `gated_reason` on each row. Only roles it has
|
||||
scored are listed, and a gated one only when `gated` is set."""
|
||||
where, params = [], []
|
||||
scored are listed, and a gated one only when `gated` is set. The score
|
||||
is the stored one moved by the role's vote (`_VOTED_SCORE`), so a vote
|
||||
shows in the order at once and needs no rescore.
|
||||
|
||||
`offset` skips that many rows of the same order, for the page that
|
||||
loads the next 60 as it is scrolled; `count_roles` is the total."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, agent=agent, gated=gated,
|
||||
judged=judged)
|
||||
if agent is None:
|
||||
select = "SELECT roles.* "
|
||||
order = "roles.first_seen DESC, roles.uid"
|
||||
else:
|
||||
select = f"SELECT roles.*, {_VOTED_SCORE} AS score, s.gated_reason "
|
||||
order = "score DESC, roles.first_seen DESC, roles.uid"
|
||||
return [ScoredRole.from_row(r) for r in self._rows(
|
||||
f"{select}{sql} ORDER BY {order} LIMIT ? OFFSET ?", [*params, limit, offset])]
|
||||
|
||||
def count_roles(self, company: str | None = None, place: str | None = None,
|
||||
open_only: bool = True, q: str | None = None,
|
||||
function: str | None = None, remote: str | None = None,
|
||||
days: int | None = None, hide_muted: bool = False,
|
||||
agent: int | None = None, gated: bool = False,
|
||||
judged: str | None = None) -> int:
|
||||
"""How many roles `roles` would list with the same filters and no limit."""
|
||||
sql, params = self._roles_from(
|
||||
company=company, place=place, open_only=open_only, q=q, function=function,
|
||||
remote=remote, days=days, hide_muted=hide_muted, agent=agent, gated=gated,
|
||||
judged=judged)
|
||||
row = self._row(f"SELECT COUNT(*) AS n {sql}", params)
|
||||
return int(row["n"]) if row else 0
|
||||
|
||||
def _roles_from(self, *, company: str | None, place: str | None, open_only: bool,
|
||||
q: str | None, function: str | None, remote: str | None,
|
||||
days: int | None, hide_muted: bool, agent: int | None,
|
||||
gated: bool, judged: str | None) -> tuple[str, list[Any]]:
|
||||
"""The `FROM ... WHERE ...` that `roles` and `count_roles` share, with
|
||||
its parameters in order."""
|
||||
where: list[str] = []
|
||||
params: list[Any] = []
|
||||
if company:
|
||||
where.append("company LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(company))
|
||||
@@ -310,6 +383,10 @@ class Store:
|
||||
for word in (q or "").split():
|
||||
where.append("title LIKE ? ESCAPE '\\'")
|
||||
params.append(_like(word))
|
||||
if judged:
|
||||
if judged not in JUDGED:
|
||||
raise ValueError(f"judged is {', '.join(JUDGED)}, not {judged!r}")
|
||||
where.append(JUDGED[judged])
|
||||
if open_only:
|
||||
where.append("closed_at IS NULL")
|
||||
if hide_muted:
|
||||
@@ -317,20 +394,15 @@ class Store:
|
||||
"(SELECT key FROM companies WHERE affinity = -1)")
|
||||
joins: list[Any] = []
|
||||
if agent is None:
|
||||
sql = "SELECT roles.* FROM roles"
|
||||
order = "roles.first_seen DESC, roles.uid"
|
||||
sql = "FROM roles"
|
||||
else:
|
||||
sql = ("SELECT roles.*, s.score, s.gated_reason FROM roles "
|
||||
"JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?")
|
||||
sql = "FROM roles JOIN scores s ON s.uid = roles.uid AND s.agent_id = ?"
|
||||
joins.append(agent)
|
||||
if not gated:
|
||||
where.append("s.gated_reason = ''")
|
||||
order = "s.score DESC, roles.first_seen DESC, roles.uid"
|
||||
if where:
|
||||
sql += " WHERE " + " AND ".join(where)
|
||||
sql += f" ORDER BY {order} LIMIT ?"
|
||||
return [ScoredRole.from_row(r)
|
||||
for r in self._rows(sql, [*joins, *params, limit])]
|
||||
return sql, [*joins, *params]
|
||||
|
||||
def mark_closed(self, source: str, seen_ids: Sequence[str],
|
||||
subscription_id: int) -> int:
|
||||
@@ -781,6 +853,11 @@ class Store:
|
||||
row = self._row("SELECT * FROM applications WHERE id=?", (app_id,))
|
||||
return Application.from_row(row) if row else None
|
||||
|
||||
def delete_application(self, app_id: str) -> bool:
|
||||
"""Drop one application and its events. Whether that is allowed (only
|
||||
while it is still `saved`) is the caller's rule, not the store's."""
|
||||
return self._write("DELETE FROM applications WHERE id=?", (app_id,)) > 0
|
||||
|
||||
def applications(self, status: str | None = None) -> list[Application]:
|
||||
sql, params = "SELECT * FROM applications", []
|
||||
if status:
|
||||
|
||||
Reference in new issue
Block a user