Make Company and Place chip inputs, add Seniority levels and Pay counts to the rail, and keep every filter on a company click

Company and Place are chipInputs on the suggest routes, their chips sent as company_keys and places and read back from the address, place tokens named through /api/places/labels. The old ?company= and ?place= show as a plain chip to take off. Seniority is a row of level chips with "and roles with no level", Pay keeps its select with "and roles that state no pay", each with its count from /api/roles/facets, asked after every reload. Feed rows show the seniority badge. More filters opens by default beside the feed and stays shut on a phone.

A company's name now links to the list on screen with that company as its one chip. The strip's sentence says what ★ does, or did. setAffinity passes the route's answer to onChange, so the strip waits on its score_job. The rail's tag chips get their pill border back, which the quiet rail button rule had taken.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-29 22:29:23 +02:00
1 parent fd89381caa
commit ae7c0eeb0e
4 files changed
+359 -77

No files matched your search

+20 -3
View File
@@ -531,13 +531,18 @@ body[data-reader="open"][data-rail="shut"] .shell {
/* Tags are chips, not rows: they're multi-select, and seeing them wrap into a /* Tags are chips, not rows: they're multi-select, and seeing them wrap into a
block makes the "pick two" affordance obvious. */ block makes the "pick two" affordance obvious. */
#tags { display: flex; flex-wrap: wrap; gap: .25rem; padding: 0 .3rem; } #tags { display: flex; flex-wrap: wrap; gap: .25rem; padding: 0 .3rem; }
.tag, #rail .tag { /* `button...:not(.linky)` to outweigh the rail's quiet button above, which
would square the chips and take their border. */
.tag, #rail button.tag:not(.linky) {
font: inherit; cursor: pointer; font: inherit; cursor: pointer;
color: var(--dim); background: none; color: var(--dim); background: none;
border: 1px solid var(--line); border-radius: 999px; border: 1px solid var(--line); border-radius: 999px;
padding: .14rem .6rem; font-size: .82rem; padding: .14rem .6rem; font-size: .82rem;
} }
.tag[aria-pressed="true"], #rail .tag[aria-pressed="true"] { @media (hover: hover) {
#rail button.tag:not(.linky):hover { color: var(--fg); background: var(--panel); }
}
.tag[aria-pressed="true"], #rail button.tag[aria-pressed="true"]:not(.linky) {
color: var(--panel); background: var(--accent); border-color: var(--accent); color: var(--panel); background: var(--accent); border-color: var(--accent);
} }
#rail .tag[aria-pressed="true"] .count { color: var(--accent-weak); } #rail .tag[aria-pressed="true"] .count { color: var(--accent-weak); }
@@ -639,6 +644,18 @@ kbd {
.rail-fields { display: flex; flex-direction: column; gap: .45rem; padding-top: .6rem; } .rail-fields { display: flex; flex-direction: column; gap: .45rem; padding-top: .6rem; }
.rail-fields input[type="text"], .rail-fields select { width: auto; } .rail-fields input[type="text"], .rail-fields select { width: auto; }
.rail-fields .check { padding: 0 .3rem; white-space: normal; } .rail-fields .check { padding: 0 .3rem; white-space: normal; }
/* A filter and what widens it: Seniority's heading, its levels and "no
level"; Pay's select and "no pay". Closer together than the fields. */
.rail-facet { display: flex; flex-direction: column; gap: .3rem; }
.rail-fields .rail-field { margin: .25rem .3rem 0; }
.rail-facet .check { font-size: .84rem; }
/* The levels are the tags' chips, and wrap as they do. */
#f-seniority:not(:empty) { display: flex; flex-wrap: wrap; gap: .25rem; padding: 0 .3rem; }
/* `?company=` and `?place=` from another page's link: a plain chip under
its field, which takes it off. */
.rail-legacy { padding: 0 .3rem; }
.rail-legacy .tag { max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.rail-legacy .chip-x { margin-left: .35rem; color: var(--faint); }
/* -- the feed -- */ /* -- the feed -- */
@@ -1030,7 +1047,7 @@ table.applications td[data-label="Saved"] { white-space: nowrap; color: var(--di
#rail-toggle { min-height: 2.75rem; } #rail-toggle { min-height: 2.75rem; }
.actions button { padding: .5rem .7rem; font-size: 1.15rem; } .actions button { padding: .5rem .7rem; font-size: 1.15rem; }
#rail .rail-row { align-items: center; min-height: 2.75rem; } #rail .rail-row { align-items: center; min-height: 2.75rem; }
#rail .tag { padding: .45rem .8rem; } #rail button.tag:not(.linky) { padding: .45rem .8rem; }
#rail .seg button { min-height: 2.75rem; } #rail .seg button { min-height: 2.75rem; }
.rail-select, .rail-fields input[type="text"], .rail-fields select, .rail-select, .rail-fields input[type="text"], .rail-fields select,
#rail select.agent-pick { min-height: 2.75rem; } #rail select.agent-pick { min-height: 2.75rem; }
+4 -2
View File
@@ -143,7 +143,9 @@
/* `onChange` runs after the server accepted the change, so each page /* `onChange` runs after the server accepted the change, so each page
decides what a change means for it: the role list refetches, since a decides what a change means for it: the role list refetches, since a
hidden company's roles come out of it, and the company list redraws. */ hidden company's roles come out of it, and the company list redraws.
It is given the route's answer, the company with `score_job`, the id
of the `score` that carries the change, for a page that waits on it. */
function affinityControl(companyKey, current, onChange, agent) { function affinityControl(companyKey, current, onChange, agent) {
const span = document.createElement("span"); const span = document.createElement("span");
span.className = "affinity"; span.className = "affinity";
@@ -178,7 +180,7 @@
} }
const company = companies.get(companyKey); const company = companies.get(companyKey);
if (company) company.affinity = updated.affinity; if (company) company.affinity = updated.affinity;
if (onChange) await onChange(); if (onChange) await onChange(updated);
} }
Object.assign(window, { Object.assign(window, {
+300 -64
View File
@@ -37,9 +37,10 @@
* *
* The filters are in the query string, so a reload or a link keeps them, and * The filters are in the query string, so a reload or a link keeps them, and
* each one set is a history entry, so back takes it off again: a tag, the * each one set is a history entry, so back takes it off again: a tag, the
* period, Show read, a select, a checkbox, Clear, and a company. Text is the * period, Show read, a select, a checkbox, a seniority level, a company or
* exception: the search box and the typed fields replace the entry, or back * place chip picked or removed, Clear, and a company's name. Text is the
* would step through a search a letter at a time. Who is viewing and the * exception: the search box replaces the entry, or back would step through a
* search a letter at a time. Who is viewing and the
* order are not filters and replace too; back and forward leave both as * order are not filters and replace too; back and forward leave both as
* they are and write them into the entry they land on. `popstate` reads the * they are and write them into the entry they land on. `popstate` reads the
* address into the filter and reloads the feed, pushing nothing. * address into the filter and reloads the feed, pushing nothing.
@@ -57,12 +58,20 @@
* reads as the link it is. Nothing to change (Clear with nothing set) just * reads as the link it is. Nothing to change (Clear with nothing set) just
* closes the reader, as Escape would. * closes the reader, as Escape would.
* *
* A company's name, in a row and in the reader, is a link to that company's * A company's name, in a row and in the reader, is a link to the list on
* roles (`?company_keys=`), keeping the agent and the order; a plain click * screen with that company as its one company chip (`?company_keys=`); a
* filters in place and pushes. With one company filtered a strip over the * plain click filters in place and pushes. With one company filtered a strip
* feed names it, counts its roles, links its careers page and carries its * over the feed names it, counts its roles, links its careers page and
* ★ ▲ ⊘ for the viewing agent. `?company=`, `?company_keys=` and `?agent=` * carries its ★ ▲ ⊘ for the viewing agent. `?company=`, `?company_keys=` and
* are how the Companies and Search agents pages link in. * `?agent=` are how the Companies and Search agents pages link in.
*
* Company and Place in the rail are chip inputs (chips.js) on the suggest
* routes: a chip is a company key or a place token (`country:DK`,
* `region:skane`), several joined by OR. `?company=` and `?place=`, the
* substrings of the links from other pages, still filter and show as a chip
* of their own to take off; nothing in the rail types a new one. Seniority
* and Pay carry the counts of `/api/roles/facets`, asked after each reload
* with the feed's own parameters, so each says what a click would add.
* *
* The list is paged: 60 rows, then 60 more each time the end of the list comes * 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 * within 600px of the screen, with the offset the rows already shown. Back to
@@ -73,7 +82,7 @@
"use strict"; "use strict";
const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, judgeButtons, const { api, esc, debounce, safeUrl, companies, loadCompanies, affinityControl, judgeButtons,
loadTracked } = window; loadTracked, chipInput } = window;
const $ = (sel, root = document) => root.querySelector(sel); const $ = (sel, root = document) => root.querySelector(sel);
// Below this the rail is over the feed rather than beside it, and the reader // Below this the rail is over the feed rather than beside it, and the reader
@@ -104,16 +113,37 @@
month: { label: "This month", days: 30 }, month: { label: "This month", days: 30 },
}; };
// The place suggestion's kind, as its hint says it: a `place:` token is a
// town (`places.suggest`).
const PLACE_KINDS = { country: "country", region: "region", place: "town" };
// Everything `clearFilters` has to put back, in one place, so a new filter // Everything `clearFilters` has to put back, in one place, so a new filter
// added here cannot be forgotten there. // added here cannot be forgotten there. `company` and `place` are the
// substrings of links from other pages; `companyKeys` and `places` are the
// rail's chips. `seniorityUnknown` and `payUnknown` are the "and roles
// with no level / no pay" boxes, asked only while a level or a pay option
// is picked.
function blankFilter() { function blankFilter() {
return { return {
sort: "score", agent: null, period: "all", tags: new Set(), showRead: true, sort: "score", agent: null, period: "all", tags: new Set(), showRead: true,
company: "", place: "", function: "", remote: "", judged: "", pay: "", company: "", place: "", function: "", remote: "", judged: "", pay: "",
showMuted: false, gated: false, companyKeys: [], showMuted: false, gated: false, companyKeys: [], places: [],
seniority: [], seniorityUnknown: true, payUnknown: false,
}; };
} }
/** How many filters are on, for the burger; `more` counts only the ones
under "More filters", for its summary. A chip or a level is one each,
as a tag is; the "no level" and "no pay" boxes widen a filter already
counted. */
function filtersOn(f = state.filter, { more = false } = {}) {
const folded = [f.company.trim(), f.place.trim(), f.function, f.remote, f.pay, f.judged,
f.showMuted, sortShown() === "score" && f.gated].filter(Boolean).length
+ f.companyKeys.length + f.places.length + f.seniority.length;
if (more) return folded;
return folded + [!f.showRead, f.period !== "all"].filter(Boolean).length + f.tags.size;
}
const state = { const state = {
filter: blankFilter(), filter: blankFilter(),
q: "", q: "",
@@ -132,8 +162,18 @@
summarising: null, // the uid whose summary is being waited for summarising: null, // the uid whose summary is being waited for
listY: 0, // where the page was scrolled when the reader replaced the feed listY: 0, // where the page was scrolled when the reader replaced the feed
feedError: false, // the feed's own fetch failed; the empty state offers a retry feedError: false, // the feed's own fetch failed; the empty state offers a retry
facets: null, // {seniority, pay} counts from /api/roles/facets for this filter
}; };
// The chips' text, by company key and by place token: what a pick said,
// or what the server named a token read from the address. Kept for the
// page's life, so back to an earlier filter finds its chips' names.
const companyNames = new Map();
const placeLabels = new Map();
// The rail's two chip inputs, made in `wire`.
let companyChips = null;
let placeChips = null;
function ago(iso) { function ago(iso) {
const mins = (Date.now() - new Date(iso)) / 60000; const mins = (Date.now() - new Date(iso)) / 60000;
if (!Number.isFinite(mins)) return ""; if (!Number.isFinite(mins)) return "";
@@ -161,6 +201,11 @@
if (!f.showRead) p.set("include_read", "false"); if (!f.showRead) p.set("include_read", "false");
f.tags.forEach((t) => p.append("tags", t)); f.tags.forEach((t) => p.append("tags", t));
f.companyKeys.forEach((key) => p.append("company_keys", key)); f.companyKeys.forEach((key) => p.append("company_keys", key));
f.places.forEach((token) => p.append("places", token));
f.seniority.forEach((level) => p.append("seniority", level));
// Each box is sent only off its default, and only while its filter is on.
if (f.seniority.length && !f.seniorityUnknown) p.set("seniority_unknown", "false");
if (f.pay && f.payUnknown) p.set("pay_unknown", "true");
if (f.agent !== null) { if (f.agent !== null) {
p.set("agent", String(f.agent)); p.set("agent", String(f.agent));
p.set("order", sortShown() === "score" ? "score" : "newest"); p.set("order", sortShown() === "score" ? "score" : "newest");
@@ -190,14 +235,48 @@
f.gated = q.get("gated") === "true" || q.get("gated") === "1"; f.gated = q.get("gated") === "true" || q.get("gated") === "1";
f.tags = new Set(q.getAll("tags")); f.tags = new Set(q.getAll("tags"));
f.companyKeys = [...new Set(q.getAll("company_keys").filter(Boolean))]; f.companyKeys = [...new Set(q.getAll("company_keys").filter(Boolean))];
f.places = [...new Set(q.getAll("places").filter(Boolean))];
f.seniority = [...new Set(q.getAll("seniority").filter(Boolean))];
f.seniorityUnknown = q.get("seniority_unknown") !== "false";
f.payUnknown = q.get("pay_unknown") === "true";
if (!view) return; if (!view) return;
if (q.get("sort") === "time") f.sort = "time"; if (q.get("sort") === "time") f.sort = "time";
// Checked against the enabled agents once they are in (`chooseAgent`). // Checked against the enabled agents once they are in (`chooseAgent`).
if (q.get("agent")) f.agent = Number(q.get("agent")); if (q.get("agent")) f.agent = Number(q.get("agent"));
if (f.company || f.place || f.function || f.remote || f.judged || f.pay // Open where the rail is a column of its own, which scrolls; shut where
|| f.showMuted || f.gated) { // it is an overlay, unless a filter in it is on, which it then shows.
$("#f-more").open = true; if (!narrow.matches || filtersOn(f, { more: true })) $("#f-more").open = true;
}
/* The chip text of place tokens read from the address, which carries only
the token. A token the server does not know is dropped from the filter
and the address, rather than sent to /api/roles for a 422. Nothing is
asked when every token already has its text. */
async function labelPlaces() {
const missing = state.filter.places.filter((t) => !placeLabels.has(t));
if (!missing.length) return;
const p = new URLSearchParams();
missing.forEach((t) => p.append("tokens", t));
let found;
try {
found = await api(`/api/places/labels?${p}`);
} catch (err) {
return; // toasted; the chips show the tokens themselves
} }
for (const { token, label } of found) placeLabels.set(token, label);
const kept = state.filter.places.filter((t) => placeLabels.has(t) || !missing.includes(t));
if (kept.length !== state.filter.places.length) {
state.filter.places = kept;
writeUrl();
}
renderRail();
}
/** A company chip's text: what was picked, else the company list's name,
else a row's, else the key, until one of those has come in. */
function companyLabel(key) {
return companyNames.get(key) || companies.get(key)?.name
|| state.items.find((r) => r.company_key === key)?.company || key;
} }
const here = () => location.pathname + location.search; const here = () => location.pathname + location.search;
@@ -252,6 +331,9 @@
$("#search").value = state.q; $("#search").value = state.q;
writeUrl(); writeUrl();
route(); route();
// An entry this page pushed holds only tokens it had names for, unless
// the page was reloaded since; then the names are asked again.
labelPlaces();
if (addressFor(pathFor(null)) === before) return; if (addressFor(pathFor(null)) === before) return;
reload(); reload();
if (state.filter.showMuted !== muted) loadFilters().catch(() => {}); if (state.filter.showMuted !== muted) loadFilters().catch(() => {});
@@ -302,6 +384,10 @@
state.selected = at >= 0 ? at : append ? state.selected : 0; state.selected = at >= 0 ? at : append ? state.selected : 0;
renderFeed(); renderFeed();
renderStats(); renderStats();
// A company chip read from the address may only now have a name, off
// its rows; and a new list has new counts under the rail's filters.
renderChips();
if (!append) loadFacets().catch(() => {});
// Still within reach of the end after a short page: the observer only // Still within reach of the end after a short page: the observer only
// fires on a change, and nothing changed, so ask again here. // fires on a change, and nothing changed, so ask again here.
requestAnimationFrame(() => { requestAnimationFrame(() => {
@@ -380,6 +466,18 @@
renderRail(); renderRail();
} }
// How many roles each seniority level and each pay state would bring,
// under every other filter on screen (`Store.role_facets`). Asked after
// each reload with the feed's parameters, the newest answer only.
let facetsRequest = 0;
async function loadFacets() {
const request = ++facetsRequest;
const data = await api(`/api/roles/facets?${feedParams()}`);
if (request !== facetsRequest) return;
state.facets = data;
renderFacets();
}
// ------------------------------------------------------------ the rail // ------------------------------------------------------------ the rail
/* A filter is a question about the feed, and the role open over the old /* A filter is a question about the feed, and the role open over the old
@@ -405,6 +503,9 @@
function clearFilters() { function clearFilters() {
const kept = { agent: state.filter.agent, sort: state.filter.sort }; const kept = { agent: state.filter.agent, sort: state.filter.sort };
state.filter = Object.assign(blankFilter(), kept); state.filter = Object.assign(blankFilter(), kept);
// Text half typed into a chip field goes too, and with it its list.
companyChips?.clear();
placeChips?.clear();
setFilter({}, { counts: true }); setFilter({}, { counts: true });
} }
@@ -428,16 +529,14 @@
setFilter({}, { replace: true }); setFilter({}, { replace: true });
} }
/** Where a company's name links: its roles, as the agent viewing them, in /** Where a company's name links: the list on screen, every filter and the
the order on screen. A company this agent hid keeps Show hidden search kept, with this company as its one company filter, in place of
companies, or its own name would lead to an empty list. */ any company chips and of `?company=`. A company this agent hid turns
on Show hidden companies, or its own name would lead to an empty list. */
function companyHref(key) { function companyHref(key) {
const p = new URLSearchParams(); const f = Object.assign({}, state.filter, { companyKeys: [key], company: "" });
p.append("company_keys", key); if (companies.get(key)?.affinity === -1) f.showMuted = true;
if (companies.get(key)?.affinity === -1) p.set("show_muted", "true"); return addressFor(pathFor(null), f);
const now = new URLSearchParams(location.search);
for (const name of ["agent", "sort"]) if (now.get(name)) p.set(name, now.get(name));
return `${pathFor(null)}?${p}`;
} }
/** A company's name, as a link to its roles when it has a key. */ /** A company's name, as a link to its roles when it has a key. */
@@ -450,12 +549,17 @@
/* A plain click lists the company's roles in place, the list its link /* A plain click lists the company's roles in place, the list its link
leads to, and pushes, so back is the list it left; a modified or middle leads to, and pushes, so back is the list it left; a modified or middle
click is the browser's, and opens the link. */ click is the browser's, and opens the link. The link is written again
first: a row drawn before the last change of filter holds the address
of the list it was drawn in. */
function companyClick(e) { function companyClick(e) {
if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return; if (e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || e.button !== 0) return;
e.preventDefault(); e.preventDefault();
const link = e.currentTarget;
link.href = companyHref(link.dataset.company);
companyNames.set(link.dataset.company, link.textContent.trim());
const counts = state.filter.showMuted; const counts = state.filter.showMuted;
readUrl(new URL(e.currentTarget.href).search, { view: false }); readUrl(new URL(link.href).search, { view: false });
$("#search").value = state.q; $("#search").value = state.q;
setFilter({}, { counts: counts !== state.filter.showMuted }); setFilter({}, { counts: counts !== state.filter.showMuted });
} }
@@ -530,22 +634,121 @@
note.hidden = live.length > 0; note.hidden = live.length > 0;
note.textContent = "No role is tagged yet."; note.textContent = "No role is tagged yet.";
setValue("f-company", f.company); renderChips();
setValue("f-place", f.place);
setValue("f-function", f.function); setValue("f-function", f.function);
setValue("f-remote", f.remote); setValue("f-remote", f.remote);
setValue("f-pay", f.pay); setValue("f-pay", f.pay);
setValue("f-judged", f.judged); setValue("f-judged", f.judged);
setValue("f-show-muted", f.showMuted); setValue("f-show-muted", f.showMuted);
setValue("f-gated", f.gated); setValue("f-gated", f.gated);
const more = [f.company.trim(), f.place.trim(), f.function, f.remote, f.pay, f.judged, renderFacets();
f.showMuted, ranked && f.gated].filter(Boolean).length + f.companyKeys.length; const more = filtersOn(f, { more: true });
$("#f-active").textContent = more ? ` · ${more}` : ""; $("#f-active").textContent = more ? ` · ${more}` : "";
document.body.dataset.rail = state.railOpen ? "open" : "shut"; document.body.dataset.rail = state.railOpen ? "open" : "shut";
$("#rail-toggle").setAttribute("aria-expanded", String(state.railOpen)); $("#rail-toggle").setAttribute("aria-expanded", String(state.railOpen));
} }
/* The chip inputs and the substring chips, from the filter: at load, on
back and forward, and after Clear. A chip input is set only when its
chips differ, since `set` draws them all again, and a pick has drawn
its own already. */
function renderChips() {
if (!companyChips) return;
const f = state.filter;
syncChips(companyChips, f.companyKeys.map((key) => ({ value: key, label: companyLabel(key) })));
syncChips(placeChips, f.places.map((t) => ({ value: t, label: placeLabels.get(t) || t })));
renderText("f-company-text", f.company.trim(), "Company", "company");
renderText("f-place-text", f.place.trim(), "Place", "place");
}
function syncChips(input, want) {
const have = input.values();
if (have.length === want.length
&& have.every((c, i) => c.value === want[i].value && c.label === want[i].label)) return;
input.set(want);
}
/* `?company=` or `?place=`, the substring a link from another page
brought: a plain chip saying what it matches, which takes it off and
pushes, as a filter does. */
function renderText(id, text, noun, key) {
const el = document.getElementById(id);
el.hidden = !text;
if (!text) {
el.replaceChildren();
delete el.dataset.text;
return;
}
if (el.dataset.text === text) return;
el.dataset.text = text;
el.innerHTML = `<button type="button" class="tag" title="Take this filter off"
aria-label="Remove the filter ${esc(noun)} contains ${esc(text)}"
>${esc(noun)} contains “${esc(text)}”<span class="chip-x" aria-hidden="true">×</span></button>`;
el.querySelector("button").onclick = () => setFilter({ [key]: "" });
}
const levelLabel = (level) => level.charAt(0).toUpperCase() + level.slice(1);
/* Which of the facet's pay states each Pay option keeps (`Store.PAY`),
so the option's count is theirs added up: 'stated' in the facet is a
line with no figure, the option "stated_only". */
const PAY_STATES = {
"": ["normalised", "stated", ""], stated: ["normalised", "stated"],
normalised: ["normalised"], stated_only: ["stated"],
};
/* Seniority and Pay with their counts. The levels are the facet's, in the
server's order; until it answers, the ones pressed, so a level read from
the address can be taken off at once. Built again only when a level,
a count or a press changed, so a pressed button keeps its focus. */
function renderFacets() {
const f = state.filter;
const facets = state.facets;
const countOf = (list, value) => list?.find((x) => x.value === value)?.count;
const shown = (n) => (n === undefined ? "" : number.format(n));
const levels = facets ? facets.seniority.map((x) => x.value).filter(Boolean) : [];
for (const level of f.seniority) if (!levels.includes(level)) levels.push(level);
const row = $("#f-seniority");
const counts = levels.map((level) => countOf(facets?.seniority, level));
const sig = JSON.stringify([levels, counts, f.seniority]);
if (row.dataset.key !== sig) {
row.dataset.key = sig;
row.innerHTML = levels.map((level, i) => `
<button type="button" class="tag" data-level="${esc(level)}"
aria-pressed="${f.seniority.includes(level)}"
>${esc(levelLabel(level))}${counts[i] === undefined ? ""
: `<span class="count">${shown(counts[i])}</span>`}</button>`).join("");
row.querySelectorAll("[data-level]").forEach((b) => {
b.onclick = () => toggleLevel(b.dataset.level);
});
}
$("#f-seniority-unknown-row").hidden = !f.seniority.length;
setValue("f-seniority-unknown", f.seniorityUnknown);
$("#f-seniority-unknown-count").textContent = shown(countOf(facets?.seniority, ""));
for (const option of $("#f-pay").options) {
const states = PAY_STATES[option.value];
const n = facets && states
? states.reduce((sum, s) => sum + (countOf(facets.pay, s) || 0), 0) : undefined;
const text = n === undefined ? option.dataset.label : `${option.dataset.label} (${shown(n)})`;
if (option.textContent !== text) option.textContent = text;
}
$("#f-pay-unknown-row").hidden = !f.pay;
setValue("f-pay-unknown", f.payUnknown);
$("#f-pay-unknown-count").textContent = shown(countOf(facets?.pay, ""));
}
/* A level pressed or let go, pushed as a filter. The last one let go
ticks "no level" again, which is how the box starts for the next. */
function toggleLevel(level) {
const f = state.filter;
const next = f.seniority.includes(level)
? f.seniority.filter((l) => l !== level) : [...f.seniority, level];
setFilter({ seniority: next, seniorityUnknown: next.length ? f.seniorityUnknown : true });
}
/* Viewing as: a select of the enabled agents, also when there is one, and /* Viewing as: a select of the enabled agents, also when there is one, and
with none a sentence and the way to make one. Nothing until the agents 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. */ are in, so a page with agents never says it has none. */
@@ -576,10 +779,7 @@
number in a circle reads as "new things" on the one control that means number in a circle reads as "new things" on the one control that means
things are being left out (newsdesk's reasoning). */ things are being left out (newsdesk's reasoning). */
function renderActive() { function renderActive() {
const f = state.filter; const on = filtersOn();
const on = [!f.showRead, f.period !== "all", f.company.trim(), f.place.trim(),
f.function, f.remote, f.pay, f.judged, f.showMuted, sortShown() === "score" && f.gated]
.filter(Boolean).length + f.tags.size + f.companyKeys.length;
const count = on === 1 ? "1 filter" : `${on} filters`; const count = on === 1 ? "1 filter" : `${on} filters`;
$(".rail-toggle-label").textContent = on ? count : "Menu"; $(".rail-toggle-label").textContent = on ? count : "Menu";
$("#rail-toggle").setAttribute("aria-label", on ? `Menu — ${count} on` : "Menu"); $("#rail-toggle").setAttribute("aria-label", on ? `Menu — ${count} on` : "Menu");
@@ -650,8 +850,10 @@
return ""; return "";
} }
function badges(role, { seniority = false } = {}) { /** Closed, pay, remote, function and seniority, as the row and the reader
const words = [role.remote, role.function, seniority ? role.seniority : ""].filter(Boolean); both show them. */
function badges(role) {
const words = [role.remote, role.function, role.seniority].filter(Boolean);
const pay = payBadge(role); const pay = payBadge(role);
return (role.closed_at ? `<span class="badge closed">closed</span>` : "") return (role.closed_at ? `<span class="badge closed">closed</span>` : "")
+ (pay ? `<span class="badge">${esc(pay)}</span>` : "") + (pay ? `<span class="badge">${esc(pay)}</span>` : "")
@@ -746,10 +948,7 @@
const retry = empty.querySelector("[data-retry]"); const retry = empty.querySelector("[data-retry]");
if (retry) retry.onclick = () => loadFeed(); if (retry) retry.onclick = () => loadFeed();
} else { } else {
const f = state.filter; const filtered = state.q || filtersOn();
const filtered = state.q || f.tags.size || f.period !== "all" || !f.showRead
|| f.company.trim() || f.place.trim() || f.function || f.remote || f.pay || f.judged
|| f.companyKeys.length;
empty.innerHTML = filtered empty.innerHTML = filtered
? `<h2>Nothing matches</h2> ? `<h2>Nothing matches</h2>
<p>No open role fits these filters. <p>No open role fits these filters.
@@ -805,8 +1004,7 @@
<button type="button" class="linky strip-drop" <button type="button" class="linky strip-drop"
title="Take the company filter off">All companies</button> title="Take the company filter off">All companies</button>
</div> </div>
<p class="strip-note">★ Favourite lists its roles from every place the agent's <p class="strip-note"></p>
required gates allow, not only the agent's own places.</p>
<p class="strip-status" role="status"></p>`; <p class="strip-status" role="status"></p>`;
el.querySelector(".strip-drop").onclick = dropCompany; el.querySelector(".strip-drop").onclick = dropCompany;
} }
@@ -814,7 +1012,12 @@
if (slot.dataset.affinity !== String(affinity)) { if (slot.dataset.affinity !== String(affinity)) {
slot.dataset.affinity = String(affinity); slot.dataset.affinity = String(affinity);
slot.replaceChildren(affinityControl(key, affinity, slot.replaceChildren(affinityControl(key, affinity,
() => affinityChanged(key, company), state.filter.agent)); (updated) => affinityChanged(key, company, updated), state.filter.agent));
// What ★ does, before; what it did, after.
el.querySelector(".strip-note").textContent = affinity === 2
? "★ Favourite: roles from every place the agent's required gates allow are listed."
: "★ Favourite also lists this company's roles outside your places, as far as the "
+ "agent's required gates allow.";
} }
const n = state.total; const n = state.total;
el.querySelector(".strip-count").textContent = state.loaded el.querySelector(".strip-count").textContent = state.loaded
@@ -823,26 +1026,24 @@
/* A company seen only through a search has no row until its first change /* A company seen only through a search has no row until its first change
creates one, so the list is reloaded then. A change dims or undims its creates one, so the list is reloaded then. A change dims or undims its
rows at once; where they rank waits on the `score` it queued, and the rows at once; where they rank waits on the `score` it queued, whose id
feed reloads when that has finished. */ the affinity route answers with (`updated.score_job`), and the feed
async function affinityChanged(key, company) { reloads when that has finished. */
async function affinityChanged(key, company, updated) {
if (!company) await loadCompanies(state.filter.agent).catch(() => {}); if (!company) await loadCompanies(state.filter.agent).catch(() => {});
renderFeed(); renderFeed();
const status = () => $("#company-strip .strip-status"); const status = () => $("#company-strip .strip-status");
if (status()) status().textContent = "Scoring again; the list reloads when that is done."; if (status()) status().textContent = "Scoring again; the list reloads when that is done.";
await scored(); await scored(updated?.score_job);
if (status()) status().textContent = ""; if (status()) status().textContent = "";
if (state.filter.companyKeys.includes(key)) reload(); if (state.filter.companyKeys.includes(key)) reload();
} }
/* Wait for the `score` that carries a change just made, the way agents.js's /* Wait for the `score` job `job`, the way agents.js's `rescore` waits:
`rescore` waits. The affinity route answers with that job's id until the queue holds it neither running nor queued. None, when the
(`score_job`), but app.js's `setAffinity` keeps the answer to itself, route could queue no job, is nothing to wait for. */
so the job is read off the queue: right after the change it is the async function scored(job) {
newest `score` queued or running, which is what `_score_after_change` if (job == null) return;
answers with. None there means it has already finished. */
async function scored() {
let job;
for (let i = 0; i < 300; i += 1) { for (let i = 0; i < 300; i += 1) {
let snapshot; let snapshot;
try { try {
@@ -850,9 +1051,7 @@
} catch (err) { } catch (err) {
return; return;
} }
const live = [...snapshot.running, ...snapshot.queued].filter((j) => j.kind === "score"); if (![...snapshot.running, ...snapshot.queued].some((j) => j.id === job)) return;
if (job === undefined) job = Math.max(-1, ...live.map((j) => j.id));
if (!live.some((j) => j.id === job)) return;
await new Promise((resolve) => setTimeout(resolve, 1000)); await new Promise((resolve) => setTimeout(resolve, 1000));
} }
} }
@@ -1041,7 +1240,7 @@
<span class="affinity-slot"></span> <span class="affinity-slot"></span>
${r.place ? `<span>${esc(r.place)}</span>` : ""} ${r.place ? `<span>${esc(r.place)}</span>` : ""}
${r.first_seen ? `<span title="First seen">${ago(r.first_seen)}</span>` : ""} ${r.first_seen ? `<span title="First seen">${ago(r.first_seen)}</span>` : ""}
${badges(r, { seniority: true })} ${badges(r)}
${tagChips(r.tags)} ${tagChips(r.tags)}
</div> </div>
<h1>${esc(r.title || "")}</h1> <h1>${esc(r.title || "")}</h1>
@@ -1315,13 +1514,47 @@
$("#period").addEventListener("change", (e) => setFilter({ period: e.target.value })); $("#period").addEventListener("change", (e) => setFilter({ period: e.target.value }));
$("#clear-tags").addEventListener("click", () => { state.filter.tags.clear(); setFilter({}); }); $("#clear-tags").addEventListener("click", () => { state.filter.tags.clear(); setFilter({}); });
const typed = debounce(() => setFilter({}, { replace: true }), 300); // A pick or a removal is a filter set, pushed; the text typed to find
for (const key of ["company", "place"]) { // it is the chip input's own and never reaches the address.
$(`#f-${key}`).addEventListener("input", (e) => { state.filter[key] = e.target.value; typed(); }); companyChips = chipInput($("#f-company"), {
} suggest: (q) => {
for (const key of ["function", "remote", "pay", "judged"]) { const p = new URLSearchParams({ q });
if (state.filter.agent !== null) p.set("agent", String(state.filter.agent));
return api(`/api/suggest/companies?${p}`).then((rows) => rows.map((c) => ({
value: c.key, label: c.name,
hint: c.affinity === 2 ? `★ ${number.format(c.count)}` : c.count,
})));
},
onChange: (items) => {
items.forEach((i) => companyNames.set(i.value, i.label));
setFilter({ companyKeys: items.map((i) => i.value) });
},
placeholder: "Company", label: "Company",
});
placeChips = chipInput($("#f-place"), {
suggest: (q) => api(`/api/suggest/places?${new URLSearchParams({ q })}`)
.then((rows) => rows.map((s) => ({
value: s.token, label: s.label,
hint: `${PLACE_KINDS[s.kind] || s.kind} · ${number.format(s.count)}`,
}))),
onChange: (items) => {
items.forEach((i) => placeLabels.set(i.value, i.label));
setFilter({ places: items.map((i) => i.value) });
},
placeholder: "Place", label: "Place",
});
for (const key of ["function", "remote", "judged"]) {
$(`#f-${key}`).addEventListener("change", (e) => setFilter({ [key]: e.target.value })); $(`#f-${key}`).addEventListener("change", (e) => setFilter({ [key]: e.target.value }));
} }
// "No pay stated" starts unticked for each pay picked anew.
$("#f-pay").addEventListener("change", (e) => setFilter({
pay: e.target.value, payUnknown: e.target.value ? state.filter.payUnknown : false,
}));
$("#f-pay-unknown").addEventListener("change",
(e) => setFilter({ payUnknown: e.target.checked }));
$("#f-seniority-unknown").addEventListener("change",
(e) => setFilter({ seniorityUnknown: e.target.checked }));
$("#f-show-muted").addEventListener("change", $("#f-show-muted").addEventListener("change",
(e) => setFilter({ showMuted: e.target.checked }, { counts: true })); (e) => setFilter({ showMuted: e.target.checked }, { counts: true }));
$("#f-gated").addEventListener("change", (e) => setFilter({ gated: e.target.checked })); $("#f-gated").addEventListener("change", (e) => setFilter({ gated: e.target.checked }));
@@ -1369,6 +1602,9 @@
wire(); wire();
renderRail(); renderRail();
renderActive(); renderActive();
// Named before the first request, which a token the server does not
// know would turn into a 422 rather than a list.
await labelPlaces();
// The feed is the page; agents and companies are enhancements that fill // The feed is the page; agents and companies are enhancements that fill
// in when they arrive, not something it waits on — a slow or failed // in when they arrive, not something it waits on — a slow or failed
+35 -8
View File
@@ -70,8 +70,25 @@
<details id="f-more" class="rail-more"> <details id="f-more" class="rail-more">
<summary>More filters<span id="f-active" class="filter-active"></span></summary> <summary>More filters<span id="f-active" class="filter-active"></span></summary>
<div class="rail-fields"> <div class="rail-fields">
<input type="text" id="f-company" placeholder="Company" aria-label="Company"> {# Company and Place are chip inputs (static/chips.js), each pick a
<input type="text" id="f-place" placeholder="Place" aria-label="Place"> company key or a place token from the suggest routes. The chips
of `?company=` and `?place=`, the substrings other pages link
with, sit under them to be taken off; nothing types a new one. #}
<div id="f-company"></div>
<div id="f-company-text" class="rail-legacy" hidden></div>
<div id="f-place"></div>
<div id="f-place-text" class="rail-legacy" hidden></div>
{# The levels come with their counts from /api/roles/facets, so the
server's list is the one shown. "No level" is a question only
once a level is pressed. #}
<div class="rail-facet" role="group" aria-labelledby="f-seniority-label">
<span class="rail-field" id="f-seniority-label">Seniority</span>
<div id="f-seniority" class="rail-chips"></div>
<label class="check" id="f-seniority-unknown-row" hidden>
<input type="checkbox" id="f-seniority-unknown"> <span>and roles with no level<span
class="count" id="f-seniority-unknown-count"></span></span>
</label>
</div>
<select id="f-function" aria-label="Function"> <select id="f-function" aria-label="Function">
<option value="">Any function</option> <option value="">Any function</option>
{% for value, label in functions %} {% for value, label in functions %}
@@ -84,12 +101,18 @@
<option value="{{ value }}">{{ label }}</option> <option value="{{ value }}">{{ label }}</option>
{% endfor %} {% endfor %}
</select> </select>
<select id="f-pay" aria-label="Pay"> <div class="rail-facet">
<option value="">Any pay</option> <select id="f-pay" aria-label="Pay">
{% for value, label in pay_options %} <option value="" data-label="Any pay">Any pay</option>
<option value="{{ value }}">{{ label }}</option> {% for value, label in pay_options %}
{% endfor %} <option value="{{ value }}" data-label="{{ label }}">{{ label }}</option>
</select> {% endfor %}
</select>
<label class="check" id="f-pay-unknown-row" hidden>
<input type="checkbox" id="f-pay-unknown"> <span>and roles that state no pay<span
class="count" id="f-pay-unknown-count"></span></span>
</label>
</div>
<select id="f-judged" aria-label="Judged"> <select id="f-judged" aria-label="Judged">
<option value="">Any vote</option> <option value="">Any vote</option>
<option value="liked">Liked</option> <option value="liked">Liked</option>
@@ -127,6 +150,10 @@
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
{# base.html has no block in its head; a stylesheet linked from the body
applies all the same, and chips.css only adds to app.css. #}
<link rel="stylesheet" href="{{ asset('chips.css') }}">
<script src="{{ asset('chips.js') }}"></script>
<script src="{{ asset('judge.js') }}"></script> <script src="{{ asset('judge.js') }}"></script>
<script src="{{ asset('roles.js') }}"></script> <script src="{{ asset('roles.js') }}"></script>
{% endblock %} {% endblock %}