Add a job leads inbox that finds and scores postings
Test and deploy / test (push) Successful in 1m55s
Test and deploy / deploy (push) Successful in 59s

The tracker recorded applications but could not find jobs. A new
pipeline (services/job_leads.go, job_sources.go) polls a watch list of
sources on a timer or on request, files unseen postings as leads, marks
which pass a keyword and location pre-filter, and has Claude score those
against a single search profile through a fourth internal Python route,
/internal/jobs/score.

Sources are Greenhouse, Lever and Ashby company boards (public JSON) and
Adzuna and Reed keyword searches (API keys). The two search fetchers are
written from the providers' documentation and tested only against stubs.

Leads are their own table, not a job status, and are not soft deleted:
the (source_kind, external_id) index is the dedup, so a dismissed lead
has to remain a row. A lead reaches the tracker only by promotion, which
goes through UpsertJobApplication. That upsert moves from the capture
handler into services so promotion and the fetcher can share it; the
capture endpoint's behaviour is unchanged.

/cv/leads is the page: inbox, watch list and profile form. The timer is
off unless JOB_LEADS_ENABLED=true and never runs at start-up, so a
deploy spends no Claude calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 15:03:46 +01:00
co-authored by Claude Opus 5.5
parent 810d3118b3
commit af50e6c8ab
40 changed files with 7295 additions and 407 deletions
+11 -3
View File
@@ -11,9 +11,10 @@
* stores/jobApplications.js and stores/jobAppReferences.js; nothing here calls
* gql() directly.
*
* Rows also arrive from two places that are not this page: the email pipeline,
* and the browser userscript in `public/job-capture.user.js`, which the header
* links to for installing.
* Rows also arrive from three places that are not this page: the email
* pipeline, the browser userscript in `public/job-capture.user.js`, which the
* header links to for installing, and the leads inbox at `/cv/leads`
* (JobLeads.vue), where tracking a lead adds it here as Saved.
*/
import { ref, computed, onMounted } from "vue";
import { RouterLink } from "vue-router";
@@ -293,6 +294,9 @@ onMounted(fetchApplications);
<h2 class="ja-heading">Job Applications</h2>
</div>
<div class="ja-header-right">
<!-- Postings the server found by itself; tracking one there adds it
to this page as Saved. -->
<RouterLink to="/cv/leads" class="cv-btn ja-btn-link">Leads</RouterLink>
<!-- A plain link to a static file: Violentmonkey intercepts any
navigation to a URL ending in .user.js and offers to install it.
The token it then asks for is generated on the admin panel. -->
@@ -564,6 +568,10 @@ onMounted(fetchApplications);
color: var(--color-ink);
}
.ja-btn-link {
text-decoration: none;
}
.ja-heading {
font-size: 1.1rem;
font-weight: 600;
+589
View File
@@ -0,0 +1,589 @@
<script setup>
/**
* Route `/cv/leads` (guarded by `meta.requiresAdmin`) — the leads inbox:
* postings the server found on its own, waiting to be tracked or dismissed.
*
* The server side is backend/services/job_leads.go. On a timer, or when
* "Check now" is pressed here, it polls the sources (JobSources.vue), keeps
* the postings that pass the keyword filter and has Claude score them against
* the profile (JobSearchProfile.vue). Nothing reaches the tracker at /cv/jobs
* until **Track** is pressed on a lead, which adds it there as Saved.
*
* This view owns the page frame, the single error banner, the run button and
* the list. Data access is in stores/jobLeads.js; nothing here calls gql().
*
* A run takes from seconds to a few minutes, so "Check now" does not wait for
* it: the server starts the run and this page polls its status, then reloads
* the list when it finishes.
*/
import { ref, computed, onMounted, onBeforeUnmount } from "vue";
import { RouterLink } from "vue-router";
import { storeToRefs } from "pinia";
import { useJobLeadsStore } from "@/stores/jobLeads";
import { useJobSearchProfileStore } from "@/stores/jobSearchProfile";
import JobSources from "./JobSources.vue";
import JobSearchProfile from "./JobSearchProfile.vue";
import "./jobs-shared.css";
const TABS = [
{ value: "new", label: "Inbox" },
{ value: "promoted", label: "Tracked" },
{ value: "dismissed", label: "Dismissed" },
];
// Labels for JobLead.sourceKind; a COPY of the kinds in JobSources.vue.
const SOURCE_LABELS = { greenhouse: "Greenhouse", lever: "Lever", ashby: "Ashby", adzuna: "Adzuna", reed: "Reed" };
const POLL_MS = 3000;
const store = useJobLeadsStore();
const { leads, status, loading } = storeToRefs(store);
const { profile } = storeToRefs(useJobSearchProfileStore());
const error = ref("");
const tab = ref("new");
const search = ref("");
// Two separate "show me the rest" switches: leads scored below the profile's
// minimum (already loaded, hidden here), and leads the keyword filter
// rejected (not loaded at all until asked for — that is most of every board).
const showLowScores = ref(false);
const showUnmatched = ref(false);
const busyId = ref(null);
const sourcesBox = ref(null);
// The posting text for the one lead whose description is open.
// `undefined` in the cache means "not fetched", `""` means "fetched, none".
const descriptionId = ref(null);
const descriptions = ref({});
function fail(err) {
console.error(err);
error.value = String(err?.message ?? err);
}
function clearError() {
error.value = "";
}
async function fetchLeads() {
// The store's fetch() records its failure instead of throwing.
await store.fetch({ includeUnmatched: showUnmatched.value });
if (store.error) fail(store.error);
}
const minScore = computed(() => profile.value?.minScore ?? 0);
/** An unscored lead is never "low": no score is not a bad score. */
const isLow = (lead) => lead.score != null && lead.score < minScore.value;
const counts = computed(() => {
const out = { new: 0, promoted: 0, dismissed: 0 };
for (const lead of leads.value) if (lead.state in out) out[lead.state]++;
return out;
});
const inTab = computed(() => leads.value.filter((lead) => lead.state === tab.value));
const hiddenLow = computed(() =>
tab.value === "new" && !showLowScores.value ? inTab.value.filter(isLow).length : 0,
);
// The server already sorts best-first, unscored after scored, newest first
// within a score, so this only filters.
const visibleLeads = computed(() => {
const needle = search.value.trim().toLowerCase();
return inTab.value.filter((lead) => {
if (tab.value === "new" && !showLowScores.value && isLow(lead)) return false;
if (!needle) return true;
return [lead.jobTitle, lead.company, lead.location, lead.scoreReasons]
.some((field) => field?.toLowerCase().includes(needle));
});
});
function scoreClass(lead) {
if (lead.score == null) return "jl-score-none";
if (lead.score >= 80) return "jl-score-high";
if (lead.score >= 60) return "jl-score-mid";
return "jl-score-low";
}
function ageLabel(lead) {
const at = lead.postedAt ?? lead.createdAt;
if (!at) return "";
const days = Math.floor((Date.now() - new Date(at).getTime()) / 86_400_000);
const age = days <= 0 ? "today" : days === 1 ? "1 day ago" : `${days} days ago`;
return lead.postedAt ? `posted ${age}` : `found ${age}`;
}
async function act(lead, action) {
busyId.value = lead.id;
try {
await store[action](lead.id);
if (descriptionId.value === lead.id) descriptionId.value = null;
error.value = "";
} catch (err) {
fail(err);
} finally {
busyId.value = null;
}
}
async function toggleDescription(lead) {
if (descriptionId.value === lead.id) {
descriptionId.value = null;
return;
}
descriptionId.value = lead.id;
if (descriptions.value[lead.id] !== undefined) return;
try {
descriptions.value[lead.id] = await store.fetchDescription(lead.id);
} catch (err) {
descriptionId.value = null;
fail(err);
}
}
async function toggleUnmatched() {
showUnmatched.value = !showUnmatched.value;
await fetchLeads();
}
// Run and poll
let pollTimer = null;
function stopPolling() {
clearTimeout(pollTimer);
pollTimer = null;
}
/** Poll until the run finishes, then reload what it changed. */
async function pollStatus() {
const current = await store.fetchStatus();
if (current?.running) {
pollTimer = setTimeout(pollStatus, POLL_MS);
return;
}
stopPolling();
if (current?.lastError) fail(current.lastError);
await Promise.all([fetchLeads(), sourcesBox.value?.refresh()]);
}
async function checkNow() {
try {
// false means a run was already going (the scheduler's, say); either way
// there is now one to wait for.
await store.runSync();
error.value = "";
status.value = { ...(status.value ?? {}), running: true };
stopPolling();
pollTimer = setTimeout(pollStatus, POLL_MS);
} catch (err) {
fail(err);
}
}
const running = computed(() => !!status.value?.running);
const lastRun = computed(() => {
if (running.value) return "Checking sources and scoring…";
if (!status.value?.lastRunAt) return "";
const when = new Date(status.value.lastRunAt).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
return `Last checked ${when}`;
});
onMounted(async () => {
await fetchLeads();
// Arriving mid-run (the scheduler's, or one started before a reload) should
// look the same as having pressed the button.
const current = await store.fetchStatus();
if (current?.running) pollTimer = setTimeout(pollStatus, POLL_MS);
});
onBeforeUnmount(stopPolling);
</script>
<template>
<div class="ja-root jl-root">
<div class="jl-header">
<div class="jl-header-left">
<RouterLink to="/cv/jobs" class="jl-back">← Tracker</RouterLink>
<h2 class="jl-heading">Job Leads</h2>
</div>
<div class="jl-header-right">
<span class="jl-hint">{{ lastRun }}</span>
<button
class="cv-btn cv-btn-primary"
:disabled="running"
title="Poll every source now, then score new leads. Profile and keyword changes take effect on a run."
@click="checkNow"
>
{{ running ? "Checking…" : "Check now" }}
</button>
</div>
</div>
<div v-if="error" class="jl-error" role="alert">
<span>{{ error }}</span>
<button class="cv-btn cv-btn-sm" @click="error = ''">Dismiss</button>
</div>
<JobSearchProfile @fail="fail" @ok="clearError" />
<JobSources ref="sourcesBox" @fail="fail" @ok="clearError" />
<div class="jl-tabs">
<button
v-for="t in TABS"
:key="t.value"
class="jl-tab"
:class="{ 'jl-tab-active': tab === t.value }"
@click="tab = t.value"
>
<span class="jl-tab-count">{{ counts[t.value] }}</span>
<span class="jl-tab-label">{{ t.label }}</span>
</button>
</div>
<div class="jl-filterbar">
<input v-model="search" class="ja-input" type="search" placeholder="Search title, company, location, reasons…" />
<label v-if="tab === 'new'" class="jl-check">
<input v-model="showLowScores" type="checkbox" />
Below {{ minScore }}<template v-if="hiddenLow"> ({{ hiddenLow }} hidden)</template>
</label>
<label v-if="tab === 'new'" class="jl-check" title="Postings the keyword filter rejected. They are never scored.">
<input :checked="showUnmatched" type="checkbox" @change="toggleUnmatched" />
Filtered out
</label>
</div>
<article
v-for="lead in visibleLeads"
:key="lead.id"
class="jl-lead"
:class="{ 'jl-lead-unmatched': !lead.matched && lead.state === 'new' }"
>
<div class="jl-score" :class="scoreClass(lead)" :title="lead.score == null ? 'Not scored' : `Fit score ${lead.score} out of 100`">
{{ lead.score ?? "–" }}
</div>
<div class="jl-lead-body">
<div class="jl-lead-title">
<a v-if="lead.url" :href="lead.url" target="_blank" rel="noopener" class="jl-link">{{ lead.jobTitle }}</a>
<span v-else>{{ lead.jobTitle }}</span>
<span class="jl-lead-company">{{ lead.company }}</span>
</div>
<div class="jl-lead-meta">
<span v-if="lead.location">{{ lead.location }}</span>
<span>{{ SOURCE_LABELS[lead.sourceKind] ?? lead.sourceKind }}</span>
<span>{{ ageLabel(lead) }}</span>
<span v-if="!lead.matched && lead.state === 'new'">filtered out</span>
</div>
<p v-if="lead.scoreReasons" class="jl-lead-reasons">{{ lead.scoreReasons }}</p>
<pre v-if="descriptionId === lead.id" class="jl-desc">{{
descriptions[lead.id] === undefined ? "Loading…" : descriptions[lead.id] || "The source gave no description."
}}</pre>
</div>
<div class="jl-lead-actions">
<button class="cv-btn cv-btn-sm" @click="toggleDescription(lead)">
{{ descriptionId === lead.id ? "Hide" : "Posting" }}
</button>
<template v-if="lead.state === 'new'">
<button
class="cv-btn cv-btn-sm cv-btn-primary"
:disabled="busyId === lead.id"
title="Add to the tracker as Saved"
@click="act(lead, 'promote')"
>
Track
</button>
<button class="cv-btn cv-btn-sm" :disabled="busyId === lead.id" @click="act(lead, 'dismiss')">Dismiss</button>
</template>
<button v-else-if="lead.state === 'dismissed'" class="cv-btn cv-btn-sm" :disabled="busyId === lead.id" @click="act(lead, 'restore')">
Restore
</button>
<RouterLink v-else to="/cv/jobs" class="cv-btn cv-btn-sm jl-btn-link">In tracker</RouterLink>
</div>
</article>
<p v-if="!visibleLeads.length" class="jl-empty">
<template v-if="loading">Loading…</template>
<template v-else-if="tab !== 'new'">Nothing here.</template>
<template v-else-if="hiddenLow">Nothing at or above {{ minScore }}. Tick "Below {{ minScore }}" to see the rest.</template>
<template v-else-if="!leads.length">No leads yet. Add a source above, then press "Check now".</template>
<template v-else>The inbox is empty.</template>
</p>
</div>
</template>
<!-- Unscoped on purpose, for the same reason as jobs-shared.css: the two child
components render the boxes these classes style, and a scoped rule stops
at a child's root element. Every selector is under .jl-root. -->
<style>
.jl-root .jl-box {
margin-bottom: 1rem;
padding: 0.75rem 1rem;
border: 1px solid var(--color-line-soft);
border-radius: 6px;
background: var(--color-paper);
}
.jl-root .jl-box-heading {
font-size: 1rem;
font-weight: 600;
color: var(--color-ink-soft);
cursor: pointer;
}
.jl-root .jl-box-heading > span {
margin-left: 0.6rem;
font-weight: 400;
}
.jl-root .jl-hint {
font-size: 0.8rem;
color: var(--color-ink-faint);
}
.jl-root p.jl-hint {
margin: 0.5rem 0 0;
}
.jl-root .jl-warn {
font-size: 0.8rem;
color: var(--color-ink-danger);
}
</style>
<style scoped>
/* Colours are the paper palette from CVLayout.vue; buttons are .cv-btn from
there too, and the inputs are styled by jobs-shared.css. The frame matches
the tracker page's (.ja-root and friends in JobApplications.vue), whose
rules are scoped to that component and so are repeated here. */
.jl-root {
padding: 1.5rem;
border-top: 2px solid var(--color-ink-soft);
background: var(--color-paper-tint);
}
.jl-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
}
.jl-header-left,
.jl-header-right {
display: flex;
align-items: center;
gap: 1rem;
}
.jl-back {
font-size: 0.85rem;
color: var(--color-ink-muted);
text-decoration: none;
}
.jl-back:hover {
color: var(--color-ink);
}
.jl-heading {
font-size: 1.1rem;
font-weight: 600;
color: var(--color-ink-soft);
}
.jl-error {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
margin-bottom: 1rem;
padding: 0.5rem 0.75rem;
border: 1px solid #b91c1c;
border-radius: 4px;
background: #fef2f2;
color: #7f1d1d;
font-size: 0.85rem;
}
.jl-tabs {
display: flex;
gap: 0.5rem;
margin-bottom: 0.75rem;
}
.jl-tab {
display: flex;
align-items: baseline;
gap: 0.4rem;
padding: 0.4rem 0.9rem;
border: 1px solid var(--color-line-soft);
border-radius: 6px;
background: var(--color-paper);
color: var(--color-ink-muted);
cursor: pointer;
}
.jl-tab-active {
border-color: var(--color-ink-soft);
color: var(--color-ink);
}
.jl-tab-count {
font-size: 1.05rem;
font-weight: 600;
}
.jl-tab-label {
font-size: 0.8rem;
}
.jl-filterbar {
display: flex;
align-items: center;
gap: 1rem;
margin-bottom: 0.75rem;
}
.jl-check {
display: flex;
align-items: center;
gap: 0.35rem;
font-size: 0.8rem;
color: var(--color-ink-muted);
white-space: nowrap;
cursor: pointer;
}
.jl-lead {
display: flex;
align-items: flex-start;
gap: 0.9rem;
margin-bottom: 0.5rem;
padding: 0.7rem 0.9rem;
border: 1px solid var(--color-line-soft);
border-radius: 6px;
background: var(--color-paper);
}
.jl-lead-unmatched {
opacity: 0.6;
}
/* The score reads as a number first; the tint only groups it. Same tints as
the tracker's status pills. */
.jl-score {
flex: 0 0 2.6rem;
padding: 0.35rem 0;
border-radius: 6px;
font-size: 1rem;
font-weight: 600;
text-align: center;
color: var(--color-ink-soft);
background: var(--color-paper-shade);
}
.jl-score-high {
background: #dcfce7;
color: #14532d;
}
.jl-score-mid {
background: #fef9c3;
color: #713f12;
}
.jl-score-none {
color: var(--color-ink-faint);
}
.jl-lead-body {
flex: 1;
min-width: 0;
}
.jl-lead-title {
font-size: 0.95rem;
font-weight: 600;
color: var(--color-ink);
}
.jl-lead-company {
margin-left: 0.5rem;
font-weight: 400;
color: var(--color-ink-muted);
}
.jl-link {
color: var(--color-ink-link);
text-decoration: none;
}
.jl-link:hover {
text-decoration: underline;
}
.jl-lead-meta {
display: flex;
flex-wrap: wrap;
gap: 0.25rem 0.9rem;
margin-top: 0.15rem;
font-size: 0.8rem;
color: var(--color-ink-faint);
}
.jl-lead-reasons {
margin: 0.4rem 0 0;
font-size: 0.85rem;
color: var(--color-ink-soft);
}
/* The posting text is long, so it scrolls inside the card. */
.jl-desc {
max-height: 22rem;
overflow: auto;
margin: 0.6rem 0 0;
padding: 0.6rem;
border: 1px solid var(--color-line-soft);
border-radius: 4px;
background: var(--color-paper-tint);
font-family: inherit;
font-size: 0.8rem;
white-space: pre-wrap;
}
.jl-lead-actions {
display: flex;
gap: 0.4rem;
white-space: nowrap;
}
.jl-btn-link {
text-decoration: none;
}
.jl-empty {
color: var(--color-ink-faint);
font-size: 0.9rem;
}
@media (max-width: 640px) {
.jl-header,
.jl-filterbar {
flex-wrap: wrap;
}
.jl-lead {
flex-wrap: wrap;
}
.jl-lead-body {
flex-basis: calc(100% - 3.5rem);
}
.jl-lead-actions {
flex-basis: 100%;
}
}
</style>
+167
View File
@@ -0,0 +1,167 @@
<script setup>
/**
* The "Search profile" box on `/cv/leads`: what a lead is judged against.
* Rendered only by JobLeads.vue; data comes from stores/jobSearchProfile.js.
*
* Two different things are edited here. The keyword lists drive a cheap
* filter on the server that decides which postings are shown and scored at
* all; the profile text is what Claude scores those against. Both take effect
* on the next run, not on save — the parent says so beside "Check now".
*
* Like JobReferences.vue it has no error display of its own: failures are
* emitted as `fail` and successes as `ok`, for the page's single banner.
*/
import { ref, computed, watch, onMounted } from "vue";
import { storeToRefs } from "pinia";
import { useJobSearchProfileStore } from "@/stores/jobSearchProfile";
import "./jobs-shared.css";
const emit = defineEmits(["fail", "ok"]);
const store = useJobSearchProfileStore();
const { profile } = storeToRefs(store);
const blank = () => ({ profile: "", includeKeywords: "", excludeKeywords: "", locations: "", minScore: 60 });
const form = ref(blank());
const saving = ref(false);
function reset() {
form.value = profile.value
? {
profile: profile.value.profile,
includeKeywords: profile.value.includeKeywords,
excludeKeywords: profile.value.excludeKeywords,
locations: profile.value.locations,
minScore: profile.value.minScore,
}
: blank();
}
watch(profile, reset);
const dirty = computed(
() => !!profile.value && Object.keys(form.value).some((key) => form.value[key] !== profile.value[key]),
);
// Open by default until there is something in it: an empty profile means no
// lead is ever scored, which is worth making obvious.
const isEmpty = computed(() => !!profile.value && !profile.value.profile.trim());
async function save() {
saving.value = true;
try {
await store.save({ ...form.value, minScore: Number(form.value.minScore) || 0 });
emit("ok");
} catch (err) {
emit("fail", err);
} finally {
saving.value = false;
}
}
onMounted(async () => {
await store.fetch();
if (store.error) emit("fail", store.error);
reset();
});
</script>
<template>
<details class="jl-box" :open="isEmpty">
<summary class="jl-box-heading">
Search profile
<span v-if="isEmpty" class="jl-warn">empty — leads will not be scored</span>
</summary>
<form class="jl-profile" @submit.prevent="save">
<label class="jl-field jl-field-wide">
<span>About you and what you want</span>
<textarea
v-model="form.profile"
class="ja-input jl-textarea"
rows="8"
placeholder="Experience, skills, the kind of role, level, location and working arrangement you are after. Each lead is scored against this text and nothing else."
></textarea>
</label>
<label class="jl-field">
<span>Title must include one of</span>
<textarea v-model="form.includeKeywords" class="ja-input jl-textarea" rows="4" placeholder="engineer&#10;developer"></textarea>
</label>
<label class="jl-field">
<span>Title must not include</span>
<textarea v-model="form.excludeKeywords" class="ja-input jl-textarea" rows="4" placeholder="intern&#10;principal"></textarea>
</label>
<label class="jl-field">
<span>Location must include one of</span>
<textarea v-model="form.locations" class="ja-input jl-textarea" rows="4" placeholder="london&#10;remote"></textarea>
</label>
<p class="jl-hint jl-field-wide">
One entry per line; an empty list is no restriction. Title keywords match whole words, so
"intern" does not exclude "Internal". Only leads that pass are shown and scored.
</p>
<div class="jl-profile-actions jl-field-wide">
<label class="jl-inline">
Hide leads scoring below
<input v-model="form.minScore" class="ja-input jl-num" type="number" min="0" max="100" />
</label>
<button type="button" class="cv-btn cv-btn-sm" :disabled="!dirty || saving" @click="reset">Reset</button>
<button type="submit" class="cv-btn cv-btn-sm cv-btn-primary" :disabled="!dirty || saving">
{{ saving ? "Saving…" : "Save" }}
</button>
</div>
</form>
</details>
</template>
<style scoped>
/* The box and its heading (.jl-box, .jl-box-heading, .jl-hint, .jl-warn) are
in JobLeads.vue's unscoped block, shared with JobSources.vue. */
.jl-profile {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 0.75rem;
margin-top: 0.75rem;
}
.jl-field {
display: flex;
flex-direction: column;
gap: 0.25rem;
font-size: 0.8rem;
color: var(--color-ink-muted);
}
.jl-field-wide {
grid-column: 1 / -1;
}
.jl-textarea {
resize: vertical;
font-family: inherit;
line-height: 1.4;
}
.jl-profile-actions {
display: flex;
align-items: center;
gap: 0.5rem;
}
.jl-inline {
display: flex;
align-items: center;
gap: 0.5rem;
margin-right: auto;
font-size: 0.8rem;
color: var(--color-ink-muted);
}
.jl-num {
flex: 0 0 4.5rem;
min-width: 0;
}
@media (max-width: 640px) {
.jl-profile {
grid-template-columns: 1fr;
}
}
</style>
+198
View File
@@ -0,0 +1,198 @@
<script setup>
/**
* The "Sources" box on `/cv/leads`: the watch list the lead fetcher polls.
* Rendered only by JobLeads.vue; data comes from stores/jobSources.js.
*
* A source is either one company's job board (Greenhouse, Lever, Ashby —
* identified by the slug in the board's URL) or a keyword search (Adzuna,
* Reed — which need API keys set on the admin panel's Environment tab). The
* kinds are a COPY of the list in backend/services/job_sources.go; the server
* rejects any other.
*
* Like JobReferences.vue it has no error display of its own: failures are
* emitted as `fail` and successes as `ok`, for the page's single banner.
*/
import { ref, computed, onMounted } from "vue";
import { storeToRefs } from "pinia";
import { useJobSourcesStore } from "@/stores/jobSources";
import "./jobs-shared.css";
const emit = defineEmits(["fail", "ok"]);
const KINDS = [
{ value: "greenhouse", label: "Greenhouse", board: true, hint: "boards.greenhouse.io/<slug>" },
{ value: "lever", label: "Lever", board: true, hint: "jobs.lever.co/<slug>" },
{ value: "ashby", label: "Ashby", board: true, hint: "jobs.ashbyhq.com/<slug>" },
{ value: "adzuna", label: "Adzuna search", board: false },
{ value: "reed", label: "Reed search", board: false },
];
const kindOf = (value) => KINDS.find((k) => k.value === value) ?? { label: value, board: true };
const store = useJobSourcesStore();
const { sources } = storeToRefs(store);
const blank = (kind = "greenhouse") => ({ kind, label: "", token: "", query: "", location: "" });
const form = ref(blank());
const formKind = computed(() => kindOf(form.value.kind));
async function fetchSources() {
// The store's fetch() records its failure instead of throwing.
await store.fetch();
if (store.error) emit("fail", store.error);
}
defineExpose({ refresh: fetchSources });
async function createSource() {
try {
await store.create({ ...form.value });
form.value = blank(form.value.kind);
emit("ok");
} catch (err) {
emit("fail", err);
}
}
async function toggleEnabled(source) {
try {
await store.update(source.id, { enabled: !source.enabled });
emit("ok");
} catch (err) {
emit("fail", err);
}
}
async function deleteSource(source) {
// Its leads stay: the server keeps them so that re-adding the source does
// not bring back everything already dismissed.
if (!confirm(`Stop watching ${source.label}? Leads already found are kept.`)) return;
try {
await store.remove(source.id);
emit("ok");
} catch (err) {
emit("fail", err);
}
}
function describe(source) {
if (kindOf(source.kind).board) return source.token;
return source.location ? `"${source.query}" in ${source.location}` : `"${source.query}"`;
}
function lastPoll(source) {
if (!source.lastFetchedAt) return "not polled yet";
const when = new Date(source.lastFetchedAt).toLocaleString(undefined, { dateStyle: "medium", timeStyle: "short" });
return `${source.lastCount} listed · ${when}`;
}
onMounted(fetchSources);
</script>
<template>
<details class="jl-box" :open="!sources.length">
<summary class="jl-box-heading">
Sources
<span class="jl-hint">{{ sources.filter((s) => s.enabled).length }} watched</span>
<span v-if="sources.some((s) => s.lastError)" class="jl-warn">one or more failing</span>
</summary>
<div v-for="source in sources" :key="source.id" class="jl-source" :class="{ 'jl-source-off': !source.enabled }">
<span class="jl-source-kind">{{ kindOf(source.kind).label }}</span>
<span class="jl-source-label">{{ source.label }}</span>
<span class="jl-source-what" :title="describe(source)">{{ describe(source) }}</span>
<span v-if="source.lastError" class="jl-warn jl-source-status" :title="source.lastError">{{ source.lastError }}</span>
<span v-else class="jl-hint jl-source-status">{{ lastPoll(source) }}</span>
<button class="cv-btn cv-btn-sm" @click="toggleEnabled(source)">
{{ source.enabled ? "Pause" : "Resume" }}
</button>
<button class="cv-btn cv-btn-sm cv-btn-danger" @click="deleteSource(source)">Delete</button>
</div>
<p v-if="!sources.length" class="jl-hint">
Nothing is being watched. Add a company's job board, or a keyword search, below.
</p>
<form class="jl-source-form" @submit.prevent="createSource">
<select v-model="form.kind" class="ja-input ja-select">
<option v-for="k in KINDS" :key="k.value" :value="k.value">{{ k.label }}</option>
</select>
<template v-if="formKind.board">
<input v-model="form.label" class="ja-input" placeholder="Company name *" required />
<input v-model="form.token" class="ja-input" :placeholder="`Board slug * — ${formKind.hint}`" required />
</template>
<template v-else>
<input v-model="form.query" class="ja-input" placeholder="Keywords * — e.g. golang backend" required />
<input v-model="form.location" class="ja-input" placeholder="Location — e.g. London" />
</template>
<button type="submit" class="cv-btn cv-btn-primary">Add</button>
</form>
<p v-if="!formKind.board" class="jl-hint">
{{ formKind.label }} needs its API key set under Admin → Environment → Job leads.
</p>
</details>
</template>
<style scoped>
/* The box and its heading (.jl-box, .jl-box-heading, .jl-hint, .jl-warn) are
in JobLeads.vue's unscoped block, shared with JobSearchProfile.vue. */
.jl-source {
display: flex;
align-items: center;
gap: 0.6rem;
padding: 0.3rem 0;
font-size: 0.85rem;
}
.jl-source:first-of-type {
margin-top: 0.75rem;
}
.jl-source-off {
opacity: 0.55;
}
.jl-source-kind {
flex: 0 0 6.5rem;
color: var(--color-ink-muted);
}
.jl-source-label {
flex: 0 0 9rem;
font-weight: 500;
color: var(--color-ink-soft);
}
.jl-source-what {
flex: 1 1 6rem;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
color: var(--color-ink-muted);
}
.jl-source-status {
flex: 1 1 10rem;
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: right;
}
.jl-source-form {
display: flex;
gap: 0.5rem;
margin-top: 0.75rem;
flex-wrap: wrap;
}
@media (max-width: 640px) {
.jl-source {
flex-wrap: wrap;
}
.jl-source-status {
flex-basis: 100%;
text-align: left;
}
}
</style>