Give the job tracker stores and fix the admin route guard

createCrudStore captures the places store's pattern and now backs
places, job applications and job references. JobApplications.vue no
longer calls gql() itself and is split into the applications table, the
references table and the add form, with the status vocabulary in
jobStatus.js.

api.js is a thin REST client that turns failures into an ApiError
carrying the backend's message; the admin views and Listening.vue use it
in place of raw axios and fetch.

The router guard waited on the home query's loaded flag, which is never
set when that query fails, so /admin and /cv/jobs could hang. It now
awaits a standalone me query owned by the auth store, and homeData gains
a settled flag for widgets that only need to know the fetch finished.

The Vite proxy targets are configurable through VITE_PROXY_*, and
build:js runs the Vite build without wasm-pack.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 14:39:19 +01:00
co-authored by Claude Opus 5.5
parent 71344a1f8d
commit d3f722d077
26 changed files with 1176 additions and 681 deletions
+15 -10
View File
@@ -8,7 +8,7 @@
* the response to generating it, and replacing it needs no restart.
*/
import { ref, onMounted } from "vue";
import axios from "axios";
import { api } from "@/api";
import Button from "@/components/input/Button.vue";
import SecretReveal from "@/components/admin/SecretReveal.vue";
import "./env.css";
@@ -22,11 +22,12 @@ const newToken = ref("");
async function fetchCaptureToken() {
try {
capture.value = (await axios.get("/api/admin/capture-token")).data;
capture.value = await api.get("/admin/capture-token", {
fallback: "Failed to load the capture token state",
});
error.value = "";
} catch (err) {
error.value =
err.response?.data?.error || "Failed to load the capture token state";
error.value = err.message;
}
}
@@ -42,12 +43,14 @@ async function generate() {
return;
busy.value = true;
try {
const res = await axios.post("/api/admin/capture-token");
newToken.value = res.data.token;
capture.value = { set: true, createdAt: res.data.createdAt };
const res = await api.post("/admin/capture-token", undefined, {
fallback: "Failed to generate a token",
});
newToken.value = res.token;
capture.value = { set: true, createdAt: res.createdAt };
error.value = "";
} catch (err) {
error.value = err.response?.data?.error || "Failed to generate a token";
error.value = err.message;
} finally {
busy.value = false;
}
@@ -58,11 +61,13 @@ async function revoke() {
return;
busy.value = true;
try {
capture.value = (await axios.delete("/api/admin/capture-token")).data;
capture.value = await api.delete("/admin/capture-token", {
fallback: "Failed to revoke the token",
});
newToken.value = "";
error.value = "";
} catch (err) {
error.value = err.response?.data?.error || "Failed to revoke the token";
error.value = err.message;
} finally {
busy.value = false;
}
+7 -6
View File
@@ -10,7 +10,7 @@
*/
import Button from "@/components/input/Button.vue";
import { ref } from "vue";
import axios from "axios";
import { api } from "@/api";
const emit = defineEmits(["done", "cancel"]);
@@ -34,19 +34,20 @@ async function submit() {
const formData = new FormData();
formData.append("image", file);
try {
const res = await axios.post("/api/rowing", formData, {
const res = await api.post("/rowing", formData, {
headers: { "Content-Type": "multipart/form-data" },
fallback: "Upload failed",
});
// Time comes back as a Go time.Duration, i.e. nanoseconds.
const mins = Math.floor(res.data.Time / 1e9 / 60);
const secs = String(Math.floor((res.data.Time / 1e9) % 60)).padStart(
const mins = Math.floor(res.Time / 1e9 / 60);
const secs = String(Math.floor((res.Time / 1e9) % 60)).padStart(
2,
"0",
);
results.value[i].status = `${res.data.Distance}m in ${mins}:${secs}`;
results.value[i].status = `${res.Distance}m in ${mins}:${secs}`;
results.value[i].ok = true;
} catch (err) {
results.value[i].status = err.response?.data?.error || "Upload failed";
results.value[i].status = err.message;
results.value[i].ok = false;
}
}),
+6 -4
View File
@@ -10,7 +10,7 @@
* onMounted, which is the desired "refresh on tab change" behaviour.
*/
import { ref, onMounted, computed } from "vue";
import axios from "axios";
import { api } from "@/api";
import Button from "@/components/input/Button.vue";
const lines = ref([]);
@@ -20,11 +20,13 @@ const loadingLogs = ref(false);
async function fetchLogs() {
loadingLogs.value = true;
try {
const res = await axios.get("/api/admin/logs");
lines.value = res.data.lines;
const res = await api.get("/admin/logs", {
fallback: "Failed to load logs",
});
lines.value = res.lines;
logsError.value = "";
} catch (err) {
logsError.value = err.response?.data?.error || "Failed to load logs";
logsError.value = err.message;
} finally {
loadingLogs.value = false;
}
+20 -20
View File
@@ -16,7 +16,7 @@
* once from the response that created it.
*/
import { ref, reactive, computed, onMounted, onUnmounted } from "vue";
import axios from "axios";
import { api } from "@/api";
import Button from "@/components/input/Button.vue";
import SecretReveal from "@/components/admin/SecretReveal.vue";
import CaptureToken from "./CaptureToken.vue";
@@ -54,13 +54,15 @@ function resetDrafts() {
async function fetchEnv() {
try {
const res = await axios.get("/api/admin/env");
groups.value = res.data.groups;
status.value = res.data.status;
const res = await api.get("/admin/env", {
fallback: "Failed to load the environment",
});
groups.value = res.groups;
status.value = res.status;
error.value = "";
resetDrafts();
} catch (err) {
error.value = err.response?.data?.error || "Failed to load the environment";
error.value = err.message;
} finally {
loading.value = false;
}
@@ -137,19 +139,18 @@ async function apply() {
applying.value = true;
outcome.value = null;
try {
const res = await axios.put("/api/admin/env", body);
revealed.value = res.data.generated || {};
status.value = res.data.status;
awaitedId.value = res.data.status.id;
const res = await api.put("/admin/env", body, {
fallback: "Failed to queue the change",
});
revealed.value = res.generated || {};
status.value = res.status;
awaitedId.value = res.status.id;
// Staged secrets have been sent; do not keep them in the inputs.
resetDrafts();
startPolling();
} catch (err) {
applying.value = false;
outcome.value = {
ok: false,
text: err.response?.data?.error || "Failed to queue the change",
};
outcome.value = { ok: false, text: err.message };
}
}
@@ -165,12 +166,12 @@ function stopPolling() {
async function poll() {
let next;
try {
next = (await axios.get("/api/admin/env/status")).data;
next = await api.get("/admin/env/status");
} catch (err) {
// 401/403 after an apply means the change invalidated this session
// (rotating BACKEND_SECRET does). Anything else is the backend
// restarting, which is the apply working.
if ([401, 403].includes(err.response?.status)) {
if ([401, 403].includes(err.status)) {
stopPolling();
applying.value = false;
outcome.value = {
@@ -200,15 +201,14 @@ async function poll() {
async function cancelPending() {
try {
status.value = (await axios.delete("/api/admin/env/pending")).data;
status.value = await api.delete("/admin/env/pending", {
fallback: "Failed to withdraw the change",
});
stopPolling();
applying.value = false;
outcome.value = { ok: true, text: "Pending change withdrawn. Nothing was applied." };
} catch (err) {
outcome.value = {
ok: false,
text: err.response?.data?.error || "Failed to withdraw the change",
};
outcome.value = { ok: false, text: err.message };
}
}
+5
View File
@@ -17,6 +17,11 @@ import { useAuthStore } from "@/stores/auth";
import Button from "@/components/input/Button.vue";
const auth = useAuthStore();
// Nothing else on this route resolves the session: the guard only runs for
// admin routes and the home query is not issued here. Without this, someone
// already signed in who opens /admin/login directly would see the login form
// instead of the "Already signed in" card.
auth.ensureLoaded();
const router = useRouter();
const route = useRoute();
const username = ref("");
+8 -9
View File
@@ -5,7 +5,7 @@
*/
import Button from "@/components/input/Button.vue";
import { ref, onMounted } from "vue";
import axios from "axios";
import { api } from "@/api";
const songs = ref([]);
const files = ref([]);
@@ -14,8 +14,8 @@ const loading = ref(false);
async function fetchSongs() {
try {
const res = await axios.get("/api/radio/songs");
songs.value = res.data.songs;
const res = await api.get("/radio/songs");
songs.value = res.songs;
} catch (err) {
console.error(err);
}
@@ -39,13 +39,14 @@ async function upload() {
const formData = new FormData();
formData.append("file", file);
try {
await axios.post("/api/radio/upload", formData, {
await api.post("/radio/upload", formData, {
headers: { "Content-Type": "multipart/form-data" },
fallback: "Upload failed",
});
results.value[i].status = "Uploaded";
results.value[i].ok = true;
} catch (err) {
results.value[i].status = err.response?.data?.error || "Upload failed";
results.value[i].status = err.message;
results.value[i].ok = false;
}
}),
@@ -58,7 +59,7 @@ async function upload() {
async function deleteSong(name) {
try {
await axios.delete(`/api/radio/songs/${encodeURIComponent(name)}`);
await api.delete(`/radio/songs/${encodeURIComponent(name)}`);
await fetchSongs();
} catch (err) {
console.error(err);
@@ -68,9 +69,7 @@ async function deleteSong(name) {
async function toggleSong(song) {
const action = song.disabled ? "enable" : "disable";
try {
await axios.patch(
`/api/radio/songs/${encodeURIComponent(song.name)}/${action}`,
);
await api.patch(`/radio/songs/${encodeURIComponent(song.name)}/${action}`);
await fetchSongs();
} catch (err) {
console.error(err);