More audit cleanup: shared route cache helper, url columns, tab keys
- One CACHE and json() in shape.js for the seven public route files - A url column type: link fields (13 of them) refuse javascript:, data: and any other scheme on save, not only when drawn - The chapter map's logo uses the shared Logo component - Schedule tabs take Home and End as well as the arrows Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
1c94ffb281
commit
d1a6332a45
12 changed files with 66 additions and 75 deletions
|
|
@ -35,6 +35,11 @@ export class HttpError extends Error {
|
||||||
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
const SLUG = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
||||||
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
||||||
const CLOCK_TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
const CLOCK_TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
||||||
|
// A url column may hold a full link, a site path, an anchor, a bare
|
||||||
|
// domain or a filename, but a scheme other than these is refused
|
||||||
|
// (javascript:, data:), whatever the page does with it later.
|
||||||
|
const URL_SCHEME = /^([a-z][a-z0-9+.-]*):/i;
|
||||||
|
const SAFE_SCHEMES = new Set(["http", "https", "mailto", "tel"]);
|
||||||
|
|
||||||
/* Not a value the caller can ever send, so it can mean "leave this
|
/* Not a value the caller can ever send, so it can mean "leave this
|
||||||
column out of the statement" without colliding with real data. */
|
column out of the statement" without colliding with real data. */
|
||||||
|
|
@ -106,6 +111,15 @@ function coerceValue(column, raw, errors, prefix = "") {
|
||||||
if (!CLOCK_TIME.test(value)) errors[key] = "Use HH:MM, 24-hour.";
|
if (!CLOCK_TIME.test(value)) errors[key] = "Use HH:MM, 24-hour.";
|
||||||
return CLOCK_TIME.test(value) ? value : null;
|
return CLOCK_TIME.test(value) ? value : null;
|
||||||
}
|
}
|
||||||
|
case "url": {
|
||||||
|
const value = String(raw).trim();
|
||||||
|
const scheme = URL_SCHEME.exec(value)?.[1].toLowerCase();
|
||||||
|
if (scheme && !SAFE_SCHEMES.has(scheme)) {
|
||||||
|
errors[key] = "Links must start with http://, https://, mailto: or tel:, or be a site path like /retreats.";
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return value === "" ? null : value;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
const value = String(raw).trim();
|
const value = String(raw).trim();
|
||||||
return value === "" ? null : value;
|
return value === "" ? null : value;
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,8 @@ import { THEME_TOKENS, checkTheme } from "./theme.js";
|
||||||
/* ── Column helpers ──────────────────────────────────────────── */
|
/* ── Column helpers ──────────────────────────────────────────── */
|
||||||
|
|
||||||
const text = (name, opts = {}) => ({ name, type: "text", ...opts });
|
const text = (name, opts = {}) => ({ name, type: "text", ...opts });
|
||||||
|
// Text that is a link: refuses javascript:, data: and other schemes.
|
||||||
|
const url = (name, opts = {}) => ({ name, type: "url", ...opts });
|
||||||
const int = (name, opts = {}) => ({ name, type: "int", ...opts });
|
const int = (name, opts = {}) => ({ name, type: "int", ...opts });
|
||||||
const real = (name, opts = {}) => ({ name, type: "real", ...opts });
|
const real = (name, opts = {}) => ({ name, type: "real", ...opts });
|
||||||
const bool = (name, opts = {}) => ({ name, type: "bool", ...opts });
|
const bool = (name, opts = {}) => ({ name, type: "bool", ...opts });
|
||||||
|
|
@ -95,7 +97,7 @@ const timelineFields = [
|
||||||
text("title"),
|
text("title"),
|
||||||
text("blurb"),
|
text("blurb"),
|
||||||
text("meta"),
|
text("meta"),
|
||||||
text("link_url"),
|
url("link_url"),
|
||||||
bool("is_featured"),
|
bool("is_featured"),
|
||||||
bool("is_published"),
|
bool("is_published"),
|
||||||
int("sort_order"),
|
int("sort_order"),
|
||||||
|
|
@ -138,7 +140,7 @@ const featuredCardsChild = (ownerKind) => ({
|
||||||
enumeration("kind", ["record", "link", "video"], { required: true }),
|
enumeration("kind", ["record", "link", "video"], { required: true }),
|
||||||
enumeration("ref_kind", ["event", "organization", "person", "team", "award"]),
|
enumeration("ref_kind", ["event", "organization", "person", "team", "award"]),
|
||||||
text("ref_id"),
|
text("ref_id"),
|
||||||
text("url"),
|
url("url"),
|
||||||
text("eyebrow"),
|
text("eyebrow"),
|
||||||
text("title"),
|
text("title"),
|
||||||
text("blurb"),
|
text("blurb"),
|
||||||
|
|
@ -158,7 +160,7 @@ const linksChild = (ownerKind) => ({
|
||||||
}),
|
}),
|
||||||
text("platform"),
|
text("platform"),
|
||||||
text("label", { required: true }),
|
text("label", { required: true }),
|
||||||
text("url", { required: true }),
|
url("url", { required: true }),
|
||||||
bool("is_primary"),
|
bool("is_primary"),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
@ -190,7 +192,7 @@ const blocksChild = (ownerKind) => ({
|
||||||
),
|
),
|
||||||
text("text"),
|
text("text"),
|
||||||
text("media"),
|
text("media"),
|
||||||
text("href"),
|
url("href"),
|
||||||
text("alt"),
|
text("alt"),
|
||||||
text("cite"),
|
text("cite"),
|
||||||
],
|
],
|
||||||
|
|
@ -203,7 +205,7 @@ const blocksChild = (ownerKind) => ({
|
||||||
columns: [
|
columns: [
|
||||||
text("text", { required: true }),
|
text("text", { required: true }),
|
||||||
text("detail"),
|
text("detail"),
|
||||||
text("url"),
|
url("url"),
|
||||||
// Schedule entries only (034_schedule_block.sql).
|
// Schedule entries only (034_schedule_block.sql).
|
||||||
text("day"),
|
text("day"),
|
||||||
text("time"),
|
text("time"),
|
||||||
|
|
@ -731,13 +733,13 @@ const frontPage = {
|
||||||
text("headline"),
|
text("headline"),
|
||||||
text("subhead"),
|
text("subhead"),
|
||||||
text("primary_label"),
|
text("primary_label"),
|
||||||
text("primary_url"),
|
url("primary_url"),
|
||||||
text("secondary_label"),
|
text("secondary_label"),
|
||||||
text("secondary_url"),
|
url("secondary_url"),
|
||||||
int("slide_seconds"),
|
int("slide_seconds"),
|
||||||
text("livestream_url"),
|
url("livestream_url"),
|
||||||
text("livestream_title"),
|
text("livestream_title"),
|
||||||
text("video_url"),
|
url("video_url"),
|
||||||
text("video_title"),
|
text("video_title"),
|
||||||
text("countdown_event_id"),
|
text("countdown_event_id"),
|
||||||
text("countdown_scope_id"),
|
text("countdown_scope_id"),
|
||||||
|
|
@ -754,7 +756,7 @@ const frontPage = {
|
||||||
text("media", { required: true }),
|
text("media", { required: true }),
|
||||||
text("alt"),
|
text("alt"),
|
||||||
text("caption"),
|
text("caption"),
|
||||||
text("link_url"),
|
url("link_url"),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -812,7 +814,7 @@ const frontPage = {
|
||||||
columns: [
|
columns: [
|
||||||
text("label", { required: true }),
|
text("label", { required: true }),
|
||||||
text("description"),
|
text("description"),
|
||||||
text("url", { required: true }),
|
url("url", { required: true }),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -888,7 +890,7 @@ const communityPage = {
|
||||||
int("internal_slots"),
|
int("internal_slots"),
|
||||||
text("external_title"),
|
text("external_title"),
|
||||||
int("external_slots"),
|
int("external_slots"),
|
||||||
text("external_url"),
|
url("external_url"),
|
||||||
text("external_label"),
|
text("external_label"),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
@ -906,7 +908,7 @@ const communityPage = {
|
||||||
table: "community_page_feeds",
|
table: "community_page_feeds",
|
||||||
owner: { column: "page_id" },
|
owner: { column: "page_id" },
|
||||||
order: "sort_order",
|
order: "sort_order",
|
||||||
columns: [text("url", { required: true }), text("label")],
|
columns: [url("url", { required: true }), text("label")],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -24,16 +24,11 @@
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
import { asBool, loadBlocks, marks, loadFeaturedCards, paragraphs } from "../shape.js";
|
import { asBool, json, loadBlocks, loadFeaturedCards, marks, paragraphs } from "../shape.js";
|
||||||
import { readFeeds } from "../feeds.js";
|
import { readFeeds } from "../feeds.js";
|
||||||
|
|
||||||
const blog = new Hono();
|
const blog = new Hono();
|
||||||
|
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
|
|
||||||
|
|
||||||
|
|
||||||
const PAGE_ID = "community";
|
const PAGE_ID = "community";
|
||||||
|
|
||||||
const splitTags = (tags) =>
|
const splitTags = (tags) =>
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ import { Hono } from "hono";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
asBool,
|
asBool,
|
||||||
|
json,
|
||||||
loadBlocks,
|
loadBlocks,
|
||||||
loadLinks,
|
loadLinks,
|
||||||
marks,
|
marks,
|
||||||
|
|
@ -67,13 +68,9 @@ const content = new Hono();
|
||||||
// Content changes weekly at most, and a stale minute costs nobody
|
// Content changes weekly at most, and a stale minute costs nobody
|
||||||
// anything. stale-while-revalidate keeps the page instant while the
|
// anything. stale-while-revalidate keeps the page instant while the
|
||||||
// refresh happens behind it.
|
// refresh happens behind it.
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
|
|
||||||
|
|
||||||
const ORG_KINDS = ["national", "region", "chapter", "partner"];
|
const ORG_KINDS = ["national", "region", "chapter", "partner"];
|
||||||
|
|
||||||
|
|
||||||
/* ── Loaders ───────────────────────────────────────────────── */
|
/* ── Loaders ───────────────────────────────────────────────── */
|
||||||
|
|
||||||
/* Hosts for a batch of events, keyed by event id, in the order
|
/* Hosts for a batch of events, keyed by event id, in the order
|
||||||
|
|
@ -484,7 +481,6 @@ content.get("/events", (c) => {
|
||||||
return json(c, { scopes, events });
|
return json(c, { scopes, events });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* One event, for its own page. */
|
/* One event, for its own page. */
|
||||||
content.get("/events/:id", (c) => {
|
content.get("/events/:id", (c) => {
|
||||||
const db = c.get("db");
|
const db = c.get("db");
|
||||||
|
|
@ -541,7 +537,6 @@ content.get("/events/:id", (c) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* ── Organizations ─────────────────────────────────────────────
|
/* ── Organizations ─────────────────────────────────────────────
|
||||||
GET /organizations every published, listed org
|
GET /organizations every published, listed org
|
||||||
GET /organizations?kind=region one kind
|
GET /organizations?kind=region one kind
|
||||||
|
|
@ -596,7 +591,6 @@ content.get("/organizations", (c) => {
|
||||||
return json(c, { organizations });
|
return json(c, { organizations });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* One organization's page: region, chapter, partner or NGU. */
|
/* One organization's page: region, chapter, partner or NGU. */
|
||||||
content.get("/organizations/:id", (c) => {
|
content.get("/organizations/:id", (c) => {
|
||||||
const db = c.get("db");
|
const db = c.get("db");
|
||||||
|
|
@ -640,7 +634,6 @@ content.get("/organizations/:id", (c) => {
|
||||||
return json(c, { organization });
|
return json(c, { organization });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* ── Teams ─────────────────────────────────────────────────────
|
/* ── Teams ─────────────────────────────────────────────────────
|
||||||
GET /teams every published, listed team
|
GET /teams every published, listed team
|
||||||
GET /teams?org=mid-atlantic one organization's teams
|
GET /teams?org=mid-atlantic one organization's teams
|
||||||
|
|
@ -676,7 +669,6 @@ content.get("/teams", (c) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
content.get("/teams/:id", (c) => {
|
content.get("/teams/:id", (c) => {
|
||||||
const db = c.get("db");
|
const db = c.get("db");
|
||||||
const id = c.req.param("id");
|
const id = c.req.param("id");
|
||||||
|
|
@ -699,7 +691,6 @@ content.get("/teams/:id", (c) => {
|
||||||
return json(c, { team: { ...shapeTeam(row, links, cards), blocks: body } });
|
return json(c, { team: { ...shapeTeam(row, links, cards), blocks: body } });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/* ── Awards ────────────────────────────────────────────────────
|
/* ── Awards ────────────────────────────────────────────────────
|
||||||
GET /awards every award
|
GET /awards every award
|
||||||
GET /awards?org=ngu awards a given organization gives
|
GET /awards?org=ngu awards a given organization gives
|
||||||
|
|
@ -738,7 +729,6 @@ content.get("/awards", (c) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
content.get("/awards/:id", (c) => {
|
content.get("/awards/:id", (c) => {
|
||||||
const db = c.get("db");
|
const db = c.get("db");
|
||||||
const id = c.req.param("id");
|
const id = c.req.param("id");
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,10 @@
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
import { CACHE } from "../shape.js";
|
||||||
|
|
||||||
const directory = new Hono();
|
const directory = new Hono();
|
||||||
|
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
directory.get("/directory", (c) => {
|
directory.get("/directory", (c) => {
|
||||||
const db = c.get("db");
|
const db = c.get("db");
|
||||||
const all = (sql) => db.prepare(sql).all();
|
const all = (sql) => db.prepare(sql).all();
|
||||||
|
|
|
||||||
|
|
@ -31,15 +31,10 @@
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
import { marks } from "../shape.js";
|
import { json, marks } from "../shape.js";
|
||||||
|
|
||||||
const history = new Hono();
|
const history = new Hono();
|
||||||
|
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
|
|
||||||
|
|
||||||
|
|
||||||
/* 'YYYY' → year, 'YYYY-MM' → month, 'YYYY-MM-DD' → day. */
|
/* 'YYYY' → year, 'YYYY-MM' → month, 'YYYY-MM-DD' → day. */
|
||||||
function precisionOfString(date) {
|
function precisionOfString(date) {
|
||||||
const parts = String(date).split("-");
|
const parts = String(date).split("-");
|
||||||
|
|
|
||||||
|
|
@ -48,14 +48,10 @@
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
import { asBool, loadFeaturedCards, loadLinks, shapeSeries, splitLinks } from "../shape.js";
|
import { asBool, json, loadFeaturedCards, loadLinks, shapeSeries, splitLinks } from "../shape.js";
|
||||||
|
|
||||||
const home = new Hono();
|
const home = new Hono();
|
||||||
|
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
|
|
||||||
|
|
||||||
const PAGE_ID = "home";
|
const PAGE_ID = "home";
|
||||||
|
|
||||||
const STAT_QUERIES = {
|
const STAT_QUERIES = {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import { fileURLToPath } from "node:url";
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js";
|
import { metaFor, renderPage, robotsTxt, siteFor, sitemap } from "../pageMeta.js";
|
||||||
|
import { CACHE } from "../shape.js";
|
||||||
|
|
||||||
const here = path.dirname(fileURLToPath(import.meta.url));
|
const here = path.dirname(fileURLToPath(import.meta.url));
|
||||||
|
|
||||||
|
|
@ -43,8 +44,6 @@ export const SITE_INDEX = path.resolve(
|
||||||
process.env.SITE_INDEX ?? path.join(here, "../../../dist/index.html"),
|
process.env.SITE_INDEX ?? path.join(here, "../../../dist/index.html"),
|
||||||
);
|
);
|
||||||
|
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
let cached = { mtime: 0, html: null };
|
let cached = { mtime: 0, html: null };
|
||||||
|
|
||||||
function indexHtml() {
|
function indexHtml() {
|
||||||
|
|
|
||||||
|
|
@ -21,15 +21,10 @@
|
||||||
|
|
||||||
import { Hono } from "hono";
|
import { Hono } from "hono";
|
||||||
|
|
||||||
import { asBool, loadBlocks, loadLinks, marks, paragraphs, splitLinks } from "../shape.js";
|
import { asBool, json, loadBlocks, loadLinks, marks, paragraphs, splitLinks } from "../shape.js";
|
||||||
|
|
||||||
const people = new Hono();
|
const people = new Hono();
|
||||||
|
|
||||||
const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
|
||||||
|
|
||||||
const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
|
|
||||||
|
|
||||||
|
|
||||||
/* How many slugs one request may name. Keeps the URL sane. */
|
/* How many slugs one request may name. Keeps the URL sane. */
|
||||||
const MAX_IDS = 50;
|
const MAX_IDS = 50;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -302,5 +302,10 @@ export function loadFeaturedCards(db, ownerKind, ownerId) {
|
||||||
|
|
||||||
export { asBool };
|
export { asBool };
|
||||||
|
|
||||||
|
/* Public reads may be cached a minute, and served a little stale
|
||||||
|
while a fresh copy is fetched. json() sends a body with it. */
|
||||||
|
export const CACHE = "public, max-age=60, stale-while-revalidate=300";
|
||||||
|
export const json = (c, body) => c.json(body, 200, { "Cache-Control": CACHE });
|
||||||
|
|
||||||
// "?,?,?" for an IN (...) list of n values.
|
// "?,?,?" for an IN (...) list of n values.
|
||||||
export const marks = (n) => Array(n).fill("?").join(",");
|
export const marks = (n) => Array(n).fill("?").join(",");
|
||||||
|
|
|
||||||
|
|
@ -224,11 +224,17 @@ export default function ScheduleBlock({
|
||||||
if (days.length === 0) return null
|
if (days.length === 0) return null
|
||||||
const current = days[Math.min(active, days.length - 1)]
|
const current = days[Math.min(active, days.length - 1)]
|
||||||
|
|
||||||
|
// Arrows move one tab and wrap; Home and End jump to the ends.
|
||||||
const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {
|
const onKey = (e: KeyboardEvent<HTMLButtonElement>) => {
|
||||||
const step = e.key === 'ArrowRight' ? 1 : e.key === 'ArrowLeft' ? -1 : 0
|
const last = days.length - 1
|
||||||
if (!step) return
|
const next =
|
||||||
|
e.key === 'ArrowRight' ? (active + 1) % days.length
|
||||||
|
: e.key === 'ArrowLeft' ? (active + last) % days.length
|
||||||
|
: e.key === 'Home' ? 0
|
||||||
|
: e.key === 'End' ? last
|
||||||
|
: null
|
||||||
|
if (next === null) return
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const next = (active + step + days.length) % days.length
|
|
||||||
setActive(next)
|
setActive(next)
|
||||||
document.getElementById(`${baseId}-tab-${next}`)?.focus()
|
document.getElementById(`${baseId}-tab-${next}`)?.focus()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { useCommunity } from "../../lib/chapters.ts";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import ArrowLink from "../../components/ArrowLink.tsx";
|
import ArrowLink from "../../components/ArrowLink.tsx";
|
||||||
import { mediaUrl } from "../../lib/media.ts";
|
import { mediaUrl } from "../../lib/media.ts";
|
||||||
|
import Logo from "../../components/Logo.tsx";
|
||||||
import { initialsFor, orgPath } from "../../lib/organizations.ts";
|
import { initialsFor, orgPath } from "../../lib/organizations.ts";
|
||||||
import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts";
|
import { AREAS, AREA_NAMES } from "../../data/mapGrid.ts";
|
||||||
import { withAlpha, accentText, readableOn } from '../../lib/color.ts'
|
import { withAlpha, accentText, readableOn } from '../../lib/color.ts'
|
||||||
|
|
@ -466,29 +467,23 @@ function RegionBlock({
|
||||||
color. Selecting another card swaps the panel's contents.
|
color. Selecting another card swaps the panel's contents.
|
||||||
═══════════════════════════════════════════════════════════════ */
|
═══════════════════════════════════════════════════════════════ */
|
||||||
|
|
||||||
/* Logo, or the organization's initials when there's no file. */
|
/* Logo, or the organization's initials when there's no file or it
|
||||||
|
fails to load. Decorative: the name is right beside it. */
|
||||||
function OrgLogo({ org, color, size = "h-14 w-14" }) {
|
function OrgLogo({ org, color, size = "h-14 w-14" }) {
|
||||||
const [failed, setFailed] = useState(false);
|
|
||||||
|
|
||||||
if (org.logo && !failed) {
|
|
||||||
return (
|
return (
|
||||||
<img
|
<Logo
|
||||||
src={mediaUrl(org.logo) ?? undefined}
|
src={mediaUrl(org.logo)}
|
||||||
alt={org.name}
|
|
||||||
onError={() => setFailed(true)}
|
|
||||||
className={`${size} object-contain rounded-xl shrink-0`}
|
className={`${size} object-contain rounded-xl shrink-0`}
|
||||||
/>
|
fallback={
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
<div
|
||||||
className={`${size} rounded-xl shrink-0 flex items-center justify-center font-extrabold`}
|
className={`${size} rounded-xl shrink-0 flex items-center justify-center font-extrabold`}
|
||||||
style={{ border: `1px solid ${color}`, color }}
|
style={{ border: `1px solid ${color}`, color: accentText(color) }}
|
||||||
aria-label={org.name}
|
aria-hidden="true"
|
||||||
>
|
>
|
||||||
{initialsFor(org.name)}
|
{initialsFor(org.name)}
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue