Third audit, UI half; side nav on top; request button colors
- Event cards: lazy -640 photo, only nearby slides drawn, a counter past 12 events, past grid paged with Show more - Community map: search over list and grid, 12 per region then Show all, list no longer redrawn on hover - People tiles: one clip check for the list, Show all past 30 - Person pages: 6 events and posts then Show all; excerpts load only the first paragraph - Admin: filter box on long pickers and the QR select, options sent per form, Media thumbnails from the small copy, debounced searches that drop stale answers - Pages show their last data while refreshing after the cache TTL - Side nav stacks above page content (the carousel arrows) - No event request button on National Retreats; request buttons take their section's accent - Version v1.11.1-audit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
11a4555683
commit
222c9e69a2
22 changed files with 686 additions and 259 deletions
53
src/components/OptionFilter.tsx
Normal file
53
src/components/OptionFilter.tsx
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
OPTION FILTER
|
||||
|
||||
A select over hundreds of records (every person, every event)
|
||||
only matches first letters as you type, so finding one means
|
||||
scrolling. Past FILTER_FROM options, a small box above it narrows
|
||||
the list to the options whose label holds what's typed:
|
||||
|
||||
const [needle, setNeedle] = useState('')
|
||||
const shown = narrow(list, needle, ([, label]) => label, ([id]) => id === value)
|
||||
{list.length > FILTER_FROM && <OptionFilter value={needle} onChange={setNeedle} ... />}
|
||||
|
||||
`keep` holds an option in whatever the box says (the one chosen),
|
||||
so narrowing never blanks the select's value.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { MagnifyingGlass } from '@phosphor-icons/react'
|
||||
|
||||
export const FILTER_FROM = 50
|
||||
|
||||
export function narrow<T>(items: T[], needle: string, text: (item: T) => string, keep?: (item: T) => boolean): T[] {
|
||||
const term = needle.trim().toLowerCase()
|
||||
if (!term) return items
|
||||
return items.filter((item) => keep?.(item) || String(text(item) ?? '').toLowerCase().includes(term))
|
||||
}
|
||||
|
||||
type OptionFilterProps = {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
label: string
|
||||
className?: string
|
||||
}
|
||||
|
||||
export function OptionFilter({ value, onChange, label, className = 'mb-1.5' }: OptionFilterProps) {
|
||||
return (
|
||||
<div className={`relative ${className}`}>
|
||||
<MagnifyingGlass
|
||||
size={16}
|
||||
weight="bold"
|
||||
aria-hidden="true"
|
||||
className="pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 text-muted"
|
||||
/>
|
||||
<input
|
||||
type="search"
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
aria-label={label}
|
||||
placeholder="Type to narrow the list"
|
||||
className="w-full border border-muted/25 bg-surface py-1.5 pl-8 pr-3 text-sm text-body outline-none transition-colors focus:border-brand focus:ring-2 focus:ring-brand/25"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
|
@ -294,10 +294,13 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
clipping sideways only, so nothing reaches the
|
||||
content or the screen's edge. clip, not hidden: hidden
|
||||
would make it a scroll container, and the sticky layers in
|
||||
it would stop sticking. */}
|
||||
it would stop sticking. z-20: in front of everything in the
|
||||
sections, such as a carousel's arrows (z-10), which as later
|
||||
siblings would otherwise draw over it; it takes no clicks
|
||||
itself, only its list does. */}
|
||||
<aside
|
||||
ref={columnRef}
|
||||
className="absolute inset-y-0 left-0 hidden overflow-x-clip 2xl:block"
|
||||
className="pointer-events-none absolute inset-y-0 left-0 z-20 hidden overflow-x-clip 2xl:block"
|
||||
style={{ width: "calc((100% - 72rem) / 2 + 1rem)" }}
|
||||
>
|
||||
{/* A solid circle centered on the list, in the light shade
|
||||
|
|
@ -322,7 +325,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
) : null}
|
||||
{/* The list, in front of the section lines and its circle. */}
|
||||
<div className="sticky z-10 pl-4 pr-2" style={{ top: stickAt(listTop), paddingTop: listTop }}>
|
||||
<div ref={listRef} className="w-fit max-w-full">
|
||||
<div ref={listRef} className="pointer-events-auto w-fit max-w-full">
|
||||
<SectionNav sections={navSections} wrap />
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { ArrowRight, CaretDown, X } from "@phosphor-icons/react";
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useId,
|
||||
useLayoutEffect,
|
||||
|
|
@ -153,6 +154,9 @@ export interface PeopleTilesProps
|
|||
onExpand?: (person: Person | null, group: PeopleGroup | null) => void;
|
||||
}
|
||||
|
||||
/* A list longer than this shows this many tiles, then "Show all". */
|
||||
const SHOW_FIRST = 30;
|
||||
|
||||
const SIZE_FEATURES: Record<PeopleTilesSize, { title: boolean; details: boolean }> = {
|
||||
sm: { title: false, details: false },
|
||||
md: { title: true, details: false },
|
||||
|
|
@ -444,6 +448,21 @@ export function PeopleTilesView({
|
|||
|
||||
const hasPeople = resolvedGroups.length > 0;
|
||||
|
||||
// A long list shows its first SHOW_FIRST tiles until "Show all".
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
const total = resolvedGroups.reduce((sum, group) => sum + group.people.length, 0);
|
||||
const shownGroups = useMemo<PeopleGroup[]>(() => {
|
||||
if (showAll || total <= SHOW_FIRST) return resolvedGroups;
|
||||
let left = SHOW_FIRST;
|
||||
const out: PeopleGroup[] = [];
|
||||
for (const group of resolvedGroups) {
|
||||
if (left <= 0) break;
|
||||
out.push({ ...group, people: group.people.slice(0, left) });
|
||||
left -= group.people.length;
|
||||
}
|
||||
return out;
|
||||
}, [resolvedGroups, showAll, total]);
|
||||
|
||||
// How much room a row has, and one tile's width and gap there, in
|
||||
// px: the probe carries --pl-w and --pl-gap, so the CSS stays the
|
||||
// one place that sizes tiles.
|
||||
|
|
@ -463,6 +482,34 @@ export function PeopleTilesView({
|
|||
return () => observer.disconnect();
|
||||
}, [overflow, hasPeople]);
|
||||
|
||||
// Which captions are cut off, every tile in one pass: after each
|
||||
// render that can change it (the room, the people, the title line)
|
||||
// and once the web font has arrived, since it changes text widths
|
||||
// without resizing anything.
|
||||
const checkClips = useCallback(() => {
|
||||
const root = rootRef.current;
|
||||
if (!root) return;
|
||||
const next = new Set<string>();
|
||||
for (const caption of root.querySelectorAll<HTMLElement>("[data-clip-key]")) {
|
||||
if (Array.from(caption.children).some((line) => line.scrollHeight > line.clientHeight + 1)) {
|
||||
next.add(caption.dataset.clipKey!);
|
||||
}
|
||||
}
|
||||
setClipped((current) =>
|
||||
current.size === next.size && [...next].every((key) => current.has(key)) ? current : next,
|
||||
);
|
||||
}, []);
|
||||
|
||||
useLayoutEffect(checkClips, [checkClips, room, shownGroups, features.title]);
|
||||
|
||||
useEffect(() => {
|
||||
let live = true;
|
||||
document.fonts?.ready.then(() => live && checkClips());
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [checkClips]);
|
||||
|
||||
// A click anywhere outside the list closes the panel.
|
||||
useEffect(() => {
|
||||
if (!openKey) return undefined;
|
||||
|
|
@ -489,23 +536,13 @@ export function PeopleTilesView({
|
|||
const open = openKey ? findByKey(resolvedGroups, openKey) : null;
|
||||
const oneRow =
|
||||
room !== null && overflow !== "scroll" &&
|
||||
fitsOneRow(resolvedGroups.map((group) => group.people.length), room.width, room.tile, room.gap);
|
||||
fitsOneRow(shownGroups.map((group) => group.people.length), room.width, room.tile, room.gap);
|
||||
const anchored = overflow !== "scroll";
|
||||
const closePanel = () => {
|
||||
setOpenKey(null);
|
||||
onExpand?.(null, null);
|
||||
};
|
||||
|
||||
function markClipped(key: string, isClipped: boolean) {
|
||||
setClipped((current) => {
|
||||
if (current.has(key) === isClipped) return current;
|
||||
const next = new Set(current);
|
||||
if (isClipped) next.add(key);
|
||||
else next.delete(key);
|
||||
return next;
|
||||
});
|
||||
}
|
||||
|
||||
function toggle(group: PeopleGroup, person: Person, index: number) {
|
||||
const key = keyFor(group, person, index);
|
||||
const next = openKey === key ? null : key;
|
||||
|
|
@ -544,7 +581,7 @@ export function PeopleTilesView({
|
|||
>
|
||||
<span ref={probeRef} className="pl__probe" aria-hidden="true" />
|
||||
<div className="pl__groups" data-row={oneRow ? "one" : undefined}>
|
||||
{resolvedGroups.map((group) => (
|
||||
{shownGroups.map((group) => (
|
||||
<section
|
||||
key={group.id}
|
||||
className="pl__group"
|
||||
|
|
@ -598,7 +635,7 @@ export function PeopleTilesView({
|
|||
isOpen={isOpen}
|
||||
panelId={`${baseId}-bio`}
|
||||
onToggle={() => toggle(group, person, index)}
|
||||
onClip={(isClipped) => markClipped(key, isClipped)}
|
||||
clipKey={key}
|
||||
/>
|
||||
{isOpen && anchored && open && (
|
||||
<DetailPanel
|
||||
|
|
@ -617,6 +654,16 @@ export function PeopleTilesView({
|
|||
))}
|
||||
</div>
|
||||
|
||||
{!showAll && total > SHOW_FIRST && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAll(true)}
|
||||
className="btn mt-4 border border-brand/40 px-5 py-2 text-sm text-link hover:border-brand"
|
||||
>
|
||||
Show all {total}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{open && !anchored && (
|
||||
<DetailPanel
|
||||
id={`${baseId}-bio`}
|
||||
|
|
@ -636,7 +683,7 @@ function Tile({
|
|||
isOpen,
|
||||
panelId,
|
||||
onToggle,
|
||||
onClip,
|
||||
clipKey,
|
||||
}: {
|
||||
person: Person;
|
||||
showTitle: boolean;
|
||||
|
|
@ -644,36 +691,20 @@ function Tile({
|
|||
isOpen: boolean;
|
||||
panelId: string;
|
||||
onToggle: () => void;
|
||||
onClip: (isClipped: boolean) => void;
|
||||
clipKey: string;
|
||||
}) {
|
||||
const title = titleOf(person);
|
||||
const captionRef = useRef<HTMLSpanElement>(null);
|
||||
|
||||
// Every caption is the same height (two lines of name, two of
|
||||
// title), so the row stays even; a name or title that needs more
|
||||
// is cut with an ellipsis. Checked again whenever the tile resizes,
|
||||
// which is also when the web font arrives.
|
||||
useLayoutEffect(() => {
|
||||
const caption = captionRef.current;
|
||||
if (!caption) return undefined;
|
||||
const check = () =>
|
||||
onClip(
|
||||
Array.from(caption.children).some((line) => line.scrollHeight > line.clientHeight + 1),
|
||||
);
|
||||
check();
|
||||
const observer = new ResizeObserver(check);
|
||||
observer.observe(caption);
|
||||
return () => observer.disconnect();
|
||||
// onClip is a fresh closure each render; the name and title are
|
||||
// what can change the answer.
|
||||
}, [person.name, title, showTitle]);
|
||||
|
||||
// is cut with an ellipsis, and the list (checkClips) gives it the
|
||||
// down arrow.
|
||||
const content = (
|
||||
<span className="pl__frame">
|
||||
<span className="pl__photo">
|
||||
<Photo src={mediaUrl(person.photo)} name={person.name} />
|
||||
</span>
|
||||
<span ref={captionRef} className="pl__caption" data-title={showTitle ? "on" : "off"}>
|
||||
<span className="pl__caption" data-clip-key={clipKey} data-title={showTitle ? "on" : "off"}>
|
||||
<span className="pl__name">{person.name}</span>
|
||||
{showTitle && title && <span className="pl__title">{title}</span>}
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -2,14 +2,33 @@ import { Link } from "react-router-dom";
|
|||
import { PaperPlaneTilt } from "@phosphor-icons/react";
|
||||
|
||||
import { requestLink } from "../data/requestTypes.ts";
|
||||
import { BRAND, accentText, withAlpha } from "../lib/color.ts";
|
||||
|
||||
/* A button to the Request form, opened on one kind of request
|
||||
(REQUEST_TYPES). Section manifests place it with `request`. */
|
||||
export default function RequestLink({ type, label, className = "" }: { type: string; label: string; className?: string }) {
|
||||
(REQUEST_TYPES), in its section's accent. Section manifests place
|
||||
it with `request`. */
|
||||
export default function RequestLink({
|
||||
type,
|
||||
label,
|
||||
accent = BRAND,
|
||||
className = "",
|
||||
}: {
|
||||
type: string;
|
||||
label: string;
|
||||
accent?: string;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<Link
|
||||
to={requestLink(type)}
|
||||
className={`inline-flex items-center gap-2 btn border border-brand/40 px-4 py-2 text-sm text-link transition-colors hover:bg-tint print:hidden ${className}`}
|
||||
className={`inline-flex items-center gap-2 btn border px-4 py-2 text-sm transition-colors hover:bg-[var(--request-hover)] print:hidden ${className}`}
|
||||
style={
|
||||
{
|
||||
borderColor: withAlpha(accent, 40),
|
||||
color: accentText(accent),
|
||||
"--request-hover": withAlpha(accent, 10),
|
||||
} as React.CSSProperties
|
||||
}
|
||||
>
|
||||
<PaperPlaneTilt aria-hidden="true" weight="bold" className="h-4 w-4" />
|
||||
{label}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import { useCallback, useEffect, useRef, useState, type ReactNode } from "react"
|
|||
import { ApiError, get, upload } from "../../lib/api.ts";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { canWrite as roleCanWrite } from "../../lib/roles.ts";
|
||||
import { formatBytes } from "./MediaLibrary.tsx";
|
||||
import { formatBytes, SEARCH_PAUSE_MS } from "./MediaLibrary.tsx";
|
||||
|
||||
export type DriveFile = {
|
||||
id: number;
|
||||
|
|
@ -115,21 +115,30 @@ export function useDriveFiles(query: string) {
|
|||
// Files in the Drive folder that Drive wouldn't share publicly.
|
||||
const [refused, setRefused] = useState<string[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// Only the newest request may write (a slow earlier search mustn't
|
||||
// replace a later one's list).
|
||||
const latest = useRef(0);
|
||||
|
||||
const reload = useCallback(() => {
|
||||
const ask = ++latest.current;
|
||||
const q = query.trim();
|
||||
setError(null);
|
||||
get(`/admin/files${q ? `?q=${encodeURIComponent(q)}` : ""}`, { ttl: 0 })
|
||||
.then((data) => {
|
||||
if (ask !== latest.current) return;
|
||||
setItems(data.files);
|
||||
setFolders(data.folders ?? []);
|
||||
setReady(data.ready);
|
||||
setRefused(data.refused ?? []);
|
||||
})
|
||||
.catch((err) => setError(err instanceof ApiError ? err.message : "Couldn't load the files."));
|
||||
.catch((err) => ask === latest.current && setError(err instanceof ApiError ? err.message : "Couldn't load the files."));
|
||||
}, [query]);
|
||||
|
||||
useEffect(reload, [reload]);
|
||||
// A search waits for a pause in the typing; the first load doesn't.
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(reload, query.trim() ? SEARCH_PAUSE_MS : 0);
|
||||
return () => clearTimeout(timer);
|
||||
}, [reload]);
|
||||
return { items, folders, ready, refused, error, reload, setItems };
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import { useLocation } from "react-router-dom";
|
|||
import { ApiError, get, post, upload } from "../../lib/api.ts";
|
||||
import { useAuth } from "../../lib/auth.tsx";
|
||||
import { canWrite as roleCanWrite } from "../../lib/roles.ts";
|
||||
import { useSmallImage } from "../../lib/useSmallImage.ts";
|
||||
|
||||
export type MediaItem = {
|
||||
id: number;
|
||||
|
|
@ -138,14 +139,23 @@ export function uploadImage(file: File, keepOriginal: boolean, folder?: string):
|
|||
return upload("/admin/media", form).then((data) => data.media);
|
||||
}
|
||||
|
||||
/* How long a search waits after the last keystroke. */
|
||||
export const SEARCH_PAUSE_MS = 250;
|
||||
/* The most the library route sends (MAX_LIST, server/src/routes/media.js). */
|
||||
const MEDIA_LIST_MAX = 500;
|
||||
|
||||
/* `type` narrows to one kind of file: image fields pick images only.
|
||||
Blank lists everything, videos and audio saved from the clip tool
|
||||
included. */
|
||||
export function useMediaLibrary(query: string, type?: "image" | "video" | "audio", folder?: string) {
|
||||
const [items, setItems] = useState<MediaItem[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
// Only the newest request may write: a slow answer to an earlier
|
||||
// search mustn't replace the list for a later one.
|
||||
const latest = useRef(0);
|
||||
|
||||
const reload = useCallback(() => {
|
||||
const ask = ++latest.current;
|
||||
const q = query.trim();
|
||||
const params = new URLSearchParams();
|
||||
if (q) params.set("q", q);
|
||||
|
|
@ -153,13 +163,17 @@ export function useMediaLibrary(query: string, type?: "image" | "video" | "audio
|
|||
if (folder) params.set("folder", folder);
|
||||
setError(null);
|
||||
get(`/admin/media${params.size ? `?${params}` : ""}`, { ttl: 0 })
|
||||
.then((data) => setItems(data.media))
|
||||
.then((data) => ask === latest.current && setItems(data.media))
|
||||
.catch((err) =>
|
||||
setError(err instanceof ApiError ? err.message : "Couldn't load the library."),
|
||||
ask === latest.current && setError(err instanceof ApiError ? err.message : "Couldn't load the library."),
|
||||
);
|
||||
}, [query, type, folder]);
|
||||
|
||||
useEffect(reload, [reload]);
|
||||
// A search waits for a pause in the typing; anything else asks at once.
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(reload, query.trim() ? SEARCH_PAUSE_MS : 0);
|
||||
return () => clearTimeout(timer);
|
||||
}, [reload]);
|
||||
|
||||
return { items, error, reload, setItems };
|
||||
}
|
||||
|
|
@ -263,62 +277,70 @@ export function MediaGrid({
|
|||
}
|
||||
|
||||
return (
|
||||
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{items.map((item) => {
|
||||
const isSelected = selected === item.url;
|
||||
const thumb = (
|
||||
<>
|
||||
<div className="aspect-[4/3] overflow-hidden" style={CHECKER}>
|
||||
{item.content_type.startsWith("video/") ? (
|
||||
// A still of the first frame; metadata only, not the file.
|
||||
<video src={item.url} preload="metadata" muted className="h-full w-full bg-black object-contain" />
|
||||
) : item.content_type.startsWith("audio/") ? (
|
||||
<div className="flex h-full w-full items-center justify-center bg-tint" aria-hidden="true">
|
||||
<FileAudio weight="bold" className="h-10 w-10 text-link" />
|
||||
</div>
|
||||
) : (
|
||||
<img
|
||||
src={item.url}
|
||||
alt=""
|
||||
loading="lazy"
|
||||
className="h-full w-full object-contain"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-1.5 truncate text-xs font-medium text-body" title={item.original_name}>
|
||||
{item.original_name}
|
||||
</p>
|
||||
<p className="text-xs text-muted/80">{mediaSize(item)}</p>
|
||||
</>
|
||||
);
|
||||
<>
|
||||
<ul className="grid grid-cols-2 gap-3 sm:grid-cols-3 lg:grid-cols-4">
|
||||
{items.map((item) => {
|
||||
const isSelected = selected === item.url;
|
||||
const thumb = (
|
||||
<>
|
||||
<div className="aspect-[4/3] overflow-hidden" style={CHECKER}>
|
||||
{item.content_type.startsWith("video/") ? (
|
||||
// Nothing loads until it's played: a page of videos
|
||||
// would otherwise fetch every one's opening.
|
||||
<video src={item.url} preload="none" muted className="h-full w-full bg-black object-contain" />
|
||||
) : item.content_type.startsWith("audio/") ? (
|
||||
<div className="flex h-full w-full items-center justify-center bg-tint" aria-hidden="true">
|
||||
<FileAudio weight="bold" className="h-10 w-10 text-link" />
|
||||
</div>
|
||||
) : (
|
||||
<Thumb url={item.url} />
|
||||
)}
|
||||
</div>
|
||||
<p className="mt-1.5 truncate text-xs font-medium text-body" title={item.original_name}>
|
||||
{item.original_name}
|
||||
</p>
|
||||
<p className="text-xs text-muted/80">{mediaSize(item)}</p>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<li
|
||||
key={item.id}
|
||||
className={`border bg-surface p-2 ${
|
||||
isSelected ? "border-brand ring-2 ring-brand/30" : "border-muted/20"
|
||||
}`}
|
||||
>
|
||||
{onPick ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onPick(item)}
|
||||
className="block w-full text-left"
|
||||
aria-pressed={isSelected}
|
||||
>
|
||||
{thumb}
|
||||
</button>
|
||||
) : (
|
||||
thumb
|
||||
)}
|
||||
{renderActions && <div className="mt-2">{renderActions(item)}</div>}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
return (
|
||||
<li
|
||||
key={item.id}
|
||||
className={`border bg-surface p-2 ${
|
||||
isSelected ? "border-brand ring-2 ring-brand/30" : "border-muted/20"
|
||||
}`}
|
||||
>
|
||||
{onPick ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onPick(item)}
|
||||
className="block w-full text-left"
|
||||
aria-pressed={isSelected}
|
||||
>
|
||||
{thumb}
|
||||
</button>
|
||||
) : (
|
||||
thumb
|
||||
)}
|
||||
{renderActions && <div className="mt-2">{renderActions(item)}</div>}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
{items.length >= MEDIA_LIST_MAX && (
|
||||
<p className="notice mt-4 p-4 text-sm text-body">Newest {MEDIA_LIST_MAX} shown, search to narrow.</p>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/* A tile's picture: the 640px copy, the full file if there's none. */
|
||||
function Thumb({ url }: { url: string }) {
|
||||
const img = useSmallImage(url);
|
||||
if (img.failed) return null;
|
||||
return <img src={img.src} onError={img.onError} alt="" loading="lazy" className="h-full w-full object-contain" />;
|
||||
}
|
||||
|
||||
/* ── Photos sent with requests ───────────────────────────────── */
|
||||
|
||||
const REQUESTS_TAB = "requests";
|
||||
|
|
|
|||
|
|
@ -88,10 +88,11 @@
|
|||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { ArrowUp, ArrowDown, CaretRight, Copy, Plus, X } from "@phosphor-icons/react";
|
||||
import { useRef, useState } from "react";
|
||||
import { useMemo, useRef, useState } from "react";
|
||||
|
||||
import { ApiError, post } from "../../lib/api.ts";
|
||||
import ContentBlocks from "../ContentBlocks.tsx";
|
||||
import { FILTER_FROM, OptionFilter, narrow } from "../OptionFilter.tsx";
|
||||
import { ImageInput, LinkPreviewInput } from "./MediaLibrary.tsx";
|
||||
import { ChooseFileButton } from "./DriveFiles.tsx";
|
||||
|
||||
|
|
@ -225,28 +226,35 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
const widget = field.widget ?? "text";
|
||||
const locked = Boolean(field.readOnly);
|
||||
|
||||
let list: any = null;
|
||||
let orphaned = false;
|
||||
|
||||
if (widget === "select") {
|
||||
list = field.optionsFrom
|
||||
? (options?.[field.optionsFrom] ?? []).map((o) => [o.id, o.label, o])
|
||||
: (field.options ?? []).map((o) =>
|
||||
Array.isArray(o) ? [o[0], o[1]] : [o, o],
|
||||
);
|
||||
if (field.filterBy && row) {
|
||||
list = list.filter(([, , raw]) => !raw || field.filterBy(raw, row));
|
||||
// The select's options, rebuilt only when their source changes
|
||||
// (or, with filterBy, the row they're filtered by), not on every
|
||||
// keystroke elsewhere in the form.
|
||||
const source = field.optionsFrom ? options?.[field.optionsFrom] : field.options;
|
||||
const filterRow = field.filterBy ? row : null;
|
||||
const list: any[] | null = useMemo<any[] | null>(() => {
|
||||
if (widget !== "select") return null;
|
||||
let all = field.optionsFrom
|
||||
? (source ?? []).map((o) => [o.id, o.label, o])
|
||||
: (source ?? []).map((o) => (Array.isArray(o) ? [o[0], o[1]] : [o, o]));
|
||||
if (field.filterBy && filterRow) {
|
||||
all = all.filter(([, , raw]) => !raw || field.filterBy(raw, filterRow));
|
||||
}
|
||||
return all;
|
||||
}, [widget, field, source, filterRow]);
|
||||
|
||||
// A stored value with no matching option renders as the blank
|
||||
// choice, which reads as "nobody set this" and saves as a
|
||||
// deliberate clear. It usually means the row it pointed at was
|
||||
// deleted, so keep it on screen and say so.
|
||||
orphaned =
|
||||
value != null &&
|
||||
value !== "" &&
|
||||
!list.some(([optionId]) => String(optionId) === String(value));
|
||||
}
|
||||
// Past FILTER_FROM options, a box above the select narrows them.
|
||||
const [needle, setNeedle] = useState("");
|
||||
const shown: any[] = list ? narrow<any>(list, needle, ([, label]) => label, ([optionId]) => String(optionId) === String(value)) : [];
|
||||
|
||||
// A stored value with no matching option renders as the blank
|
||||
// choice, which reads as "nobody set this" and saves as a
|
||||
// deliberate clear. It usually means the row it pointed at was
|
||||
// deleted, so keep it on screen and say so.
|
||||
const orphaned =
|
||||
list != null &&
|
||||
value != null &&
|
||||
value !== "" &&
|
||||
!list.some(([optionId]) => String(optionId) === String(value));
|
||||
|
||||
// A file from the Drive library into this link field (`files`).
|
||||
const pickFile = (file) => {
|
||||
|
|
@ -297,21 +305,30 @@ export function Field({ field, value, row, options, error, onChange, onPatch }:
|
|||
// A select has no readOnly, so this one really does have
|
||||
// to be disabled: there's no way to keep it focusable
|
||||
// and still refuse a new choice.
|
||||
<select
|
||||
{...common}
|
||||
disabled={locked}
|
||||
className={`${locked ? inputLocked : common.className} ${
|
||||
orphaned && !locked ? inputError : ""
|
||||
}`}
|
||||
>
|
||||
<option value="">{field.blankLabel ?? "- Please choose from the list -"}</option>
|
||||
{orphaned && <option value={value}>{value} no longer exists</option>}
|
||||
{list.map(([id2, label]) => (
|
||||
<option key={id2} value={id2}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<>
|
||||
{(list?.length ?? 0) > FILTER_FROM && !locked && (
|
||||
<OptionFilter
|
||||
value={needle}
|
||||
onChange={setNeedle}
|
||||
label={`Narrow the ${typeof field.label === "function" ? field.label(row) : field.label} list`}
|
||||
/>
|
||||
)}
|
||||
<select
|
||||
{...common}
|
||||
disabled={locked}
|
||||
className={`${locked ? inputLocked : common.className} ${
|
||||
orphaned && !locked ? inputError : ""
|
||||
}`}
|
||||
>
|
||||
<option value="">{field.blankLabel ?? "- Please choose from the list -"}</option>
|
||||
{orphaned && <option value={value}>{value} no longer exists</option>}
|
||||
{shown.map(([id2, label]) => (
|
||||
<option key={id2} value={id2}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</>
|
||||
) : widget === "color" ? (
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue