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>
92 lines
3.4 KiB
JavaScript
92 lines
3.4 KiB
JavaScript
/* The Applications tab: every saved role and its status.
|
|
*
|
|
* The template renders an empty table; the rows come from /api/applications
|
|
* and a status change is a fetch through `api()` from app.js, which toasts a
|
|
* refusal. A role's title opens its read page, where ★ unsaves it; one that
|
|
* was never a posting links out to where it was found, if anywhere. The
|
|
* company names come from app.js's shared company list.
|
|
*/
|
|
(function () {
|
|
"use strict";
|
|
|
|
const { api, count, cell, companies, loadCompanies } = window;
|
|
const $ = (sel, root = document) => root.querySelector(sel);
|
|
|
|
// `ROLEDESK_STATUSES` is set by applications.html from the same `STATUSES`
|
|
// tuple the store validates against, so this list can never drift from
|
|
// what a `POST .../status` will accept.
|
|
function statusSelect(current) {
|
|
const select = document.createElement("select");
|
|
for (const status of window.ROLEDESK_STATUSES) {
|
|
const option = document.createElement("option");
|
|
option.value = status;
|
|
option.textContent = status[0].toUpperCase() + status.slice(1);
|
|
option.selected = status === current;
|
|
select.appendChild(option);
|
|
}
|
|
return select;
|
|
}
|
|
|
|
/** "25 Sep", or "25 Sep 2025" when it is not this year. */
|
|
function savedOn(iso) {
|
|
const at = new Date(iso);
|
|
if (Number.isNaN(at.getTime())) return "";
|
|
const options = { day: "numeric", month: "short" };
|
|
if (at.getFullYear() !== new Date().getFullYear()) options.year = "numeric";
|
|
return at.toLocaleDateString("en-GB", options);
|
|
}
|
|
|
|
function render(applications) {
|
|
const body = $("#applications-list");
|
|
body.replaceChildren();
|
|
for (const application of applications) {
|
|
const tr = document.createElement("tr");
|
|
if (application.role_uid || application.url) {
|
|
const link = document.createElement("a");
|
|
link.textContent = application.role_title || "(untitled)";
|
|
if (application.role_uid) {
|
|
link.href = `/roles/${encodeURIComponent(application.role_uid)}`;
|
|
} else {
|
|
link.href = application.url;
|
|
link.target = "_blank";
|
|
link.rel = "noopener";
|
|
}
|
|
cell(tr, "Role", link);
|
|
} else {
|
|
cell(tr, "Role", application.role_title || "(untitled)");
|
|
}
|
|
const company = companies.get(application.company_key);
|
|
cell(tr, "Company", company ? company.name : application.company_key);
|
|
const select = statusSelect(application.status);
|
|
select.addEventListener("change", () => setStatus(application.id, select));
|
|
cell(tr, "Status", select);
|
|
const saved = cell(tr, "Saved", savedOn(application.created_at));
|
|
saved.title = application.created_at;
|
|
body.appendChild(tr);
|
|
}
|
|
$("#applications-count").textContent =
|
|
count(applications.length, "tracked application");
|
|
}
|
|
|
|
async function setStatus(id, select) {
|
|
select.disabled = true;
|
|
try {
|
|
await api(`/api/applications/${encodeURIComponent(id)}/status`, {
|
|
method: "POST", body: { status: select.value },
|
|
});
|
|
render(await api("/api/applications"));
|
|
} catch (err) {
|
|
select.disabled = false;
|
|
}
|
|
}
|
|
|
|
document.addEventListener("DOMContentLoaded", async () => {
|
|
try {
|
|
const [, applications] = await Promise.all([loadCompanies(), api("/api/applications")]);
|
|
render(applications);
|
|
} catch (err) {
|
|
/* already toasted */
|
|
}
|
|
});
|
|
})();
|