The seed was jobhunt-hq's 186 US boards, chosen because they could be read. It is now a hand-picked list of European tech employers, with `board` filled by the new `app.jobs.discover` from each company's own careers site and every board fetched once before it landed: 175 have one, and the rest keep the ATS host their site runs on (Teamtailor 32, Workday 12, SuccessFactors 9, ...) and a careers URL, as rows the app cannot read yet. Companies shows them as "not readable yet" with a link, behind a filter, so the next parser to write is the host that filter shows most. `app companies discover NAME DOMAIN [--add]` reads the home page, its careers links and the usual paths for a link into a known host, one level down on a careers page, and probes Greenhouse, Lever, Ashby, SmartRecruiters, Recruitee and Personio by slug when the pages link nothing. It is what the LinkedIn flow will call. Migration 7 adds companies.ats, country and city. The Workable parser now reads the v3 shape its list endpoint actually sends (location object, department list, shortcode and no URL or text); the first populated board showed it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
257 lines
9.6 KiB
JavaScript
257 lines
9.6 KiB
JavaScript
/* The Company boards section of Sources: every company, its board, its open
|
|
* roles, its affinity, following a new one, and pruning boards with nothing
|
|
* open in a region.
|
|
*
|
|
* The list is app.js's shared company list (`/api/companies`), already
|
|
* joined with each company's board subscription — its id and whether it is
|
|
* on — so nothing here fetches `/api/sources` as well. The affinity buttons
|
|
* are `affinityControl`, the same ones the Roles tab and the read page draw.
|
|
*
|
|
* Liked and hidden are per search agent, so the `#c-agent` select above the
|
|
* list says whose the list shows and whose the buttons set. It opens on the
|
|
* server's default, the enabled agent with the lowest id; with no agent at
|
|
* all there is nothing to like, and the section says so instead of drawing
|
|
* the buttons.
|
|
*/
|
|
(function () {
|
|
"use strict";
|
|
|
|
const { api, count, debounce, companies, loadCompanies, affinityControl } = window;
|
|
const $ = (sel, root = document) => root.querySelector(sel);
|
|
|
|
/** @type {object[]} the search agents, by id */
|
|
let agents = [];
|
|
|
|
/** The id in `#c-agent`, or null while there is no agent to pick. */
|
|
function agentId() {
|
|
const value = $("#c-agent").value;
|
|
return value ? Number(value) : null;
|
|
}
|
|
|
|
async function loadAgents() {
|
|
agents = (await api("/api/agents")).sort((a, b) => a.id - b.id);
|
|
const select = $("#c-agent");
|
|
select.replaceChildren();
|
|
for (const a of agents) {
|
|
const option = document.createElement("option");
|
|
option.value = String(a.id);
|
|
option.textContent = a.name;
|
|
select.appendChild(option);
|
|
}
|
|
const first = agents.find((a) => a.enabled) || agents[0];
|
|
if (first) select.value = String(first.id);
|
|
select.closest("label").hidden = !first;
|
|
$("#c-no-agent").hidden = Boolean(first);
|
|
}
|
|
|
|
// ---------------------------------------------------------------- the list
|
|
|
|
function subLine(company) {
|
|
const sub = document.createElement("span");
|
|
sub.className = "sub";
|
|
if (company.board) {
|
|
const badge = document.createElement("span");
|
|
badge.className = "badge";
|
|
badge.textContent = company.board;
|
|
sub.appendChild(badge);
|
|
} else if (company.ats || company.careers_url) {
|
|
// Followed, but its careers site runs on nothing the app reads yet.
|
|
const badge = document.createElement("span");
|
|
badge.className = "badge";
|
|
badge.textContent = company.ats || "own site";
|
|
sub.appendChild(badge);
|
|
sub.append(" · not readable yet");
|
|
} else {
|
|
sub.append("from job boards");
|
|
}
|
|
if (company.careers_url && !company.board) {
|
|
const link = document.createElement("a");
|
|
link.href = company.careers_url;
|
|
link.target = "_blank";
|
|
link.rel = "noopener";
|
|
link.textContent = "careers page";
|
|
sub.append(" · ");
|
|
sub.appendChild(link);
|
|
}
|
|
sub.append(` · ${count(company.open_roles, "open role")}`);
|
|
return sub;
|
|
}
|
|
|
|
/** The board switch, or nothing for a company known only from a search:
|
|
there is no subscription to switch. */
|
|
function onSwitch(company, rerender) {
|
|
if (company.subscription_id == null) return null;
|
|
const box = document.createElement("input");
|
|
box.type = "checkbox";
|
|
box.checked = Boolean(company.on);
|
|
box.setAttribute("aria-label", `Read ${company.name}'s board`);
|
|
box.addEventListener("change", async () => {
|
|
box.disabled = true;
|
|
try {
|
|
const result = await api(`/api/sources/${company.subscription_id}/switch`,
|
|
{ method: "POST", body: { on: box.checked } });
|
|
company.on = result.source.on;
|
|
if (!box.checked && result.closed) {
|
|
window.toast.info(`${company.name}: ${count(result.closed, "open role")} closed.`);
|
|
}
|
|
} catch (err) {
|
|
box.checked = !box.checked;
|
|
}
|
|
box.disabled = false;
|
|
rerender();
|
|
});
|
|
return box;
|
|
}
|
|
|
|
function matchesFilter(company, filter) {
|
|
switch (filter) {
|
|
case "favourite": return company.affinity === 2;
|
|
case "liked": return company.affinity === 1;
|
|
case "hidden": return company.affinity === -1;
|
|
case "on": return company.on === true;
|
|
case "off": return company.on === false;
|
|
case "unreadable": return company.subscription_id == null && Boolean(company.ats || company.careers_url);
|
|
default: return true;
|
|
}
|
|
}
|
|
|
|
function render() {
|
|
const q = $("#c-q").value.trim().toLowerCase();
|
|
const filter = $("#c-filter").value;
|
|
const rows = [...companies.values()]
|
|
.filter((c) => !q || c.name.toLowerCase().includes(q) || c.board.includes(q)
|
|
|| (c.ats || "").includes(q) || (c.country || "").toLowerCase() === q)
|
|
.filter((c) => matchesFilter(c, filter))
|
|
.sort((a, b) => b.open_roles - a.open_roles || a.name.localeCompare(b.name));
|
|
const body = $("#companies-list");
|
|
body.replaceChildren();
|
|
for (const company of rows) {
|
|
const row = document.createElement("div");
|
|
row.className = "crow";
|
|
if (company.affinity === -1) row.dataset.hidden = "true";
|
|
const link = document.createElement("a");
|
|
link.className = "name";
|
|
link.href = `/?company=${encodeURIComponent(company.name)}`;
|
|
link.title = "This company's open roles";
|
|
link.textContent = company.name;
|
|
row.appendChild(link);
|
|
const switchBox = onSwitch(company, render);
|
|
if (switchBox) row.appendChild(switchBox);
|
|
const agent = agentId();
|
|
if (agent != null) {
|
|
row.appendChild(affinityControl(company.key, company.affinity, async () => render(), agent));
|
|
}
|
|
row.appendChild(subLine(company));
|
|
body.appendChild(row);
|
|
}
|
|
const open = rows.reduce((sum, c) => sum + c.open_roles, 0);
|
|
$("#companies-count").textContent =
|
|
`${count(rows.length, "company", "companies")}, ${count(open, "open role")}`;
|
|
}
|
|
|
|
// -------------------------------------------------------------------- follow
|
|
|
|
async function addBoard(event) {
|
|
event.preventDefault();
|
|
const status = $("#board-status");
|
|
const button = $("#board-form button[type=submit]");
|
|
button.disabled = true;
|
|
status.textContent = "Reading the board once before following it…";
|
|
const board = `${$("#b-host").value}:${$("#b-slug").value.trim()}`;
|
|
try {
|
|
const result = await api("/api/boards", {
|
|
method: "POST",
|
|
body: { board, name: $("#b-name").value.trim() },
|
|
});
|
|
await loadCompanies(agentId());
|
|
render();
|
|
$("#board-form").reset();
|
|
status.textContent = `Following ${result.source.label}: `
|
|
+ `${count(result.found, "role")} listed. They arrive with the next pull.`;
|
|
} catch (err) {
|
|
status.textContent = "";
|
|
}
|
|
button.disabled = false;
|
|
}
|
|
|
|
// -------------------------------------------------------------------- prune
|
|
|
|
/** @type {object[]} the boards the last preview named. */
|
|
let pruneBoards = [];
|
|
|
|
async function previewPrune(event) {
|
|
event.preventDefault();
|
|
const status = $("#prune-status");
|
|
const list = $("#prune-list");
|
|
const region = $("#p-region").value.trim();
|
|
list.replaceChildren();
|
|
$("#p-apply").disabled = true;
|
|
$("#p-apply").textContent = "Switch off these boards";
|
|
status.textContent = "Checking every board…";
|
|
try {
|
|
const result = await api(`/api/prune?region=${encodeURIComponent(region)}`);
|
|
pruneBoards = result.boards;
|
|
const roles = pruneBoards.reduce((sum, b) => sum + b.open_roles, 0);
|
|
status.textContent = pruneBoards.length
|
|
? `${count(pruneBoards.length, "board")} with no open role in ${region}, `
|
|
+ `${count(roles, "open role")} between them:`
|
|
: `Every board that is on has a role in ${region}.`;
|
|
for (const board of pruneBoards) {
|
|
const li = document.createElement("li");
|
|
li.textContent = `${board.label} (${board.target}), ${count(board.open_roles, "open role")}`;
|
|
list.appendChild(li);
|
|
}
|
|
$("#p-apply").disabled = pruneBoards.length === 0;
|
|
$("#p-apply").textContent = `Switch off these ${count(pruneBoards.length, "board")}`;
|
|
} catch (err) {
|
|
status.textContent = "";
|
|
}
|
|
}
|
|
|
|
async function applyPrune() {
|
|
const region = $("#p-region").value.trim();
|
|
if (!window.confirm(`Switch off ${count(pruneBoards.length, "board")} and close their roles? `
|
|
+ "Each can be switched back on in the list above.")) return;
|
|
$("#p-apply").disabled = true;
|
|
try {
|
|
const result = await api("/api/prune", { method: "POST", body: { region } });
|
|
$("#prune-status").textContent = `Switched off ${count(result.pruned, "board")}, `
|
|
+ `closed ${count(result.roles_closed, "role")}. ${result.boards_left} boards are on.`;
|
|
$("#prune-list").replaceChildren();
|
|
$("#p-apply").textContent = "Switch off these boards";
|
|
await loadCompanies(agentId());
|
|
render();
|
|
} catch (err) {
|
|
$("#p-apply").disabled = false;
|
|
}
|
|
}
|
|
|
|
// -------------------------------------------------------------------- init
|
|
|
|
async function switchAgent() {
|
|
try {
|
|
await loadCompanies(agentId());
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
render();
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", async () => {
|
|
if (!$("#companies-list")) return;
|
|
try {
|
|
await loadAgents();
|
|
await loadCompanies(agentId());
|
|
} catch (err) {
|
|
return;
|
|
}
|
|
render();
|
|
$("#c-q").addEventListener("input", debounce(render, 150));
|
|
$("#c-filter").addEventListener("change", render);
|
|
$("#c-agent").addEventListener("change", switchAgent);
|
|
$("#board-form").addEventListener("submit", addBoard);
|
|
$("#prune-form").addEventListener("submit", previewPrune);
|
|
$("#p-apply").addEventListener("click", applyPrune);
|
|
});
|
|
})();
|