Codebase audits, privacy, dark mode, palette (v1.9.0 to v1.9.4-audit) #14
5 changed files with 69 additions and 12 deletions
|
|
@ -23,6 +23,8 @@ const NOTE_LIMIT = 2000;
|
|||
|
||||
/* ── GET /api/admin/feedback ─────────────────────────────────────
|
||||
?status=new one of STATUSES, or omitted for all
|
||||
?kind=feedback website feedback (every type but 'privacy')
|
||||
?kind=privacy data requests from the Privacy page
|
||||
?type=broken feedback_type
|
||||
?q=retreat substring of the message
|
||||
?before=41 cursor: rows with a lower id than this
|
||||
|
|
@ -31,11 +33,17 @@ const NOTE_LIMIT = 2000;
|
|||
|
||||
admin.get("/feedback", (c) => {
|
||||
const db = c.get("db");
|
||||
const { status, type, q, before, limit } = c.req.query();
|
||||
const { status, type, kind, q, before, limit } = c.req.query();
|
||||
|
||||
const where = [];
|
||||
const params = [];
|
||||
|
||||
// Data requests and website feedback share the table but are two
|
||||
// queues in the admin (Forms → Website feedback, Data requests).
|
||||
const kindWhere =
|
||||
kind === "privacy" ? "feedback_type = 'privacy'" : kind === "feedback" ? "feedback_type <> 'privacy'" : null;
|
||||
if (kindWhere) where.push(kindWhere);
|
||||
|
||||
if (STATUSES.includes(status)) {
|
||||
where.push("status = ?");
|
||||
params.push(status);
|
||||
|
|
@ -69,19 +77,27 @@ admin.get("/feedback", (c) => {
|
|||
const hasMore = rows.length > take;
|
||||
const page = hasMore ? rows.slice(0, take) : rows;
|
||||
|
||||
// Counts are unfiltered on purpose: the tabs should show what's
|
||||
// waiting overall, not what's left after the current filter.
|
||||
// Status counts cover this queue (kind) but ignore the other
|
||||
// filters: the tabs show what's waiting, not what's left after a
|
||||
// search. newByKind is what's new in each queue, for the queue tabs.
|
||||
const counts = Object.fromEntries(STATUSES.map((s) => [s, 0]));
|
||||
for (const row of db
|
||||
.prepare("SELECT status, COUNT(*) AS n FROM feedback GROUP BY status")
|
||||
.prepare(`SELECT status, COUNT(*) AS n FROM feedback ${kindWhere ? `WHERE ${kindWhere}` : ""} GROUP BY status`)
|
||||
.all()) {
|
||||
counts[row.status] = row.n;
|
||||
}
|
||||
const newByKind = db
|
||||
.prepare(
|
||||
`SELECT SUM(feedback_type <> 'privacy') AS feedback, SUM(feedback_type = 'privacy') AS privacy
|
||||
FROM feedback WHERE status = 'new'`,
|
||||
)
|
||||
.get();
|
||||
|
||||
return c.json(
|
||||
{
|
||||
feedback: page,
|
||||
counts,
|
||||
newByKind: { feedback: newByKind?.feedback ?? 0, privacy: newByKind?.privacy ?? 0 },
|
||||
nextCursor: hasMore ? page[page.length - 1].id : null,
|
||||
},
|
||||
200,
|
||||
|
|
|
|||
|
|
@ -128,6 +128,7 @@ export default function App() {
|
|||
<Route path="panel" element={<AdminPanel />} />
|
||||
</Route>
|
||||
<Route path="feedback" element={<AdminFeedback />} />
|
||||
<Route path="data-requests" element={<AdminFeedback kind="privacy" />} />
|
||||
<Route path="media" element={<AdminMedia />} />
|
||||
<Route element={<RequireRole role="admin" />}>
|
||||
<Route path="clips" element={<AdminClips />} />
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ const PAGE = sitePage("/privacy");
|
|||
|
||||
The contact address is Panel → Site settings → Privacy contact
|
||||
email. Requests from the form below are feedback rows of type
|
||||
'privacy', in Admin → Feedback.
|
||||
'privacy', in Admin → Forms → Data requests.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const LAST_UPDATED = "September 28, 2026";
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { Link, useNavigate } from "react-router-dom";
|
||||
|
||||
import { del, get, patch, ApiError } from "../../lib/api.ts";
|
||||
import { isUnauthorized, useAuth } from "../../lib/auth.tsx";
|
||||
|
|
@ -225,9 +225,25 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
|
|||
|
||||
/* ── The page ────────────────────────────────────────────────── */
|
||||
|
||||
export default function AdminFeedback() {
|
||||
/* The two queues this page shows: the website feedback form, and
|
||||
data requests from the Privacy page. Same table, same triage. */
|
||||
const QUEUES = {
|
||||
feedback: {
|
||||
to: "/admin/feedback",
|
||||
title: "Website feedback",
|
||||
blurb: "Everything submitted through the site's feedback form.",
|
||||
},
|
||||
privacy: {
|
||||
to: "/admin/data-requests",
|
||||
title: "Data requests",
|
||||
blurb: "Requests to see, correct or delete someone's information, from the Privacy page. Each has an email to answer.",
|
||||
},
|
||||
} as const;
|
||||
|
||||
export default function AdminFeedback({ kind = "feedback" }: { kind?: keyof typeof QUEUES }) {
|
||||
const { user } = useAuth();
|
||||
const navigate = useNavigate();
|
||||
const queue = QUEUES[kind];
|
||||
|
||||
const [status, setStatus] = useState("new");
|
||||
const [query, setQuery] = useState("");
|
||||
|
|
@ -235,6 +251,7 @@ export default function AdminFeedback() {
|
|||
|
||||
const [rows, setRows] = useState<any[]>([]);
|
||||
const [counts, setCounts] = useState<any>({});
|
||||
const [newByKind, setNewByKind] = useState<any>({});
|
||||
const [cursor, setCursor] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<any>(null);
|
||||
|
|
@ -249,6 +266,7 @@ export default function AdminFeedback() {
|
|||
setError(null);
|
||||
|
||||
const params = new URLSearchParams();
|
||||
params.set("kind", kind);
|
||||
if (status !== "all") params.set("status", status);
|
||||
if (search) params.set("q", search);
|
||||
if (before) params.set("before", String(before));
|
||||
|
|
@ -257,6 +275,7 @@ export default function AdminFeedback() {
|
|||
const data = await get(`/admin/feedback?${params}`, { ttl: 0 });
|
||||
setRows((prev) => (before ? [...prev, ...data.feedback] : data.feedback));
|
||||
setCounts(data.counts);
|
||||
setNewByKind(data.newByKind ?? {});
|
||||
setCursor(data.nextCursor);
|
||||
} catch (err) {
|
||||
if (isUnauthorized(err)) {
|
||||
|
|
@ -271,7 +290,7 @@ export default function AdminFeedback() {
|
|||
setLoading(false);
|
||||
}
|
||||
},
|
||||
[status, search, navigate],
|
||||
[kind, status, search, navigate],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -306,11 +325,27 @@ export default function AdminFeedback() {
|
|||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-3xl font-bold text-link">Feedback</h1>
|
||||
{/* The two queues, each with what's new in it. */}
|
||||
<nav aria-label="Forms" className="mb-6 flex gap-1 border-b border-brand/15">
|
||||
{Object.entries(QUEUES).map(([id, q]) => (
|
||||
<Link
|
||||
key={id}
|
||||
to={q.to}
|
||||
aria-current={id === kind ? "page" : undefined}
|
||||
className={
|
||||
"-mb-px border-b-2 px-4 py-2 text-sm font-semibold transition-colors " +
|
||||
(id === kind ? "border-link text-link" : "border-transparent text-muted hover:text-link")
|
||||
}
|
||||
>
|
||||
{q.title}
|
||||
{newByKind[id] ? ` (${newByKind[id]} new)` : ""}
|
||||
</Link>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<h1 className="text-3xl font-bold text-link">{queue.title}</h1>
|
||||
<p className="mt-2 text-sm text-muted">
|
||||
{canWrite
|
||||
? "Everything submitted through the site form."
|
||||
: "Read-only: your account can't change statuses or notes."}
|
||||
{canWrite ? queue.blurb : "Read-only: your account can't change statuses or notes."}
|
||||
</p>
|
||||
|
||||
{/* Filters */}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,11 @@ export const FORMS_NAV = {
|
|||
label: "Website feedback",
|
||||
blurb: "The triage queue for the feedback form.",
|
||||
},
|
||||
{
|
||||
to: "/admin/data-requests",
|
||||
label: "Data requests",
|
||||
blurb: "Requests to see, correct or delete someone's information, from the Privacy page.",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue