Viewing as leads the Roles rail; settings get a rail, agent cards, one Sources section at a time
A search agent is a persona, and every like or pass belongs to the one being viewed. The rail now opens on Viewing as: a full-width chooser, the name alone with one agent, a note with none, remembered in the URL and localStorage. The vote buttons, the reader's affinity control, the feed, the tag counts and the reader fetch all carry that agent; before, votes sent none and every one landed on the default agent. Best first and Newest first are back as the segmented control under Order, independent of the agent. The rail selects no longer clip descenders: Chrome ignores line-height on a select, so the fixed box is gone in favour of padding and a min-height. Settings render inside a sticky rail (Search agents; Sources with Job boards, Company boards, Runs, Messages; Account), a strip under the header on a phone, so Runs is one click away however long the company list gets. Sources shows one section at a time, chosen by the fragment, so the old redirects still land. Search agents are cards, newest first: name, an On/Off switch with its word, the intent in full, the weights, Edit in place, New agent on top, and a link to Roles as that agent. Switching one on rescores it. replace_scores writes nothing for an agent deleted while score was running, instead of failing the run on the foreign key. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
063771d617
commit
c4f2bcc0c9
20 files changed
+836
-326
No files matched your search
+163
-71
@@ -19,9 +19,25 @@
|
||||
* back always means "out of the reader". The server answers `/roles/{uid}`
|
||||
* with this same page, and `route` is the only thing that reads the path.
|
||||
*
|
||||
* The rail opens on Viewing as: the search agent the feed is seen as. An
|
||||
* agent is a persona ("me as a candidate", "me as a hiring manager watching
|
||||
* the market") with its own scores, votes and hidden companies, so every
|
||||
* request that has an answer per agent names it: the feed, the tag counts,
|
||||
* the role in the reader, the company list, each vote (judge.js's `{agent}`)
|
||||
* and each company affinity. One is always picked while any is enabled: the
|
||||
* one in `?agent=`, else the one this browser viewed last (localStorage),
|
||||
* else the enabled one with the lowest id, which is the server's default too.
|
||||
* Picking another reloads the feed and the counts under the reader, which
|
||||
* stays open and is fetched again for that agent's vote.
|
||||
*
|
||||
* Order is Best first (`order=score`, the agent's score moved by its votes)
|
||||
* or Newest first (`order=newest`), the same two whichever agent is viewed,
|
||||
* and both carry the agent's votes and hidden companies.
|
||||
*
|
||||
* The filters are in the query string, replaced rather than pushed, so a
|
||||
* reload or a link keeps them and the back button is not buried under them.
|
||||
* `?company=` and `?agent=` are how the Companies and Ranking pages link in.
|
||||
* `?company=` and `?agent=` are how the Companies and Search agents pages
|
||||
* link in.
|
||||
*
|
||||
* The list is paged: 60 rows, then 60 more each time the end of the list comes
|
||||
* within 600px of the screen, with the offset the rows already shown. Back to
|
||||
@@ -47,10 +63,12 @@
|
||||
const TEASER = 500;
|
||||
/** How many rows and how far down, for coming back to this page. */
|
||||
const KEPT = "roledesk.roles";
|
||||
/** The agent last viewed as, so the next visit opens on the same persona. */
|
||||
const VIEWING = "roledesk.agent";
|
||||
const number = new Intl.NumberFormat("en");
|
||||
|
||||
// What the list is in the order of. Best first is the first enabled
|
||||
// ranking's score, moved by the role's vote; Newest first is first seen.
|
||||
// What the list is in the order of. Best first is the viewing agent's
|
||||
// score, moved by its votes; Newest first is first seen.
|
||||
const SORTS = { score: "Best first", time: "Newest first" };
|
||||
|
||||
// The named windows over `days`, which counts back from now.
|
||||
@@ -76,7 +94,8 @@
|
||||
q: "",
|
||||
railOpen: !narrow.matches,
|
||||
railAutoShut: false, // the reader folded the rail, so closing unfolds it
|
||||
agents: [], // the enabled rankings, from /api/agents
|
||||
agents: [], // the enabled search agents, from /api/agents, by id
|
||||
agentsLoaded: false, // so "no agent" is not said before the answer
|
||||
tags: [], // [{tag, count, unread}] from /api/filters
|
||||
items: [], // the rows on screen, in order
|
||||
total: 0, // how many roles the filters match in all
|
||||
@@ -102,15 +121,10 @@
|
||||
|
||||
// ------------------------------------------------------------ the order
|
||||
|
||||
/** The ranking the list is ordered by, or null for Newest first. Best first
|
||||
with no ranking enabled is Newest first; an `agent` from the URL that is
|
||||
not an enabled ranking falls back to the first one. */
|
||||
function rankedBy() {
|
||||
if (state.filter.sort !== "score" || !state.agents.length) return null;
|
||||
const chosen = state.agents.find((a) => a.id === state.filter.agent);
|
||||
return (chosen || state.agents[0]).id;
|
||||
}
|
||||
const sortShown = () => (rankedBy() === null ? "time" : "score");
|
||||
/** The order the list is in. Best first needs an agent to score by: with
|
||||
none enabled the server answers newest first, and so does this. */
|
||||
const sortShown = () =>
|
||||
(state.filter.sort === "score" && state.filter.agent !== null ? "score" : "time");
|
||||
|
||||
function feedParams() {
|
||||
const f = state.filter;
|
||||
@@ -123,10 +137,10 @@
|
||||
if (f.showMuted) p.set("show_muted", "true");
|
||||
if (!f.showRead) p.set("include_read", "false");
|
||||
f.tags.forEach((t) => p.append("tags", t));
|
||||
const agent = rankedBy();
|
||||
if (agent !== null) {
|
||||
p.set("agent", String(agent));
|
||||
if (f.gated) p.set("gated", "true");
|
||||
if (f.agent !== null) {
|
||||
p.set("agent", String(f.agent));
|
||||
p.set("order", sortShown() === "score" ? "score" : "newest");
|
||||
if (f.gated && sortShown() === "score") p.set("gated", "true");
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -149,10 +163,8 @@
|
||||
f.gated = q.get("gated") === "true" || q.get("gated") === "1";
|
||||
f.tags = new Set(q.getAll("tags"));
|
||||
if (q.get("sort") === "time") f.sort = "time";
|
||||
if (q.get("agent")) {
|
||||
f.sort = "score";
|
||||
f.agent = Number(q.get("agent"));
|
||||
}
|
||||
// Checked against the enabled agents once they are in (`chooseAgent`).
|
||||
if (q.get("agent")) f.agent = Number(q.get("agent"));
|
||||
if (f.company || f.place || f.function || f.remote || f.judged || f.showMuted || f.gated) {
|
||||
$("#f-more").open = true;
|
||||
}
|
||||
@@ -162,12 +174,8 @@
|
||||
adding one: a filter is a question, not a place. */
|
||||
function writeUrl() {
|
||||
const p = feedParams();
|
||||
p.delete("agent");
|
||||
p.delete("gated");
|
||||
const f = state.filter;
|
||||
if (f.sort === "time") p.set("sort", "time");
|
||||
else if (f.agent !== null) p.set("agent", String(f.agent));
|
||||
if (f.gated && f.sort === "score") p.set("gated", "true");
|
||||
p.delete("order");
|
||||
if (state.filter.sort === "time") p.set("sort", "time");
|
||||
const query = p.toString();
|
||||
const url = location.pathname + (query ? `?${query}` : "");
|
||||
if (url !== location.pathname + location.search) history.replaceState(history.state, "", url);
|
||||
@@ -226,15 +234,58 @@
|
||||
}
|
||||
|
||||
async function loadAgents() {
|
||||
state.agents = (await api("/api/agents")).filter((a) => a.enabled);
|
||||
state.agents = (await api("/api/agents")).filter((a) => a.enabled)
|
||||
.sort((a, b) => a.id - b.id);
|
||||
state.agentsLoaded = true;
|
||||
}
|
||||
|
||||
// The tag counts. Asked with `show_muted` only, the one filter the route
|
||||
// takes, so picking a tag does not renumber the others.
|
||||
function storedAgent() {
|
||||
try { return Number(localStorage.getItem(VIEWING)) || null; } catch (err) { return null; }
|
||||
}
|
||||
|
||||
function rememberAgent(id) {
|
||||
try {
|
||||
if (id === null) localStorage.removeItem(VIEWING);
|
||||
else localStorage.setItem(VIEWING, String(id));
|
||||
} catch (err) { /* private mode: the next visit opens on the default */ }
|
||||
}
|
||||
|
||||
/** The agent to view as, among the enabled ones: the address's, else the
|
||||
one this browser viewed last, else the lowest id. An agent disabled or
|
||||
deleted since is passed over, not kept as a question nobody answers. */
|
||||
function chooseAgent() {
|
||||
const ids = state.agents.map((a) => a.id);
|
||||
const wanted = [state.filter.agent, storedAgent()].find((id) => ids.includes(id));
|
||||
state.filter.agent = wanted ?? (ids.length ? ids[0] : null);
|
||||
rememberAgent(state.filter.agent);
|
||||
writeUrl();
|
||||
}
|
||||
|
||||
/* Another persona over the same roles: its scores, votes and hidden
|
||||
companies, so the companies come first (they dim rows), then the feed
|
||||
and the tag counts. The reader stays, fetched again for this agent's
|
||||
vote; a filter closes it, an agent does not, since the role is still in
|
||||
question, only the eyes on it changed. */
|
||||
async function setAgent(id) {
|
||||
if (id === state.filter.agent) return;
|
||||
state.filter.agent = id;
|
||||
rememberAgent(id);
|
||||
writeUrl();
|
||||
renderRail();
|
||||
renderActive();
|
||||
await loadCompanies(id).catch(() => {});
|
||||
reload();
|
||||
loadFilters().catch(() => {});
|
||||
if (state.readingUid) refreshReader(state.readingUid);
|
||||
}
|
||||
|
||||
// The tag counts. Asked with `show_muted` and the agent only, the filters
|
||||
// the route takes, so picking a tag does not renumber the others.
|
||||
let filtersRequest = 0;
|
||||
async function loadFilters() {
|
||||
const params = new URLSearchParams();
|
||||
if (state.filter.showMuted) params.set("show_muted", "true");
|
||||
if (state.filter.agent !== null) params.set("agent", String(state.filter.agent));
|
||||
const request = ++filtersRequest;
|
||||
const data = await api(`/api/filters?${params}`);
|
||||
if (request !== filtersRequest) return;
|
||||
@@ -257,8 +308,9 @@
|
||||
renderActive();
|
||||
}
|
||||
|
||||
// Who is viewing and in which order are not filters, so they stay.
|
||||
function clearFilters() {
|
||||
const kept = { agent: state.filter.agent };
|
||||
const kept = { agent: state.filter.agent, sort: state.filter.sort };
|
||||
state.filter = Object.assign(blankFilter(), kept);
|
||||
setFilter({}, { counts: true });
|
||||
}
|
||||
@@ -297,33 +349,20 @@
|
||||
const f = state.filter;
|
||||
$("#show-read").setAttribute("aria-pressed", String(f.showRead));
|
||||
|
||||
// The order. One ranking, or none, is the segmented control; more than one
|
||||
// is a select naming each, so none is lost.
|
||||
const ranked = rankedBy();
|
||||
const many = state.agents.length > 1;
|
||||
$("#sort").hidden = many;
|
||||
$("#agent").hidden = !many;
|
||||
if (many) {
|
||||
const select = $("#agent");
|
||||
select.replaceChildren(...state.agents.map((a) => new Option(a.name, String(a.id))),
|
||||
new Option(SORTS.time, ""));
|
||||
select.value = ranked === null ? "" : String(ranked);
|
||||
} else {
|
||||
const none = !state.agents.length;
|
||||
$("#sort").innerHTML = Object.entries(SORTS).map(([key, label]) => {
|
||||
const off = key === "score" && none;
|
||||
return `<button type="button" data-sort="${key}" aria-pressed="${sortShown() === key}"
|
||||
${off ? `aria-disabled="true" title="No ranking is enabled. Settings, Ranking sets one up."`
|
||||
: ""}>${label}</button>`;
|
||||
}).join("");
|
||||
$("#sort").querySelectorAll("[data-sort]").forEach((b) => {
|
||||
b.onclick = () => {
|
||||
if (b.getAttribute("aria-disabled") === "true") return;
|
||||
setFilter({ sort: b.dataset.sort });
|
||||
};
|
||||
});
|
||||
}
|
||||
$("#show-gated").hidden = ranked === null;
|
||||
renderAgent();
|
||||
|
||||
// The order, the same two whatever is viewed. Best first needs an agent
|
||||
// to score by, so with none it is greyed and says why.
|
||||
const none = state.agentsLoaded && !state.agents.length;
|
||||
$("#sort").querySelectorAll("[data-sort]").forEach((b) => {
|
||||
b.setAttribute("aria-pressed", String(sortShown() === b.dataset.sort));
|
||||
const off = b.dataset.sort === "score" && none;
|
||||
if (off) b.setAttribute("aria-disabled", "true");
|
||||
else b.removeAttribute("aria-disabled");
|
||||
b.title = off ? "No search agent is enabled, so nothing is scored." : "";
|
||||
});
|
||||
const ranked = sortShown() === "score";
|
||||
$("#show-gated").hidden = !ranked;
|
||||
|
||||
$("#period").value = f.period;
|
||||
|
||||
@@ -354,13 +393,41 @@
|
||||
setValue("f-show-muted", f.showMuted);
|
||||
setValue("f-gated", f.gated);
|
||||
const more = [f.company.trim(), f.place.trim(), f.function, f.remote, f.judged,
|
||||
f.showMuted, ranked !== null && f.gated].filter(Boolean).length;
|
||||
f.showMuted, ranked && f.gated].filter(Boolean).length;
|
||||
$("#f-active").textContent = more ? ` · ${more}` : "";
|
||||
|
||||
document.body.dataset.rail = state.railOpen ? "open" : "shut";
|
||||
$("#rail-toggle").setAttribute("aria-expanded", String(state.railOpen));
|
||||
}
|
||||
|
||||
/* Viewing as: a select with two or more agents, the name with one, and
|
||||
with none a sentence and the way to make one. Nothing until the agents
|
||||
are in, so a page with agents never says it has none. */
|
||||
function renderAgent() {
|
||||
const agents = state.agents;
|
||||
const select = $("#agent");
|
||||
select.hidden = agents.length < 2;
|
||||
$("#agent-one").hidden = agents.length !== 1;
|
||||
$("#agent-none").hidden = !state.agentsLoaded || agents.length > 0;
|
||||
if (agents.length > 1) {
|
||||
// Rebuilt only when the agents changed, since the rail is drawn again on
|
||||
// every filter and a rebuild shuts a select that is open.
|
||||
const key = agents.map((a) => `${a.id}:${a.name}`).join("\n");
|
||||
if (select.dataset.key !== key) {
|
||||
select.dataset.key = key;
|
||||
select.replaceChildren(...agents.map((a) => new Option(a.name, String(a.id))));
|
||||
}
|
||||
select.value = String(state.filter.agent);
|
||||
// A long name is cut at the rail's edge; the whole of it is a hover away.
|
||||
select.title = select.selectedOptions[0]?.text || "";
|
||||
} else if (agents.length === 1) {
|
||||
$("#agent-one").textContent = agents[0].name;
|
||||
} else if (state.agentsLoaded) {
|
||||
$("#agent-none").innerHTML = `No search agent is enabled, so nothing is ranked.
|
||||
<a href="/settings/agents">Search agents</a> sets one up.`;
|
||||
}
|
||||
}
|
||||
|
||||
/* With the rail shut, which is every narrow screen, the burger is the only
|
||||
thing left that can say a filter is on, so it says how many, in words: a
|
||||
number in a circle reads as "new things" on the one control that means
|
||||
@@ -368,7 +435,7 @@
|
||||
function renderActive() {
|
||||
const f = state.filter;
|
||||
const on = [!f.showRead, f.period !== "all", f.company.trim(), f.place.trim(),
|
||||
f.function, f.remote, f.judged, f.showMuted, rankedBy() !== null && f.gated]
|
||||
f.function, f.remote, f.judged, f.showMuted, sortShown() === "score" && f.gated]
|
||||
.filter(Boolean).length + f.tags.size;
|
||||
const count = on === 1 ? "1 filter" : `${on} filters`;
|
||||
$(".rail-toggle-label").textContent = on ? count : "Menu";
|
||||
@@ -451,7 +518,8 @@
|
||||
${text ? `<p class="excerpt">${esc(text)}</p>` : ""}
|
||||
</div>
|
||||
<div class="actions judge"></div>`;
|
||||
el.querySelector(".actions").appendChild(judgeButtons(role, () => paintRow(el, role)));
|
||||
el.querySelector(".actions").appendChild(
|
||||
judgeButtons(role, () => paintRow(el, role), { agent: state.filter.agent }));
|
||||
// Plain click reads it here; a modified or middle click still gets the
|
||||
// real link, which is this same page with the role open.
|
||||
el.querySelector(".headline").onclick = (e) => {
|
||||
@@ -570,8 +638,19 @@
|
||||
renderFeed();
|
||||
rowAt(state.selected)?.scrollIntoView({ block: "nearest" });
|
||||
markRead(uid);
|
||||
await refreshReader(uid);
|
||||
}
|
||||
|
||||
/** One role as the viewing agent sees it, which is what its vote is. */
|
||||
function roleUrl(uid) {
|
||||
const agent = state.filter.agent;
|
||||
return `/api/roles/${encodeURIComponent(uid)}${agent === null ? "" : `?agent=${agent}`}`;
|
||||
}
|
||||
|
||||
// The fetch behind the reader: on opening, and again when the agent changes.
|
||||
async function refreshReader(uid) {
|
||||
try {
|
||||
const role = await api(`/api/roles/${encodeURIComponent(uid)}`);
|
||||
const role = await api(roleUrl(uid));
|
||||
if (state.readingUid !== uid) return; // moved on before this landed
|
||||
state.reading = role;
|
||||
renderReader();
|
||||
@@ -704,7 +783,9 @@
|
||||
state.selected >= state.items.length - 1 ? "disabled" : ""}>Next →</button>
|
||||
</div>`;
|
||||
|
||||
if (r.uid) el.querySelector(".judge").appendChild(judgeButtons(r));
|
||||
if (r.uid) {
|
||||
el.querySelector(".judge").appendChild(judgeButtons(r, null, { agent: state.filter.agent }));
|
||||
}
|
||||
renderAffinity(el.querySelector(".affinity-slot"), r);
|
||||
el.querySelector(".close").onclick = () => closeReader();
|
||||
el.querySelector(".step-prev").onclick = () => move(-1);
|
||||
@@ -727,7 +808,7 @@
|
||||
slot.replaceChildren(affinityControl(r.company_key, company.affinity, () => {
|
||||
renderAffinity(slot, r);
|
||||
renderFeed();
|
||||
}));
|
||||
}, state.filter.agent));
|
||||
}
|
||||
|
||||
/* The answer, into the role on screen and into its row, whose excerpt is
|
||||
@@ -783,7 +864,7 @@
|
||||
await new Promise((resolve) => setTimeout(resolve, 4000));
|
||||
if (state.summarising !== uid) return;
|
||||
let fresh;
|
||||
try { fresh = await api(`/api/roles/${encodeURIComponent(uid)}`); } catch (err) { break; }
|
||||
try { fresh = await api(roleUrl(uid)); } catch (err) { break; }
|
||||
if (fresh.summary) { state.summarising = null; merge(fresh); return; }
|
||||
}
|
||||
if (state.summarising === uid) {
|
||||
@@ -931,9 +1012,14 @@
|
||||
$("#rail-toggle").addEventListener("click", toggleRail);
|
||||
$("#scrim").addEventListener("click", toggleRail);
|
||||
$("#show-read").addEventListener("click", () => setFilter({ showRead: !state.filter.showRead }));
|
||||
$("#agent").addEventListener("change", (e) => {
|
||||
const id = e.target.value;
|
||||
setFilter(id ? { sort: "score", agent: Number(id) } : { sort: "time" });
|
||||
$("#agent").addEventListener("change", (e) => setAgent(Number(e.target.value)));
|
||||
$("#sort").innerHTML = Object.entries(SORTS).map(([key, label]) =>
|
||||
`<button type="button" data-sort="${key}">${label}</button>`).join("");
|
||||
$("#sort").querySelectorAll("[data-sort]").forEach((b) => {
|
||||
b.onclick = () => {
|
||||
if (b.getAttribute("aria-disabled") === "true") return;
|
||||
setFilter({ sort: b.dataset.sort });
|
||||
};
|
||||
});
|
||||
$("#period").innerHTML = Object.entries(PERIODS).map(([key, p]) =>
|
||||
`<option value="${key}">${esc(p.label)}</option>`).join("");
|
||||
@@ -973,11 +1059,14 @@
|
||||
// Kept on the way out, whichever way that is, so back finds it.
|
||||
window.addEventListener("pagehide", keep);
|
||||
// Back from another tab without a reload (the back/forward cache): the
|
||||
// rows are the ones left, but a vote or a star may have changed there.
|
||||
// rows are the ones left, but a vote, a star or an agent may have changed
|
||||
// there.
|
||||
window.addEventListener("pageshow", async (e) => {
|
||||
if (!e.persisted) return;
|
||||
const y = window.scrollY;
|
||||
await Promise.all([loadTracked(), loadCompanies()]).catch(() => {});
|
||||
await loadAgents().then(chooseAgent).catch(() => {});
|
||||
renderRail();
|
||||
await Promise.all([loadTracked(), loadCompanies(state.filter.agent)]).catch(() => {});
|
||||
await loadFeed({ keep: state.items.length });
|
||||
if (state.readingUid) renderReader();
|
||||
window.scrollTo(0, y);
|
||||
@@ -991,8 +1080,11 @@
|
||||
wire();
|
||||
renderRail();
|
||||
renderActive();
|
||||
// The agent first: the companies, the feed and the counts are its.
|
||||
try {
|
||||
await Promise.all([loadCompanies(), loadTracked(), loadAgents()]);
|
||||
await Promise.all([loadTracked(), loadAgents()]);
|
||||
chooseAgent();
|
||||
await loadCompanies(state.filter.agent);
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user