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
+16 -79
View File
@@ -1,17 +1,13 @@
/**
* Places-to-go list (the "Places" tab inside the Collage widget) — full CRUD.
* Places-to-go list (the "Places" tab inside the Collage widget) — full CRUD,
* built on createCrudStore().
*
* Not part of the homeData query because it is sign-in-only; PlacesTable.vue
* fetches it lazily once the user is logged in. PLACE_FIELDS is interpolated into
* every query/mutation so the selection set can never drift between them.
* fetches it lazily once the user is logged in.
*/
import { defineStore } from "pinia";
import { ref } from "vue";
import { gql } from "@/graphql";
import { createCrudStore } from "@/stores/createCrudStore";
// Shared selection set: interpolated into every query and mutation so they can
// never drift apart.
const PLACE_FIELDS = `
id
title
@@ -26,75 +22,16 @@ const PLACE_FIELDS = `
updatedAt
`;
export const usePlacesStore = defineStore("places", () => {
const places = ref([]);
const loaded = ref(false);
const loading = ref(false);
const error = ref(null);
/** Load all places into `places`. Records failures on `error` rather than throwing. */
async function fetch() {
loading.value = true;
try {
const data = await gql(`query Places { places { ${PLACE_FIELDS} } }`);
places.value = data.places || [];
loaded.value = true;
error.value = null;
} catch (err) {
error.value = err;
} finally {
loading.value = false;
}
}
/** Create a place and prepend it locally (newest first). Throws on failure. */
async function create(input) {
const data = await gql(
`mutation CreatePlace($input: CreatePlaceInput!) {
createPlace(input: $input) { ${PLACE_FIELDS} }
}`,
{ input },
);
places.value = [data.createPlace, ...places.value];
return data.createPlace;
}
/** Patch a place and replace it in the local list. Throws on failure. */
async function update(id, input) {
const data = await gql(
`mutation UpdatePlace($id: ID!, $input: UpdatePlaceInput!) {
updatePlace(id: $id, input: $input) { ${PLACE_FIELDS} }
}`,
{ id, input },
);
const idx = places.value.findIndex((p) => p.id === id);
if (idx >= 0) places.value[idx] = data.updatePlace;
return data.updatePlace;
}
/** Flip a place's `done` flag. */
async function toggleDone(place) {
return update(place.id, { done: !place.done });
}
/** Soft-delete a place and drop it from the local list. */
async function remove(id) {
await gql(
`mutation DeletePlace($id: ID!) { deletePlace(id: $id) { id } }`,
{ id },
);
places.value = places.value.filter((p) => p.id !== id);
}
return {
places,
loaded,
loading,
error,
fetch,
create,
update,
toggleDone,
remove,
};
export const usePlacesStore = createCrudStore("places", {
type: "Place",
list: "places",
fields: PLACE_FIELDS,
// The list query returns newest first, so a new place goes on top.
insert: "prepend",
// deletePlace returns the deleted Place, unlike the job tracker's deletes.
deleteReturns: "object",
extend: ({ update }) => ({
/** Flip a place's `done` flag. */
toggleDone: (place) => update(place.id, { done: !place.done }),
}),
});