- 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]>
217 lines
5.7 KiB
Vue
217 lines
5.7 KiB
Vue
<script setup>
|
|
/**
|
|
* Route `/admin` (guarded by `meta.requiresAdmin`) — a tab strip over every
|
|
* create/manage form. Each entry in `sections` maps a tab id to a component
|
|
* rendered by <component :is>. Unlike the home widgets these are eagerly
|
|
* imported, since reaching this page means you want them.
|
|
*/
|
|
import { ref, computed } from "vue";
|
|
import { useRouter } from "vue-router";
|
|
import { useAuthStore } from "@/stores/auth";
|
|
import Button from "@/components/input/Button.vue";
|
|
|
|
import CreateUser from "./CreateUser.vue";
|
|
import CreatePost from "./CreatePost.vue";
|
|
import CreateFavorite from "./CreateFavorite.vue";
|
|
import CreateActivity from "./CreateActivity.vue";
|
|
import CreateRowing from "./CreateRowing.vue";
|
|
import CreateBookmark from "./CreateBookmark.vue";
|
|
import CreatePlace from "./CreatePlace.vue";
|
|
import ManagePages from "./ManagePages.vue";
|
|
import ManageUsers from "./ManageUsers.vue";
|
|
import ManageRadio from "./ManageRadio.vue";
|
|
|
|
const auth = useAuthStore();
|
|
const router = useRouter();
|
|
|
|
const sections = [
|
|
{ id: "user", label: "User", component: CreateUser },
|
|
{ id: "post", label: "Post", component: CreatePost },
|
|
{ id: "favorite", label: "Favorite", component: CreateFavorite },
|
|
{ id: "activity", label: "Activity", component: CreateActivity },
|
|
{ id: "rowing", label: "Rowing", component: CreateRowing },
|
|
{ id: "bookmark", label: "Bookmark", component: CreateBookmark },
|
|
{ id: "place", label: "Place / Thing To Do", component: CreatePlace },
|
|
{ id: "pages", label: "Pages", component: ManagePages },
|
|
{ id: "users", label: "Manage Users", component: ManageUsers },
|
|
{ id: "radio", label: "Manage Radio", component: ManageRadio },
|
|
];
|
|
|
|
const active = ref("place");
|
|
const activeSection = computed(() =>
|
|
sections.find((s) => s.id === active.value),
|
|
);
|
|
|
|
// The create forms emit "done"/"cancel" and leave it to the host to react
|
|
// (the Feed widget's modal closes on them). Here the form stays open, so
|
|
// "done" needs a visible confirmation, and "cancel" remounts the form via
|
|
// formKey, which is the only way to clear fields the form keeps to itself.
|
|
const notice = ref("");
|
|
const formKey = ref(0);
|
|
|
|
function selectSection(id) {
|
|
active.value = id;
|
|
notice.value = "";
|
|
}
|
|
|
|
function onDone() {
|
|
notice.value = "Saved.";
|
|
}
|
|
|
|
function onCancel() {
|
|
notice.value = "";
|
|
formKey.value++;
|
|
}
|
|
|
|
// The requiresAdmin guard only runs on navigation, so logging out in place
|
|
// would leave the panel on screen for a signed-out visitor; leave it instead.
|
|
async function handleLogout() {
|
|
await auth.logOut();
|
|
router.push("/admin/login");
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<main class="admin-page">
|
|
<div class="admin-shell bdr-1">
|
|
<header class="admin-header">
|
|
<div class="flex flex-col">
|
|
<h1>Admin</h1>
|
|
<small v-if="auth.user?.username">
|
|
signed in as {{ auth.user.username }}
|
|
</small>
|
|
</div>
|
|
<Button @click="handleLogout">Log Out</Button>
|
|
</header>
|
|
|
|
<div class="admin-body">
|
|
<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 }}
|
|
</button>
|
|
<!-- Logs and incoming request bodies live in Dozzle, outside the
|
|
SPA (nginx serves it at /dozzle/ behind the admin check). -->
|
|
<a
|
|
class="admin-nav-link no-underline"
|
|
href="/dozzle/"
|
|
target="_blank"
|
|
rel="noopener"
|
|
>
|
|
Logs ↗
|
|
</a>
|
|
</nav>
|
|
|
|
<section class="admin-panel bdr-2 bg-surface">
|
|
<component
|
|
:is="activeSection.component"
|
|
:key="formKey"
|
|
@done="onDone"
|
|
@cancel="onCancel"
|
|
/>
|
|
<small v-if="notice" class="admin-notice" role="status">
|
|
{{ notice }}
|
|
</small>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.admin-page {
|
|
display: flex;
|
|
justify-content: center;
|
|
width: 100%;
|
|
padding: 8px;
|
|
}
|
|
|
|
.admin-shell {
|
|
width: 100%;
|
|
max-width: 900px;
|
|
background-color: var(--color-surface);
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.admin-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 6px 12px;
|
|
border-bottom: 1px solid var(--color-quaternary);
|
|
}
|
|
|
|
.admin-body {
|
|
display: grid;
|
|
grid-template-columns: 200px 1fr;
|
|
gap: 8px;
|
|
padding: 8px;
|
|
}
|
|
|
|
.admin-nav {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 3px;
|
|
}
|
|
|
|
.admin-nav-link {
|
|
text-align: left;
|
|
padding: 6px 10px;
|
|
color: var(--color-primary);
|
|
background-color: var(--color-link-bg);
|
|
border: 1px solid transparent;
|
|
font-family: var(--font-heading);
|
|
letter-spacing: 0.025em;
|
|
cursor: pointer;
|
|
transition:
|
|
background-color 120ms ease,
|
|
border-color 120ms ease,
|
|
color 120ms ease;
|
|
}
|
|
.admin-nav-link:hover {
|
|
border-color: var(--color-primary);
|
|
}
|
|
.admin-nav-link.is-active {
|
|
border-color: var(--color-primary);
|
|
color: var(--color-tertiary);
|
|
background-color: var(--color-surface-tint);
|
|
}
|
|
|
|
.admin-panel {
|
|
padding: 12px;
|
|
min-height: 300px;
|
|
}
|
|
.admin-panel :deep(h1) {
|
|
margin-top: 0;
|
|
}
|
|
|
|
.admin-notice {
|
|
display: block;
|
|
margin-top: 8px;
|
|
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>
|