Security: - docx unzip reads each part once (a repeated entry was a zip bomb) - request files must be named for their type (no PDF named .html) - team roster hidden when its organization is unpublished - /people?ids= hides draft organizations, takes 200 ids - v_events takes the first published host and reads event_hosts directly (migration 059, plus an index on person_awards.event_id) - group accounts refused while access groups are off; group sync can't undo a superadmin's disable - 64 KB body limit on login, feedback and csp-report - Drive pick-up races no longer 500; random upload boundary Scalability: - /events filters by scope, host, status and type on the server; Home no longer prefetches every event - /organizations leaves out bodies and leadership; the map's group panel fetches its own - admin lists page with Show more and a real count - content request record search and the newsletter's post list ask the server Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
3.3 KiB
TypeScript
77 lines
3.3 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
|
EVENT DATA
|
|
|
|
Events, narrowed by the server. Each filter is part of the path,
|
|
so the cache in api.ts gives each its own entry and callers
|
|
asking the same thing share one fetch.
|
|
|
|
useEvents({ scope: "national" }) one band
|
|
useEvents({ host: "northwest" }) one host's events
|
|
useEvents({ status: "upcoming" }) a home page strip
|
|
useEvents({ type: "workshop" }) one kind, wherever it is
|
|
useEvents({ type: ["class", "workshop"] })
|
|
useEvents() everything
|
|
|
|
`scope` and `type` are different questions and stack rather
|
|
than overlap: the scope is whose gathering an event is, the type
|
|
is what kind of gathering it is. A regional class matches both
|
|
{ scope: "regional" } and { type: "class" }.
|
|
|
|
The event_scopes rows come back alongside, for anything that
|
|
offers a scope filter.
|
|
|
|
No fallback. An empty list on a failed request would read as
|
|
"nothing scheduled" when the truth is "the server is down", so
|
|
the error comes back and each caller says so.
|
|
═══════════════════════════════════════════════════════════════ */
|
|
|
|
import { useResource } from "./useResource.ts";
|
|
|
|
/* Shared empty lists, so a memo keyed on them doesn't
|
|
restart on every render before the data arrives. */
|
|
const NO_SCOPES: any[] = [];
|
|
const NO_EVENTS: any[] = [];
|
|
|
|
/* The path for a filter, as the server reads it (routes/content.js). */
|
|
export function eventsPath({ scope, host, status, type }: any = {}) {
|
|
const query = new URLSearchParams();
|
|
if (scope) query.set("scope", scope);
|
|
// An organization or a person slug: co-hosting puts one event on
|
|
// both hosts' lists, which is the point.
|
|
if (host) query.set("host", host);
|
|
if (status) query.set("status", status);
|
|
const types = Array.isArray(type) ? type.join(",") : type;
|
|
if (types) query.set("type", types);
|
|
const qs = query.toString();
|
|
return qs ? `/events?${qs}` : "/events";
|
|
}
|
|
|
|
export function useEvents(filter: any = {}) {
|
|
const { data, error, loading } = useResource(eventsPath(filter));
|
|
const events = data?.events ?? NO_EVENTS;
|
|
const scopes = data?.scopes ?? NO_SCOPES;
|
|
return { events, scopes, loading, error };
|
|
}
|
|
|
|
/* Past and upcoming, split. `status` arrives already resolved, the
|
|
explicit value when there is one, otherwise derived from ends_on,
|
|
so nothing here needs to know which of the two it got. */
|
|
export function splitByStatus(events: any[] = []) {
|
|
const upcoming: any[] = [];
|
|
const past: any[] = [];
|
|
|
|
for (const event of events) {
|
|
(event.status === "past" ? past : upcoming).push(event);
|
|
}
|
|
|
|
return { upcoming, past };
|
|
}
|
|
|
|
/* Which of the declared types a list actually contains, in
|
|
EVENT_TYPES order rather than whatever order the rows arrived
|
|
in. A section with one type has nothing to filter, which is what
|
|
lets the chip bar hide itself. */
|
|
export function typesPresent(events: any[] = [], declared: any[] = []) {
|
|
const seen = new Set(events.map(e => e.event_type));
|
|
return declared.filter(entry => seen.has(entry.id));
|
|
}
|