Harden job-application tracker: backend fixes, tests, UI rework
Deploy with Docker Compose / deploy (push) Successful in 1m8s

Backend (email sync + resolvers):
- Sync window anchored on latest received_at with slack + rewind age-out
- Skip ctx-cancelled per-email side effects
- Soft-deleted applications no longer block pipeline matching
- Status normalization shared between pipeline and resolvers, with tests
- Reject empty jobTitle/company on create/update
- IMAP fallback synthesizes Message-ID from stable message traits
- Consistent list ordering with id tie-break

Frontend (JobApplications.vue):
- Unified status vocabulary with pipeline (lowercase keys)
- Emptied optional fields now clear on save; row stays open on failure
- URL editable, notes textarea, appliedAt defaults to today
- Error banner, delete confirmations, inline status select
- Search, sortable columns, status-count filter tiles, stale-row marker
- CSV export with UTF-8 BOM + CRLF

Tests: stdlib table-driven tests for sync, status, auth, handlers.

Co-Authored-By: Claude Code <[email protected]>
This commit is contained in:
2026-09-22 22:31:30 +01:00
co-authored by Claude Code
parent 8effc3de83
commit 50c2fdfdd1
9 changed files with 1605 additions and 112 deletions
+484 -79
View File
@@ -5,21 +5,49 @@
* Two independent CRUD tables over GraphQL; editing is inline via an `editingId`
* plus a scratch copy of the row.
*/
import { ref, onMounted } from "vue";
import { ref, computed, onMounted } from "vue";
import { RouterLink } from "vue-router";
import { gql } from "@/graphql";
const applications = ref([]);
const editingId = ref(null);
const editForm = ref({});
const error = ref("");
/**
* The status vocabulary is the email pipeline's (services.statusOrder), not a
* separate UI list: the pipeline writes these lowercase keys, and a status it
* does not rank switches its forward-only progression guard off for that row.
* Labels are display-only.
*/
const STATUS_OPTIONS = [
{ value: "applied", label: "Applied" },
{ value: "screening", label: "Screening" },
{ value: "assessment", label: "Assessment" },
{ value: "interviewing", label: "Interviewing" },
{ value: "offer", label: "Offer" },
{ value: "rejected", label: "Rejected" },
{ value: "withdrawn", label: "Withdrawn" },
];
// Statuses still in play — used to decide whether a row is worth chasing.
const OPEN_STATUSES = ["applied", "screening", "assessment", "interviewing"];
const STALE_DAYS = 14;
function today() {
return new Date().toISOString().substring(0, 10);
}
const form = ref({
jobTitle: "",
company: "",
location: "",
url: "",
status: "Applied",
status: "applied",
notes: "",
appliedAt: "",
// Logging an application on the day you send it is the common case, so the
// date defaults to today rather than landing null and ageing as unknown.
appliedAt: today(),
});
const references = ref([]);
@@ -29,32 +57,38 @@ const editRefForm = ref({});
const REF_CATEGORIES = ["profile", "experience"];
const REF_FIELDS = `id category label value sortOrder createdAt`;
const STATUS_OPTIONS = [
"Applied",
"Screening",
"Interview",
"Offer",
"Rejected",
"Withdrawn",
];
const APP_FIELDS = `id jobTitle company location url status notes appliedAt createdAt updatedAt`;
const APP_FIELDS = `id jobTitle company location url status notes appliedAt createdAt`;
// Filter/sort state. All of it runs over the already-loaded array — the query
// has no arguments and the dataset is one person's applications.
const search = ref("");
const statusFilter = ref(null);
const sortKey = ref("updatedAt");
const sortDir = ref("desc");
function fail(err) {
console.error(err);
// The realistic failure here is a lapsed 7-day cookie: the router guard only
// checks the in-memory admin flag, so every mutation returns "admin access
// required" while the page still looks signed in.
error.value = String(err?.message ?? err);
}
async function fetchApplications() {
try {
const data = await gql(`query { jobApplications { ${APP_FIELDS} } }`);
applications.value = data.jobApplications;
} catch (err) {
console.error(err);
fail(err);
}
}
async function createApplication() {
if (!form.value.jobTitle || !form.value.company || !form.value.status) return;
if (!form.value.jobTitle.trim() || !form.value.company.trim()) return;
try {
const input = {
jobTitle: form.value.jobTitle,
company: form.value.company,
jobTitle: form.value.jobTitle.trim(),
company: form.value.company.trim(),
status: form.value.status,
location: form.value.location || undefined,
url: form.value.url || undefined,
@@ -75,16 +109,22 @@ async function createApplication() {
company: "",
location: "",
url: "",
status: "Applied",
status: "applied",
notes: "",
appliedAt: "",
appliedAt: today(),
};
error.value = "";
} catch (err) {
console.error(err);
fail(err);
}
}
function startEdit(app) {
// Switching rows mid-edit would throw away unsaved typing silently, and the
// Edit button sits in every row, so the misclick is easy to make.
if (editingId.value !== null && editingId.value !== app.id && isEditDirty()) {
if (!confirm("Discard unsaved changes to the row you are editing?")) return;
}
editingId.value = app.id;
editForm.value = {
jobTitle: app.jobTitle,
@@ -97,6 +137,21 @@ function startEdit(app) {
};
}
function isEditDirty() {
const app = applications.value.find((a) => a.id === editingId.value);
if (!app) return false;
const e = editForm.value;
return (
e.jobTitle !== app.jobTitle ||
e.company !== app.company ||
e.location !== (app.location ?? "") ||
e.url !== (app.url ?? "") ||
e.status !== app.status ||
e.notes !== (app.notes ?? "") ||
e.appliedAt !== (app.appliedAt ? app.appliedAt.substring(0, 10) : "")
);
}
function cancelEdit() {
editingId.value = null;
editForm.value = {};
@@ -104,13 +159,18 @@ function cancelEdit() {
async function saveEdit(id) {
try {
// Optional fields send `''` rather than `undefined` when emptied: the
// resolver skips fields that are absent, so `|| undefined` would turn
// "delete this wrong URL" into a silent no-op that re-renders the old
// value. appliedAt has no empty representation, so clearing it is not
// offered — the field stays as it was.
const input = {
jobTitle: editForm.value.jobTitle || undefined,
company: editForm.value.company || undefined,
status: editForm.value.status || undefined,
location: editForm.value.location || undefined,
url: editForm.value.url || undefined,
notes: editForm.value.notes || undefined,
jobTitle: editForm.value.jobTitle,
company: editForm.value.company,
status: editForm.value.status,
location: editForm.value.location ?? "",
url: editForm.value.url ?? "",
notes: editForm.value.notes ?? "",
appliedAt: editForm.value.appliedAt
? new Date(editForm.value.appliedAt).toISOString()
: undefined,
@@ -124,20 +184,46 @@ async function saveEdit(id) {
const idx = applications.value.findIndex((a) => a.id === id);
if (idx !== -1) applications.value[idx] = data.updateJobApplication;
editingId.value = null;
error.value = "";
} catch (err) {
console.error(err);
// editingId is deliberately left set: the row stays open with the typing
// intact so the save can be retried.
fail(err);
}
}
async function deleteApplication(id) {
/** Status is the field that changes most, so it is editable straight from the pill. */
async function setStatus(app, status) {
if (status === app.status) return;
try {
const data = await gql(
`mutation UpdateJobApplication($id: ID!, $input: UpdateJobApplicationInput!) {
updateJobApplication(id: $id, input: $input) { ${APP_FIELDS} }
}`,
{ id: app.id, input: { status } },
);
const idx = applications.value.findIndex((a) => a.id === app.id);
if (idx !== -1) applications.value[idx] = data.updateJobApplication;
error.value = "";
} catch (err) {
fail(err);
}
}
async function deleteApplication(app) {
// Delete sits next to Edit in a 0.4rem-gap row and the notes it takes with
// it are not recoverable through any UI path.
if (!confirm(`Delete the ${app.jobTitle} application at ${app.company}?`))
return;
try {
await gql(
`mutation DeleteJobApplication($id: ID!) { deleteJobApplication(id: $id) }`,
{ id },
{ id: app.id },
);
applications.value = applications.value.filter((a) => a.id !== id);
applications.value = applications.value.filter((a) => a.id !== app.id);
error.value = "";
} catch (err) {
console.error(err);
fail(err);
}
}
@@ -163,8 +249,13 @@ function exportCsv() {
a.createdAt ? a.createdAt.substring(0, 10) : "",
]);
const escape = (v) => `"${String(v).replace(/"/g, '""')}"`;
const csv = [headers, ...rows].map((r) => r.map(escape).join(",")).join("\n");
const blob = new Blob([csv], { type: "text/csv" });
// CRLF joins and a BOM because the destination for an exported tracker is
// Excel, which otherwise reads the UTF-8 as the local ANSI codepage (so "£"
// and accents arrive mangled) and mis-splits LF-only rows.
const csv =
"\ufeff" +
[headers, ...rows].map((r) => r.map(escape).join(",")).join("\r\n");
const blob = new Blob([csv], { type: "text/csv;charset=utf-8" });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
@@ -178,7 +269,7 @@ async function fetchReferences() {
const data = await gql(`query { jobAppReferences { ${REF_FIELDS} } }`);
references.value = data.jobAppReferences;
} catch (err) {
console.error(err);
fail(err);
}
}
@@ -198,8 +289,9 @@ async function createReference() {
);
references.value.push(data.createJobAppReference);
refForm.value = { category: refForm.value.category, label: "", value: "" };
error.value = "";
} catch (err) {
console.error(err);
fail(err);
}
}
@@ -233,20 +325,23 @@ async function saveRefEdit(id) {
const idx = references.value.findIndex((r) => r.id === id);
if (idx !== -1) references.value[idx] = data.updateJobAppReference;
editingRefId.value = null;
error.value = "";
} catch (err) {
console.error(err);
fail(err);
}
}
async function deleteReference(id) {
async function deleteReference(ref) {
if (!confirm(`Delete the reference "${ref.label}"?`)) return;
try {
await gql(
`mutation DeleteJobAppReference($id: ID!) { deleteJobAppReference(id: $id) }`,
{ id },
{ id: ref.id },
);
references.value = references.value.filter((r) => r.id !== id);
references.value = references.value.filter((r) => r.id !== ref.id);
error.value = "";
} catch (err) {
console.error(err);
fail(err);
}
}
@@ -258,16 +353,83 @@ function copyToClipboard(text) {
navigator.clipboard.writeText(text);
}
function statusLabel(status) {
return (
STATUS_OPTIONS.find((s) => s.value === status?.toLowerCase())?.label ??
status
);
}
function statusClass(status) {
const map = {
Applied: "bg-blue-100 text-blue-800",
Screening: "bg-yellow-100 text-yellow-800",
Interview: "bg-violet-100 text-violet-800",
Offer: "bg-green-100 text-green-800",
Rejected: "bg-red-100 text-red-800",
Withdrawn: "bg-gray-100 text-gray-500",
};
return map[status] ?? "bg-gray-200 text-gray-700";
return `ja-badge-${status?.toLowerCase() ?? "unknown"}`;
}
/** Whole days between a timestamp and now; null when there is no date. */
function daysSince(iso) {
if (!iso) return null;
return Math.floor((Date.now() - new Date(iso).getTime()) / 86400000);
}
function ageLabel(app) {
// createdAt is the fallback: an application logged without an applied date
// still has a meaningful age.
const days = daysSince(app.appliedAt ?? app.createdAt);
return days === null ? "—" : days === 0 ? "today" : `${days}d`;
}
/** A row worth chasing: still open, and nothing has moved it in a fortnight. */
function isStale(app) {
if (!OPEN_STATUSES.includes(app.status?.toLowerCase())) return false;
const days = daysSince(app.updatedAt ?? app.createdAt);
return days !== null && days >= STALE_DAYS;
}
const statusCounts = computed(() => {
const counts = {};
for (const app of applications.value) {
const key = app.status?.toLowerCase();
counts[key] = (counts[key] ?? 0) + 1;
}
return counts;
});
const visibleApplications = computed(() => {
const q = search.value.trim().toLowerCase();
const rows = applications.value.filter((app) => {
if (statusFilter.value && app.status?.toLowerCase() !== statusFilter.value)
return false;
if (!q) return true;
// Notes are searched because the email pipeline appends its findings
// there, making them the de-facto history of the application.
return [app.jobTitle, app.company, app.location, app.notes]
.filter(Boolean)
.some((field) => field.toLowerCase().includes(q));
});
const dir = sortDir.value === "asc" ? 1 : -1;
return [...rows].sort((a, b) => {
const av = a[sortKey.value] ?? "";
const bv = b[sortKey.value] ?? "";
// Rows missing the sort field go last in either direction rather than
// clustering at whichever end empty-string happens to sort to.
if (!av && bv) return 1;
if (av && !bv) return -1;
if (av === bv) return 0;
return av > bv ? dir : -dir;
});
});
function toggleSort(key) {
if (sortKey.value === key) {
sortDir.value = sortDir.value === "asc" ? "desc" : "asc";
} else {
sortKey.value = key;
sortDir.value = "desc";
}
}
function toggleStatusFilter(status) {
statusFilter.value = statusFilter.value === status ? null : status;
}
onMounted(() => {
@@ -292,6 +454,11 @@ onMounted(() => {
</button>
</div>
<div v-if="error" class="ja-error" role="alert">
<span>{{ error }}</span>
<button class="cv-btn cv-btn-sm" @click="error = ''">Dismiss</button>
</div>
<div class="ja-ref-section">
<h3 class="ja-ref-heading">Quick Reference</h3>
<div v-for="cat in REF_CATEGORIES" :key="cat" class="ja-ref-category">
@@ -316,7 +483,7 @@ onMounted(() => {
</button>
<button
class="cv-btn cv-btn-sm cv-btn-danger"
@click="deleteReference(ref.id)"
@click="deleteReference(ref)"
>
Delete
</button>
@@ -392,8 +559,8 @@ onMounted(() => {
required
/>
<select v-model="form.status" class="ja-input ja-select">
<option v-for="s in STATUS_OPTIONS" :key="s" :value="s">
{{ s }}
<option v-for="s in STATUS_OPTIONS" :key="s.value" :value="s.value">
{{ s.label }}
</option>
</select>
</div>
@@ -421,22 +588,48 @@ onMounted(() => {
</div>
</form>
<table class="ja-table" v-if="applications.length">
<!-- Pipeline bar: counts at a glance, each one a filter toggle. -->
<div class="ja-pipeline" v-if="applications.length">
<button
v-for="s in STATUS_OPTIONS"
:key="s.value"
class="ja-pipe-tile"
:class="{ 'ja-pipe-active': statusFilter === s.value }"
@click="toggleStatusFilter(s.value)"
>
<span class="ja-pipe-count">{{ statusCounts[s.value] ?? 0 }}</span>
<span class="ja-pipe-label">{{ s.label }}</span>
</button>
</div>
<div class="ja-filterbar" v-if="applications.length">
<input
v-model="search"
class="ja-input"
type="search"
placeholder="Search title, company, location, notes…"
/>
<span class="ja-count"
>{{ visibleApplications.length }} / {{ applications.length }}</span
>
</div>
<table class="ja-table" v-if="visibleApplications.length">
<thead>
<tr>
<th>Title</th>
<th>Company</th>
<th>Status</th>
<th class="ja-sortable" @click="toggleSort('jobTitle')">Title</th>
<th class="ja-sortable" @click="toggleSort('company')">Company</th>
<th class="ja-sortable" @click="toggleSort('status')">Status</th>
<th>Location</th>
<th>Applied</th>
<th class="ja-sortable" @click="toggleSort('appliedAt')">Applied</th>
<th>Notes</th>
<th></th>
</tr>
</thead>
<tbody>
<template v-for="app in applications" :key="app.id">
<tr v-if="editingId !== app.id">
<td>
<template v-for="app in visibleApplications" :key="app.id">
<tr v-if="editingId !== app.id" :class="{ 'ja-stale': isStale(app) }">
<td data-label="Title">
<a
v-if="app.url"
:href="app.url"
@@ -447,70 +640,107 @@ onMounted(() => {
>
<span v-else>{{ app.jobTitle }}</span>
</td>
<td>{{ app.company }}</td>
<td>
<span :class="['ja-badge', statusClass(app.status)]">{{
app.status
}}</span>
<td data-label="Company">{{ app.company }}</td>
<td data-label="Status">
<select
class="ja-badge ja-badge-select"
:class="statusClass(app.status)"
:value="app.status?.toLowerCase()"
@change="setStatus(app, $event.target.value)"
>
<option
v-for="s in STATUS_OPTIONS"
:key="s.value"
:value="s.value"
>
{{ s.label }}
</option>
<!-- A status the pipeline wrote that we no longer list still
needs to render rather than showing a blank select. -->
<option
v-if="!STATUS_OPTIONS.some((s) => s.value === app.status)"
:value="app.status"
>
{{ statusLabel(app.status) }}
</option>
</select>
</td>
<td data-label="Location">{{ app.location || "—" }}</td>
<td
data-label="Applied"
:title="app.appliedAt ? app.appliedAt.substring(0, 10) : ''"
>
{{ ageLabel(app) }}
</td>
<td class="ja-notes-cell" data-label="Notes" :title="app.notes">
{{ app.notes ?? "" }}
</td>
<td>{{ app.location ?? "—" }}</td>
<td>{{ app.appliedAt ? app.appliedAt.substring(0, 10) : "—" }}</td>
<td class="ja-notes-cell">{{ app.notes ?? "" }}</td>
<td class="ja-actions">
<button class="cv-btn cv-btn-sm" @click="startEdit(app)">
Edit
</button>
<button
class="cv-btn cv-btn-sm cv-btn-danger"
@click="deleteApplication(app.id)"
@click="deleteApplication(app)"
>
Delete
</button>
</td>
</tr>
<tr v-else class="ja-edit-row">
<td>
<td data-label="Title">
<input
v-model="editForm.jobTitle"
class="ja-input ja-input-sm"
placeholder="Job title"
/>
<input
v-model="editForm.url"
class="ja-input ja-input-sm"
placeholder="URL"
/>
</td>
<td>
<td data-label="Company">
<input
v-model="editForm.company"
class="ja-input ja-input-sm"
placeholder="Company"
/>
</td>
<td>
<td data-label="Status">
<select
v-model="editForm.status"
class="ja-input ja-input-sm ja-select"
>
<option v-for="s in STATUS_OPTIONS" :key="s" :value="s">
{{ s }}
<option
v-for="s in STATUS_OPTIONS"
:key="s.value"
:value="s.value"
>
{{ s.label }}
</option>
</select>
</td>
<td>
<td data-label="Location">
<input
v-model="editForm.location"
class="ja-input ja-input-sm"
placeholder="Location"
/>
</td>
<td>
<td data-label="Applied">
<input
v-model="editForm.appliedAt"
class="ja-input ja-input-sm"
type="date"
/>
</td>
<td>
<input
<td data-label="Notes">
<!-- Textarea, not an input: the pipeline appends newline-joined
findings here, so notes are routinely multi-line. -->
<textarea
v-model="editForm.notes"
class="ja-input ja-input-sm"
class="ja-input ja-input-sm ja-edit-notes"
placeholder="Notes"
/>
</td>
@@ -529,6 +759,9 @@ onMounted(() => {
</template>
</tbody>
</table>
<p v-else-if="applications.length" class="ja-empty">
No applications match this filter.
</p>
<p v-else class="ja-empty">No applications yet.</p>
</div>
</template>
@@ -570,6 +803,20 @@ onMounted(() => {
color: var(--color-ink-soft);
}
.ja-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;
}
/* Forms */
.ja-form {
display: flex;
@@ -615,6 +862,65 @@ onMounted(() => {
min-width: 0;
}
.ja-edit-notes {
resize: vertical;
min-height: 3.5rem;
}
/* Pipeline bar */
.ja-pipeline {
display: flex;
gap: 0.4rem;
flex-wrap: wrap;
margin-bottom: 0.75rem;
}
.ja-pipe-tile {
display: flex;
flex-direction: column;
align-items: center;
gap: 0.1rem;
padding: 0.4rem 0.7rem;
border: 1px solid var(--color-line-soft);
border-radius: 4px;
background: var(--color-paper);
cursor: pointer;
min-width: 68px;
}
.ja-pipe-tile:hover {
background: var(--color-paper-shade);
}
.ja-pipe-active {
border-color: var(--color-ink);
background: var(--color-paper-shade);
}
.ja-pipe-count {
font-size: 1rem;
font-weight: 600;
color: var(--color-ink-soft);
}
.ja-pipe-label {
font-size: 0.7rem;
color: var(--color-ink-muted);
}
.ja-filterbar {
display: flex;
align-items: center;
gap: 0.75rem;
margin-bottom: 0.75rem;
}
.ja-count {
font-size: 0.8rem;
color: var(--color-ink-faint);
white-space: nowrap;
}
/* Applications table */
.ja-table {
width: 100%;
@@ -636,12 +942,27 @@ onMounted(() => {
background: var(--color-paper-shade);
}
.ja-sortable {
cursor: pointer;
user-select: none;
}
.ja-sortable:hover {
color: var(--color-ink);
}
.ja-table tr:hover td {
background: var(--color-paper-shade);
}
/* Open for a fortnight with nothing moving — the follow-up queue. */
.ja-stale td:first-child {
box-shadow: inset 3px 0 0 var(--color-ink-muted);
}
.ja-edit-row td {
padding: 0.3rem 0.4rem;
vertical-align: top;
}
.ja-actions {
@@ -666,13 +987,51 @@ onMounted(() => {
text-decoration: underline;
}
/* Status pill; colour classes come from statusClass() */
/* Status pill, doubling as an inline select. Palette is CVLayout's paper
tokens with a per-status tint, rather than off-theme Tailwind colours. */
.ja-badge {
display: inline-block;
padding: 0.15rem 0.5rem;
border-radius: 10px;
font-size: 0.78rem;
font-weight: 500;
border: 1px solid var(--color-line);
background: var(--color-paper-shade);
color: var(--color-ink-soft);
}
.ja-badge-select {
cursor: pointer;
appearance: none;
}
.ja-badge-applied {
background: #eef2ff;
color: #3730a3;
}
.ja-badge-screening {
background: #fefce8;
color: #854d0e;
}
.ja-badge-assessment {
background: #fff7ed;
color: #9a3412;
}
.ja-badge-interviewing {
background: #f5f3ff;
color: #5b21b6;
}
.ja-badge-offer {
background: #f0fdf4;
color: #166534;
}
.ja-badge-rejected {
background: #fef2f2;
color: #991b1b;
}
.ja-badge-withdrawn {
background: var(--color-paper-shade);
color: var(--color-ink-faint);
}
.ja-empty {
@@ -743,4 +1102,50 @@ onMounted(() => {
margin-top: 0.75rem;
flex-wrap: wrap;
}
/* Seven columns plus an action cell will not fit a phone, so the table becomes
stacked cards with the header text carried by each cell's data-label. */
@media (max-width: 640px) {
.ja-table thead {
display: none;
}
.ja-table,
.ja-table tbody,
.ja-table tr,
.ja-table td {
display: block;
width: 100%;
}
.ja-table tr {
margin-bottom: 0.75rem;
border: 1px solid var(--color-line-soft);
border-radius: 6px;
background: var(--color-paper);
}
.ja-table td {
border-bottom: none;
padding: 0.3rem 0.6rem;
}
.ja-table td[data-label]::before {
content: attr(data-label);
display: block;
font-size: 0.7rem;
text-transform: uppercase;
color: var(--color-ink-faint);
}
.ja-notes-cell {
max-width: none;
white-space: pre-wrap;
overflow: visible;
}
.ja-stale td:first-child {
box-shadow: inset 0 3px 0 var(--color-ink-muted);
}
}
</style>