diff --git a/vue/README.md b/vue/README.md index a5df8a0..ffdeb99 100644 --- a/vue/README.md +++ b/vue/README.md @@ -388,6 +388,8 @@ Note that Tailwind's spacing unit is set to **3px** (not the default 4px), so `p - Never hard-code a colour in a component; use a token. The one exception is `` drawing (MobileAutomata), which can't read CSS variables. - Home widgets: wrap the title in `
`; admin-only create forms use `` in the header's `#action` slot and render the form inside a `` so it pops up over the page instead of replacing the widget. - Crossfading content in place: `` inside a `position: relative` parent. Route changes use ``. +- Keyboard focus and reduced motion are handled globally in `styles.css`: every focusable element gets a pink `:focus-visible` ring (text fields a pink border instead), and `prefers-reduced-motion` collapses transitions and CSS animations. Both are low-specificity, so a component's own focus or outline style wins. A JS animation loop has to check `matchMedia("(prefers-reduced-motion: reduce)")` itself, as `Headline.vue` does. +- Forms are real `
` elements with `type="submit"` / `type="button"` on their buttons, not `@keyup.enter` on each input: Enter then submits from any field and password managers recognise the login. A form that saves shows its error inline and disables its button while the request is out (`useCreateForm` returns `error` and `submitting` for this). ## Production Build diff --git a/vue/src/assets/styles.css b/vue/src/assets/styles.css index 3018e13..0acbe3f 100644 --- a/vue/src/assets/styles.css +++ b/vue/src/assets/styles.css @@ -6,9 +6,11 @@ * every token is BOTH a utility class in templates * (text-primary, bg-surface, font-heading) AND a CSS variable * in component diff --git a/vue/src/views/admin/CreateActivity.vue b/vue/src/views/admin/CreateActivity.vue index 731557d..734956e 100644 --- a/vue/src/views/admin/CreateActivity.vue +++ b/vue/src/views/admin/CreateActivity.vue @@ -8,7 +8,7 @@ import { useCreateForm } from "@/js/useCreateForm"; const emit = defineEmits(["done", "cancel"]); -const { values, submit: post } = useCreateForm({ +const { values, submit: post, error, submitting } = useCreateForm({ mutation: `mutation CreateActivity($input: CreateActivityInput!) { createActivity(input: $input) { id } }`, fields: ["type", "name", "link"], optional: ["link"], @@ -19,12 +19,15 @@ const { type, name, link } = values; diff --git a/vue/src/views/admin/CreateBookmark.vue b/vue/src/views/admin/CreateBookmark.vue index d6901c1..1c3cfd5 100644 --- a/vue/src/views/admin/CreateBookmark.vue +++ b/vue/src/views/admin/CreateBookmark.vue @@ -8,7 +8,7 @@ import { useCreateForm } from "@/js/useCreateForm"; const emit = defineEmits(["done", "cancel"]); -const { values, submit } = useCreateForm({ +const { values, submit, error, submitting } = useCreateForm({ mutation: `mutation CreateBookmark($input: CreateBookmarkInput!) { createBookmark(input: $input) { id } }`, fields: ["category", "name", "link"], emit, @@ -17,22 +17,15 @@ const { category, name, link } = values; diff --git a/vue/src/views/admin/CreateFavorite.vue b/vue/src/views/admin/CreateFavorite.vue index ea2cb8f..09db90d 100644 --- a/vue/src/views/admin/CreateFavorite.vue +++ b/vue/src/views/admin/CreateFavorite.vue @@ -8,7 +8,7 @@ import { useCreateForm } from "@/js/useCreateForm"; const emit = defineEmits(["done", "cancel"]); -const { values, submit: post } = useCreateForm({ +const { values, submit: post, error, submitting } = useCreateForm({ mutation: `mutation CreateFavorite($input: CreateFavoriteInput!) { createFavorite(input: $input) { id } }`, fields: ["type", "name", "link"], optional: ["link"], @@ -19,12 +19,15 @@ const { type, name, link } = values; diff --git a/vue/src/views/admin/CreatePlace.vue b/vue/src/views/admin/CreatePlace.vue index 426e3af..ee02524 100644 --- a/vue/src/views/admin/CreatePlace.vue +++ b/vue/src/views/admin/CreatePlace.vue @@ -19,13 +19,16 @@ const imageUrl = ref(""); const notes = ref(""); const done = ref(false); const error = ref(""); +const submitting = ref(false); async function submit() { + if (submitting.value) return; if (!title.value.trim()) { error.value = "Title is required"; return; } error.value = ""; + submitting.value = true; try { await places.create({ title: title.value.trim(), @@ -48,56 +51,38 @@ async function submit() { emit("done"); } catch (err) { error.value = err?.message || "Failed to save"; + } finally { + submitting.value = false; } } diff --git a/vue/src/views/admin/CreatePost.vue b/vue/src/views/admin/CreatePost.vue index 2671542..832e567 100644 --- a/vue/src/views/admin/CreatePost.vue +++ b/vue/src/views/admin/CreatePost.vue @@ -10,7 +10,7 @@ import { useCreateForm } from "@/js/useCreateForm"; const emit = defineEmits(["done", "cancel"]); -const { values, submit: post } = useCreateForm({ +const { values, submit: post, error, submitting } = useCreateForm({ mutation: `mutation CreatePost($input: CreatePostInput!) { createPost(input: $input) { id } }`, fields: ["title", "content"], resultKey: "createPost", @@ -20,16 +20,14 @@ const { title, content } = values; diff --git a/vue/src/views/admin/CreateRowing.vue b/vue/src/views/admin/CreateRowing.vue index f2eecff..5164b93 100644 --- a/vue/src/views/admin/CreateRowing.vue +++ b/vue/src/views/admin/CreateRowing.vue @@ -16,6 +16,7 @@ const emit = defineEmits(["done", "cancel"]); const images = ref([]); const results = ref([]); +const uploading = ref(false); function onFileChange(e) { images.value = Array.from(e.target.files); @@ -23,7 +24,8 @@ function onFileChange(e) { } async function submit() { - if (!images.value.length) return; + if (!images.value.length || uploading.value) return; + uploading.value = true; results.value = images.value.map((f) => ({ name: f.name, status: "Uploading...", @@ -54,6 +56,7 @@ async function submit() { ); images.value = []; + uploading.value = false; // Only a clean run counts as done: hosts close or confirm on "done", which // would hide or contradict the per-file failure rows above. if (results.value.every((r) => r.ok)) emit("done"); @@ -69,11 +72,13 @@ async function submit() { multiple @change="onFileChange" /> - +
{{ r.name }}: - {{ + {{ r.status }}
diff --git a/vue/src/views/admin/CreateUser.vue b/vue/src/views/admin/CreateUser.vue index 8e273d9..53cd4d1 100644 --- a/vue/src/views/admin/CreateUser.vue +++ b/vue/src/views/admin/CreateUser.vue @@ -12,10 +12,13 @@ const username = ref(""); const password = ref(""); const message = ref(""); const error = ref(""); +const submitting = ref(false); async function handleCreate() { + if (submitting.value) return; message.value = ""; error.value = ""; + submitting.value = true; try { const data = await gql( `mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { id username } }`, @@ -26,29 +29,37 @@ async function handleCreate() { password.value = ""; } catch (err) { error.value = err.message || "Failed to create user."; + } finally { + submitting.value = false; } } diff --git a/vue/src/views/admin/ManagePages.vue b/vue/src/views/admin/ManagePages.vue index 6d12019..0579b24 100644 --- a/vue/src/views/admin/ManagePages.vue +++ b/vue/src/views/admin/ManagePages.vue @@ -17,6 +17,7 @@ const pages = usePagesStore(); pages.fetch(); const removeTarget = ref(null); const confirmationOpen = ref(false); +const removeError = ref(""); async function remove(page) { removeTarget.value = page; @@ -27,10 +28,11 @@ async function confirmRemove() { const page = removeTarget.value; removeTarget.value = null; if (!page) return; + removeError.value = ""; try { await pages.remove(page.id); } catch (err) { - alert(err?.message || "Failed to delete"); + removeError.value = err?.message || "Failed to delete"; } } @@ -43,6 +45,9 @@ async function confirmRemove() { The home page (/stp) and the landing page's notes are canvases too — edit those on the pages themselves.

+

Couldn't load the pages.

diff --git a/vue/src/views/admin/ManageRadio.vue b/vue/src/views/admin/ManageRadio.vue index ea0c1d4..5af5ca5 100644 --- a/vue/src/views/admin/ManageRadio.vue +++ b/vue/src/views/admin/ManageRadio.vue @@ -2,8 +2,11 @@ /** * Admin panel: list and upload tracks for the Icecast radio. REST * (multipart/form-data) rather than GraphQL because it moves files. + * Deleting removes the file from the radio's library for good, so it asks + * first; a failed list, enable/disable or delete is shown above the list. */ import Button from "@/components/input/Button.vue"; +import ConfirmDialog from "@/components/util/ConfirmDialog.vue"; import { ref, onMounted } from "vue"; import { api } from "@/api"; @@ -11,13 +14,19 @@ const songs = ref([]); const files = ref([]); const results = ref([]); const loading = ref(false); +const error = ref(""); +const deleteTarget = ref(null); +const confirmOpen = ref(false); async function fetchSongs() { try { - const res = await api.get("/radio/songs"); + const res = await api.get("/radio/songs", { + fallback: "Couldn't load the songs", + }); songs.value = res.songs; } catch (err) { console.error(err); + error.value = err.message; } } @@ -57,22 +66,40 @@ async function upload() { await fetchSongs(); } -async function deleteSong(name) { +function askDelete(song) { + deleteTarget.value = song; + confirmOpen.value = true; +} + +async function deleteSong() { + const song = deleteTarget.value; + deleteTarget.value = null; + if (!song) return; + error.value = ""; try { - await api.delete(`/radio/songs/${encodeURIComponent(name)}`); + await api.delete(`/radio/songs/${encodeURIComponent(song.name)}`, { + fallback: "Delete failed", + }); await fetchSongs(); } catch (err) { console.error(err); + error.value = err.message; } } async function toggleSong(song) { const action = song.disabled ? "enable" : "disable"; + error.value = ""; try { - await api.patch(`/radio/songs/${encodeURIComponent(song.name)}/${action}`); + await api.patch( + `/radio/songs/${encodeURIComponent(song.name)}/${action}`, + undefined, + { fallback: `Couldn't ${action} the song` }, + ); await fetchSongs(); } catch (err) { console.error(err); + error.value = err.message; } } @@ -94,26 +121,41 @@ onMounted(fetchSongs); multiple @change="onFileChange" /> - + +
{{ r.name }}: - {{ + {{ r.status }}
- {{ song.name }} + + {{ song.name }} + {{ formatSize(song.size) }} - disabled + disabled - +
+ + diff --git a/vue/src/views/admin/ManageUsers.vue b/vue/src/views/admin/ManageUsers.vue index a882af9..4d22a28 100644 --- a/vue/src/views/admin/ManageUsers.vue +++ b/vue/src/views/admin/ManageUsers.vue @@ -2,7 +2,8 @@ /** * Admin panel: list users and toggle their admin flag. Mutates the local `user` * object in place from the mutation's response, so the row updates without a - * refetch. + * refetch. A failed load or toggle is shown above the table rather than only + * logged, and a row's button is disabled while its toggle is in flight. */ import Button from "@/components/input/Button.vue"; import { ref, onMounted } from "vue"; @@ -11,6 +12,9 @@ import { gql } from "@/graphql"; const auth = useAuthStore(); const users = ref([]); +const loaded = ref(false); +const error = ref(""); +const pending = ref(null); async function fetchUsers() { try { @@ -18,15 +22,23 @@ async function fetchUsers() { users.value = data.users; } catch (err) { console.error(err); + error.value = err.message || "Couldn't load the users"; + } finally { + loaded.value = true; } } async function toggleAdmin(user) { + error.value = ""; + pending.value = user.id; try { const data = await auth.setUserAdmin(user.id, !user.admin); user.admin = data.admin; } catch (err) { console.error(err); + error.value = err.message || `Couldn't change ${user.username}`; + } finally { + pending.value = null; } } @@ -34,18 +46,26 @@ onMounted(fetchUsers); diff --git a/vue/src/views/home/Steam.vue b/vue/src/views/home/Steam.vue index 87621df..30b8533 100644 --- a/vue/src/views/home/Steam.vue +++ b/vue/src/views/home/Steam.vue @@ -42,7 +42,7 @@ function formatHours(minutes) { Steam