Page features: directory and blog post tabs, image converter, version names
- Featured event badge: above the event's card from lg up, left out on phones - Version names from the tag (The Region Cards Update) in the site and admin footers - Tools -> Image converter (JPG, PNG, WebP in the browser) and Download as in Media - People directory sections take several tags, a tab each (migration 078) - Tab blocks split a blog post into tabs; contents follow the open tab (migration 079) - The side nav sun fades out as the page scrolls into the footer Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
a6c66d4607
commit
31afa889d6
28 changed files with 878 additions and 70 deletions
196
src/pages/admin/AdminConvert.tsx
Normal file
196
src/pages/admin/AdminConvert.tsx
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
ADMIN: IMAGE CONVERTER (Tools → Image converter, everyone)
|
||||
|
||||
Pictures turned into JPG, PNG or WebP in the browser
|
||||
(src/lib/convertImage.ts): pick or drop any number, choose the
|
||||
format (and quality, for JPG and WebP), download each. Nothing is
|
||||
uploaded or kept. The Media library's Download as does the same
|
||||
for a picture already there.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { useId, useState } from "react";
|
||||
|
||||
import { OUTPUT_FORMATS, convertImage, renamed, saveBlob, type OutputType } from "../../lib/convertImage.ts";
|
||||
|
||||
const MUTED = "var(--color-muted)";
|
||||
|
||||
const button =
|
||||
"btn border border-brand px-4 py-2 text-sm text-link transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50";
|
||||
const primary =
|
||||
"btn bg-action px-5 py-2.5 text-white transition-colors hover:bg-action-hover disabled:bg-muted/25";
|
||||
|
||||
type Item = { file: File; result?: Blob; error?: string };
|
||||
|
||||
const kb = (bytes: number) => (bytes >= 1024 * 1024 ? `${(bytes / 1024 / 1024).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`);
|
||||
|
||||
export default function AdminConvert() {
|
||||
const inputId = useId();
|
||||
const formatId = useId();
|
||||
const qualityId = useId();
|
||||
const [items, setItems] = useState<Item[]>([]);
|
||||
const [type, setType] = useState<OutputType>("image/jpeg");
|
||||
const [quality, setQuality] = useState(90);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [over, setOver] = useState(false);
|
||||
const lossy = OUTPUT_FORMATS.find((f) => f.type === type)?.lossy;
|
||||
|
||||
const add = (files: FileList | null) => {
|
||||
const pictures = [...(files ?? [])].filter((file) => file.type.startsWith("image/") || /\.(heic|heif)$/i.test(file.name));
|
||||
setItems((current) => [...current, ...pictures.map((file) => ({ file }))]);
|
||||
};
|
||||
|
||||
async function convertAll() {
|
||||
setBusy(true);
|
||||
const next: Item[] = [];
|
||||
for (const item of items) {
|
||||
try {
|
||||
next.push({ file: item.file, result: await convertImage(item.file, type, quality / 100) });
|
||||
} catch (err) {
|
||||
next.push({ file: item.file, error: err instanceof Error ? err.message : "Couldn't convert it." });
|
||||
}
|
||||
}
|
||||
setItems(next);
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
const done = items.filter((item) => item.result);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="flex flex-wrap items-baseline gap-3">
|
||||
<h1 className="text-2xl font-bold text-link">Image converter</h1>
|
||||
<p className="text-sm" style={{ color: MUTED }}>
|
||||
Turn pictures into JPG, PNG or WebP. Done in your browser: nothing is uploaded.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<section className="mt-6 bg-raised p-5 shadow-md">
|
||||
<label
|
||||
htmlFor={inputId}
|
||||
onDragOver={(e) => {
|
||||
e.preventDefault();
|
||||
setOver(true);
|
||||
}}
|
||||
onDragLeave={() => setOver(false)}
|
||||
onDrop={(e) => {
|
||||
e.preventDefault();
|
||||
setOver(false);
|
||||
add(e.dataTransfer.files);
|
||||
}}
|
||||
className={`block cursor-pointer border-2 p-8 text-center text-sm transition-colors ${
|
||||
over ? "border-brand bg-tint" : "border-muted/30"
|
||||
}`}
|
||||
>
|
||||
<span className="font-semibold text-link">Choose pictures</span> or drop them here
|
||||
<span className="mt-1 block text-xs" style={{ color: MUTED }}>
|
||||
JPEG, PNG, WebP, GIF, AVIF, BMP or SVG (HEIC in Safari only)
|
||||
</span>
|
||||
<input
|
||||
id={inputId}
|
||||
type="file"
|
||||
accept="image/*,.heic,.heif"
|
||||
multiple
|
||||
className="sr-only"
|
||||
onChange={(e) => {
|
||||
add(e.target.files);
|
||||
e.target.value = "";
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<div className="mt-5 flex flex-wrap items-end gap-4">
|
||||
<div>
|
||||
<label htmlFor={formatId} className="block text-sm font-medium text-body">
|
||||
Save as
|
||||
</label>
|
||||
<select
|
||||
id={formatId}
|
||||
value={type}
|
||||
onChange={(e) => {
|
||||
setType(e.target.value as OutputType);
|
||||
setItems((current) => current.map(({ file }) => ({ file })));
|
||||
}}
|
||||
className="mt-1 border border-muted/25 bg-surface px-3 py-2 text-sm text-body"
|
||||
>
|
||||
{OUTPUT_FORMATS.map((format) => (
|
||||
<option key={format.type} value={format.type}>
|
||||
{format.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
{lossy && (
|
||||
<div>
|
||||
<label htmlFor={qualityId} className="block text-sm font-medium text-body">
|
||||
Quality: {quality}
|
||||
</label>
|
||||
<input
|
||||
id={qualityId}
|
||||
type="range"
|
||||
min={40}
|
||||
max={100}
|
||||
value={quality}
|
||||
onChange={(e) => {
|
||||
setQuality(Number(e.target.value));
|
||||
setItems((current) => current.map(({ file }) => ({ file })));
|
||||
}}
|
||||
className="mt-2 w-48 accent-[var(--color-action)]"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<button type="button" className={primary} disabled={busy || items.length === 0} onClick={convertAll}>
|
||||
{busy ? "Converting…" : `Convert ${items.length || ""}`.trim()}
|
||||
</button>
|
||||
{done.length > 1 && (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
onClick={() => done.forEach((item) => saveBlob(item.result as Blob, renamed(item.file.name, type)))}
|
||||
>
|
||||
Download all
|
||||
</button>
|
||||
)}
|
||||
{items.length > 0 && (
|
||||
<button type="button" className={button} disabled={busy} onClick={() => setItems([])}>
|
||||
Clear
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{type === "image/jpeg" && (
|
||||
<p className="mt-2 text-xs" style={{ color: MUTED }}>
|
||||
JPG has no transparency: see-through parts turn white.
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{items.length > 0 && (
|
||||
<ul className="mt-6 divide-y divide-brand/10 bg-raised shadow-md">
|
||||
{items.map((item, index) => (
|
||||
<li key={`${item.file.name}-${index}`} className="flex flex-wrap items-center gap-3 px-4 py-3 text-sm">
|
||||
<span className="min-w-0 flex-1 truncate text-body" title={item.file.name}>
|
||||
{item.file.name}
|
||||
</span>
|
||||
<span style={{ color: MUTED }}>{kb(item.file.size)}</span>
|
||||
{item.result ? (
|
||||
<>
|
||||
<span className="text-body">→ {kb(item.result.size)}</span>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
onClick={() => saveBlob(item.result as Blob, renamed(item.file.name, type))}
|
||||
>
|
||||
Download {renamed(item.file.name, type)}
|
||||
</button>
|
||||
</>
|
||||
) : item.error ? (
|
||||
<span className="text-danger">{item.error}</span>
|
||||
) : (
|
||||
<span style={{ color: MUTED }}>Ready</span>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -26,7 +26,7 @@ import { ArrowRight, ArrowUpRight } from "@phosphor-icons/react";
|
|||
import { Link } from "react-router-dom";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { useWideAdminPage } from "../../lib/adminWidth.tsx";
|
||||
import { SITE_VERSION } from "../../lib/version.ts";
|
||||
import { SITE_VERSION, VERSION_NAME } from "../../lib/version.ts";
|
||||
import { ROLE_LABELS, isSuper } from "../../lib/roles.ts";
|
||||
import { PALETTE } from "../../lib/color.ts";
|
||||
import { DATA_NAV, FORMS_NAV, PAGES_NAV, PANEL_NAV, TOOLS_NAV, target, visibleItems } from "./adminNav.ts";
|
||||
|
|
@ -187,7 +187,7 @@ export default function AdminHome() {
|
|||
</PanelSection>
|
||||
|
||||
<PanelSection title="Site">
|
||||
<p className="font-mono text-xs text-muted/80">{SITE_VERSION}</p>
|
||||
<p className="font-mono text-xs text-muted/80">{SITE_VERSION}{VERSION_NAME && ` · ${VERSION_NAME}`}</p>
|
||||
<a
|
||||
href="/"
|
||||
target="_blank"
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import { Link, NavLink, Outlet, useLocation, useNavigate } from "react-router-do
|
|||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { AdminTitleContext } from "../../lib/adminTitle.tsx";
|
||||
import { AdminWidthContext, type AdminWidth } from "../../lib/adminWidth.tsx";
|
||||
import { SITE_VERSION } from "../../lib/version.ts";
|
||||
import { SITE_VERSION, VERSION_NAME } from "../../lib/version.ts";
|
||||
import { ROLE_LABELS, isSuper } from "../../lib/roles.ts";
|
||||
import siteLogo from "../../assets/logos/NGU_Logo.svg";
|
||||
import ThemeToggle from "../../components/ThemeToggle.tsx";
|
||||
|
|
@ -226,7 +226,7 @@ export default function AdminLayout() {
|
|||
<img src={siteLogo} alt="NGU" className="h-6 w-auto" />
|
||||
</Link>
|
||||
<span className="ml-auto font-mono text-xs text-muted/70">
|
||||
{SITE_VERSION}
|
||||
{SITE_VERSION}{VERSION_NAME && ` · ${VERSION_NAME}`}
|
||||
</span>
|
||||
</div>
|
||||
</footer>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
a page (an image field stores the path, not a foreign key).
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import DownloadAs from "../../components/admin/DownloadAs.tsx";
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
|
|
@ -641,6 +642,9 @@ export default function AdminMedia() {
|
|||
>
|
||||
Open
|
||||
</a>
|
||||
{item.content_type?.startsWith("image/") && (
|
||||
<DownloadAs url={item.url} name={item.original_name} />
|
||||
)}
|
||||
{roleCanWrite(user) && (
|
||||
<RenameControl
|
||||
item={item}
|
||||
|
|
|
|||
|
|
@ -201,6 +201,11 @@ export const TOOLS_NAV = {
|
|||
label: "Media",
|
||||
blurb: "Uploaded images: logos, photos and backgrounds, ready to reuse.",
|
||||
},
|
||||
{
|
||||
to: "/admin/convert",
|
||||
label: "Image converter",
|
||||
blurb: "Turn pictures into JPG, PNG or WebP, in your browser. Images in Media can also be downloaded as any of them.",
|
||||
},
|
||||
{
|
||||
to: "/admin/clips",
|
||||
label: "Video clips",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue