Polish the SPA: focus rings, reduced motion, forms that report errors
- Global :focus-visible ring (text fields get a border instead) and a prefers-reduced-motion override; the navbar marquee stops for it too. - Button: disabled state and horizontal padding. - useCreateForm returns error and submitting, so the create forms show a refused save inline and can't double-submit; they, Login, CreatePlace and CreateUser are real <form>s so Enter submits from any field. - Admin: section list wraps on phones, Manage Users is a table with errors, Manage Radio confirms before deleting, page delete errors show inline. - Hard-coded Tailwind colours replaced with tokens; 404 image alt text and no forced scrollbars. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
<template>
|
||||
<main class="flex flex-col items-center">
|
||||
<div
|
||||
class="page-a4 items-center bdr-1 flex flex-col relative overflow-scroll"
|
||||
class="page-a4 items-center bdr-1 flex flex-col relative overflow-auto"
|
||||
>
|
||||
<h1>404</h1>
|
||||
<RouterLink to="/" class="bdr-2">
|
||||
<img src="/img/memes/epic.jpeg" loading="lazy" />
|
||||
<RouterLink to="/" class="bdr-2" aria-label="Back to the home page">
|
||||
<img src="/img/memes/epic.jpeg" alt="" class="block max-w-full" />
|
||||
</RouterLink>
|
||||
<h1>Click her, she will take you home</h1>
|
||||
</div>
|
||||
|
||||
@@ -85,12 +85,14 @@ async function handleLogout() {
|
||||
</header>
|
||||
|
||||
<div class="admin-body">
|
||||
<nav class="admin-nav">
|
||||
<nav class="admin-nav" aria-label="Admin sections">
|
||||
<button
|
||||
v-for="section in sections"
|
||||
:key="section.id"
|
||||
type="button"
|
||||
class="admin-nav-link"
|
||||
:class="{ 'is-active': active === section.id }"
|
||||
:aria-current="active === section.id ? 'page' : undefined"
|
||||
@click="selectSection(section.id)"
|
||||
>
|
||||
{{ section.label }}
|
||||
@@ -114,7 +116,9 @@ async function handleLogout() {
|
||||
@done="onDone"
|
||||
@cancel="onCancel"
|
||||
/>
|
||||
<small v-if="notice" class="admin-notice">{{ notice }}</small>
|
||||
<small v-if="notice" class="admin-notice" role="status">
|
||||
{{ notice }}
|
||||
</small>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
@@ -195,9 +199,18 @@ async function handleLogout() {
|
||||
color: var(--color-secondary);
|
||||
}
|
||||
|
||||
/* On a phone the section list would be eleven full-width rows above the
|
||||
form; as wrapping chips it takes three or four lines. */
|
||||
@media (max-width: 700px) {
|
||||
.admin-body {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.admin-nav {
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.admin-nav-link {
|
||||
padding: 4px 8px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -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;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<form class="flex flex-col" @submit.prevent="post">
|
||||
<h1>Create Activity</h1>
|
||||
<input type="text" v-model="type" placeholder="Type" @keyup.enter="post" />
|
||||
<input type="text" v-model="name" placeholder="Name" @keyup.enter="post" />
|
||||
<input type="text" v-model="link" placeholder="Link" @keyup.enter="post" />
|
||||
<Button @click="post">Upload</Button>
|
||||
<Button @click="emit('cancel')">Cancel</Button>
|
||||
</div>
|
||||
<input type="text" v-model="type" placeholder="Type" />
|
||||
<input type="text" v-model="name" placeholder="Name" />
|
||||
<input type="text" v-model="link" placeholder="Link" />
|
||||
<small v-if="error" class="p-1" role="alert">{{ error }}</small>
|
||||
<Button type="submit" :disabled="submitting">
|
||||
{{ submitting ? "Uploading…" : "Upload" }}
|
||||
</Button>
|
||||
<Button type="button" @click="emit('cancel')">Cancel</Button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -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;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<form class="flex flex-col" @submit.prevent="submit">
|
||||
<h1>Create Bookmark</h1>
|
||||
<input type="text" v-model="category" placeholder="Category" />
|
||||
<input
|
||||
type="text"
|
||||
v-model="name"
|
||||
placeholder="Name"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
v-model="link"
|
||||
placeholder="Link"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<Button @click="submit">Upload</Button>
|
||||
<Button @click="emit('cancel')">Cancel</Button>
|
||||
</div>
|
||||
<input type="text" v-model="name" placeholder="Name" />
|
||||
<input type="text" v-model="link" placeholder="Link" />
|
||||
<small v-if="error" class="p-1" role="alert">{{ error }}</small>
|
||||
<Button type="submit" :disabled="submitting">
|
||||
{{ submitting ? "Uploading…" : "Upload" }}
|
||||
</Button>
|
||||
<Button type="button" @click="emit('cancel')">Cancel</Button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -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;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<form class="flex flex-col" @submit.prevent="post">
|
||||
<h1>Create Favorite</h1>
|
||||
<input type="text" v-model="type" placeholder="Type" @keyup.enter="post" />
|
||||
<input type="text" v-model="name" placeholder="Name" @keyup.enter="post" />
|
||||
<input type="text" v-model="link" placeholder="Link" @keyup.enter="post" />
|
||||
<Button @click="post">Upload</Button>
|
||||
<Button @click="emit('cancel')">Cancel</Button>
|
||||
</div>
|
||||
<input type="text" v-model="type" placeholder="Type" />
|
||||
<input type="text" v-model="name" placeholder="Name" />
|
||||
<input type="text" v-model="link" placeholder="Link" />
|
||||
<small v-if="error" class="p-1" role="alert">{{ error }}</small>
|
||||
<Button type="submit" :disabled="submitting">
|
||||
{{ submitting ? "Uploading…" : "Upload" }}
|
||||
</Button>
|
||||
<Button type="button" @click="emit('cancel')">Cancel</Button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<form class="flex flex-col" @submit.prevent="submit">
|
||||
<h1>Add Place / Thing To Do</h1>
|
||||
<input
|
||||
type="text"
|
||||
v-model="title"
|
||||
placeholder="Title (required)"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
v-model="location"
|
||||
placeholder="Location"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input type="text" v-model="title" placeholder="Title (required)" />
|
||||
<input type="text" v-model="location" placeholder="Location" />
|
||||
<input
|
||||
type="text"
|
||||
v-model="category"
|
||||
placeholder="Category (place, activity, food…)"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
v-model="cost"
|
||||
placeholder="Cost (e.g. £20 pp)"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input type="text" v-model="cost" placeholder="Cost (e.g. £20 pp)" />
|
||||
<input
|
||||
type="number"
|
||||
v-model="priority"
|
||||
placeholder="Priority (higher = sooner)"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
v-model="imageUrl"
|
||||
placeholder="Image URL"
|
||||
@keyup.enter="submit"
|
||||
/>
|
||||
<input type="text" v-model="imageUrl" placeholder="Image URL" />
|
||||
<textarea class="h-25" v-model="notes" placeholder="Notes"></textarea>
|
||||
<label class="flex flex-row items-center gap-2 p-2 text-primary">
|
||||
<input type="checkbox" v-model="done" class="w-auto" />
|
||||
Already done
|
||||
</label>
|
||||
<small v-if="error" class="p-1">{{ error }}</small>
|
||||
<Button @click="submit">Upload</Button>
|
||||
<Button @click="emit('cancel')">Cancel</Button>
|
||||
</div>
|
||||
<small v-if="error" class="p-1" role="alert">{{ error }}</small>
|
||||
<Button type="submit" :disabled="submitting">
|
||||
{{ submitting ? "Uploading…" : "Upload" }}
|
||||
</Button>
|
||||
<Button type="button" @click="emit('cancel')">Cancel</Button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -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;
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<form class="flex flex-col" @submit.prevent="post">
|
||||
<h1>Create Post</h1>
|
||||
<input
|
||||
type="text"
|
||||
v-model="title"
|
||||
placeholder="Title"
|
||||
@keyup.enter="post"
|
||||
/>
|
||||
<input type="text" v-model="title" placeholder="Title" />
|
||||
<textarea class="h-50" v-model="content" placeholder="Content"></textarea>
|
||||
<Button @click="post">Upload</Button>
|
||||
<Button @click="emit('cancel')">Cancel</Button>
|
||||
</div>
|
||||
<small v-if="error" class="p-1" role="alert">{{ error }}</small>
|
||||
<Button type="submit" :disabled="submitting">
|
||||
{{ submitting ? "Uploading…" : "Upload" }}
|
||||
</Button>
|
||||
<Button type="button" @click="emit('cancel')">Cancel</Button>
|
||||
</form>
|
||||
</template>
|
||||
|
||||
@@ -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"
|
||||
/>
|
||||
<Button @click="submit">Upload</Button>
|
||||
<Button @click="submit" :disabled="uploading || !images.length">
|
||||
{{ uploading ? "Reading…" : "Upload" }}
|
||||
</Button>
|
||||
<Button @click="emit('cancel')">Cancel</Button>
|
||||
<div v-for="r in results" :key="r.name">
|
||||
<span class="text-primary">{{ r.name }}: </span>
|
||||
<span :class="r.ok ? 'text-secondary' : 'text-red-500'">{{
|
||||
<span :class="r.ok ? 'text-secondary' : 'text-tertiary'">{{
|
||||
r.status
|
||||
}}</span>
|
||||
</div>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="auth.loggedIn && auth.user.admin" class="flex flex-col">
|
||||
<form
|
||||
v-if="auth.loggedIn && auth.user.admin"
|
||||
class="flex flex-col"
|
||||
@submit.prevent="handleCreate"
|
||||
>
|
||||
<h1>Create User</h1>
|
||||
<p v-if="message" class="text-green-500">{{ message }}</p>
|
||||
<p v-if="error" class="text-red-500">{{ error }}</p>
|
||||
<p v-if="message" class="text-secondary" role="status">{{ message }}</p>
|
||||
<p v-if="error" class="text-tertiary" role="alert">{{ error }}</p>
|
||||
<input
|
||||
type="text"
|
||||
v-model="username"
|
||||
placeholder="Username"
|
||||
@keyup.enter="handleCreate"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
v-model="password"
|
||||
placeholder="Password"
|
||||
@keyup.enter="handleCreate"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
<Button @click="handleCreate">Create Account</Button>
|
||||
</div>
|
||||
<Button type="submit" :disabled="submitting">
|
||||
{{ submitting ? "Creating…" : "Create Account" }}
|
||||
</Button>
|
||||
</form>
|
||||
<div v-else-if="auth.loggedIn" class="flex flex-col">
|
||||
<p>You do not have permission to create users.</p>
|
||||
</div>
|
||||
|
||||
@@ -86,7 +86,9 @@ function handleLogout() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="login-card bdr-1">
|
||||
<!-- A real <form>, so Enter submits from either field and password
|
||||
managers recognise it as a sign-in. -->
|
||||
<form v-else class="login-card bdr-1" @submit.prevent="handleLogin">
|
||||
<h1>Login</h1>
|
||||
<small class="login-hint">
|
||||
Admin access is required beyond this point.
|
||||
@@ -99,7 +101,7 @@ function handleLogout() {
|
||||
v-model="username"
|
||||
autocomplete="username"
|
||||
placeholder="Username"
|
||||
@keyup.enter="handleLogin"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
@@ -110,16 +112,18 @@ function handleLogout() {
|
||||
v-model="password"
|
||||
autocomplete="current-password"
|
||||
placeholder="Password"
|
||||
@keyup.enter="handleLogin"
|
||||
required
|
||||
/>
|
||||
</label>
|
||||
|
||||
<small v-if="errorMsg" class="login-error">{{ errorMsg }}</small>
|
||||
<small v-if="errorMsg" class="login-error" role="alert">
|
||||
{{ errorMsg }}
|
||||
</small>
|
||||
|
||||
<Button @click="handleLogin" :disabled="submitting">
|
||||
<Button type="submit" class="mt-1 py-2" :disabled="submitting">
|
||||
{{ submitting ? "Signing in…" : "Log In" }}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -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.
|
||||
</p>
|
||||
<p v-if="removeError" class="text-tertiary" role="alert">
|
||||
{{ removeError }}
|
||||
</p>
|
||||
<p v-if="pages.error" class="text-tertiary">Couldn't load the pages.</p>
|
||||
<table v-else-if="pages.pages.length" class="w-full">
|
||||
<tr v-for="page in pages.pages" :key="page.id">
|
||||
|
||||
@@ -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"
|
||||
/>
|
||||
<Button @click="upload" :disabled="loading">Upload</Button>
|
||||
<Button @click="upload" :disabled="loading || !files.length">
|
||||
{{ loading ? "Uploading…" : "Upload" }}
|
||||
</Button>
|
||||
<p v-if="error" class="text-tertiary" role="alert">{{ error }}</p>
|
||||
<div v-for="r in results" :key="r.name">
|
||||
<span class="text-primary">{{ r.name }}: </span>
|
||||
<span :class="r.ok ? 'text-secondary' : 'text-red-500'">{{
|
||||
<span :class="r.ok ? 'text-secondary' : 'text-tertiary'">{{
|
||||
r.status
|
||||
}}</span>
|
||||
</div>
|
||||
<div
|
||||
v-for="song in songs"
|
||||
:key="song.name"
|
||||
class="flex flex-row items-center gap-2"
|
||||
class="flex flex-row flex-wrap items-center gap-2"
|
||||
:class="{ 'opacity-50': song.disabled }"
|
||||
>
|
||||
<span :class="{ 'line-through': song.disabled }">{{ song.name }}</span>
|
||||
<span class="text-primary" :class="{ 'line-through': song.disabled }">
|
||||
{{ song.name }}
|
||||
</span>
|
||||
<span class="text-secondary text-sm">{{ formatSize(song.size) }}</span>
|
||||
<span v-if="song.disabled" class="text-red-400 text-xs">disabled</span>
|
||||
<span v-if="song.disabled" class="text-tertiary text-xs">disabled</span>
|
||||
<Button @click="toggleSong(song)">{{
|
||||
song.disabled ? "Enable" : "Disable"
|
||||
}}</Button>
|
||||
<Button @click="deleteSong(song.name)">Delete</Button>
|
||||
<Button @click="askDelete(song)">Delete</Button>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
v-if="deleteTarget"
|
||||
v-model="confirmOpen"
|
||||
title="Delete song"
|
||||
:message="`Delete “${deleteTarget.name}” from the radio? The file is removed for good.`"
|
||||
confirm-label="Delete"
|
||||
@confirm="deleteSong"
|
||||
@cancel="deleteTarget = null"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -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);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-col">
|
||||
<div class="flex flex-col gap-2">
|
||||
<h1>Manage Users</h1>
|
||||
<div
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
class="flex flex-row items-center gap-2"
|
||||
>
|
||||
<span>{{ user.username }}</span>
|
||||
<span v-if="user.admin">(admin)</span>
|
||||
<Button v-if="user.id !== auth.user.id" @click="toggleAdmin(user)">
|
||||
{{ user.admin ? "Demote" : "Promote" }}
|
||||
</Button>
|
||||
</div>
|
||||
<p v-if="error" class="text-tertiary" role="alert">{{ error }}</p>
|
||||
<p v-if="!loaded" class="text-muted">Loading…</p>
|
||||
<table v-else-if="users.length" class="w-full">
|
||||
<tr v-for="user in users" :key="user.id">
|
||||
<td class="py-1">{{ user.username }}</td>
|
||||
<td class="py-1">{{ user.admin ? "admin" : "user" }}</td>
|
||||
<td class="py-1 text-right">
|
||||
<span v-if="user.id === auth.user.id" class="text-muted">you</span>
|
||||
<Button
|
||||
v-else
|
||||
:disabled="pending === user.id"
|
||||
@click="toggleAdmin(user)"
|
||||
>
|
||||
{{ user.admin ? "Demote" : "Promote" }}
|
||||
</Button>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p v-else-if="!error" class="text-muted">No users.</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -42,7 +42,7 @@ function formatHours(minutes) {
|
||||
Steam
|
||||
<span
|
||||
class="inline-block w-2 h-2 rounded-full"
|
||||
:class="steamStatus.online ? 'bg-green-500' : 'bg-gray-400'"
|
||||
:class="steamStatus.online ? 'bg-secondary' : 'bg-muted'"
|
||||
:title="steamStatus.online ? 'Online' : 'Offline'"
|
||||
/>
|
||||
</span>
|
||||
|
||||
Reference in New Issue
Block a user