Feature updates: photo framing, group pages, schedule images, content block placement #29
1 changed files with 111 additions and 97 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import { CaretRight, MagnifyingGlass, X } from '@phosphor-icons/react';
|
||||
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Fragment, useMemo, useRef, useState } from "react";
|
||||
import { useCommunity } from "../../lib/useCommunity.ts";
|
||||
import { useOrganization } from "../../lib/useContent.ts";
|
||||
import { Link } from "react-router-dom";
|
||||
|
|
@ -157,6 +157,7 @@ function Tile({
|
|||
count = 0,
|
||||
selected,
|
||||
hovered,
|
||||
hoveredArea,
|
||||
setSelected,
|
||||
setHovered,
|
||||
onPick,
|
||||
|
|
@ -168,19 +169,23 @@ function Tile({
|
|||
const ids = slices.map(s => s.regionId);
|
||||
const active = ids.includes(selected) || ids.includes(hovered);
|
||||
const dimmed = selected && !ids.includes(selected);
|
||||
// The state under the pointer, outlined in ink over its region's
|
||||
// color, so both read at once.
|
||||
const here = hoveredArea === code;
|
||||
const clipId = `clip-${code}`;
|
||||
// Solid, never see-through: a tile with no groups, or one dimmed
|
||||
// while another region is picked, is its color mixed toward the
|
||||
// page's rather than faded, so the backdrop doesn't show through.
|
||||
const strength = dimmed ? (count ? 35 : 15) : count ? 100 : active ? 50 : 28;
|
||||
const strength = dimmed ? (count ? 35 : 15) : count ? 100 : here ? 70 : active ? 50 : 28;
|
||||
const tileFill = (color: string) => `color-mix(in srgb, ${color} ${strength}%, var(--color-surface))`;
|
||||
|
||||
// Clicking a shared tile cycles through its regions and then
|
||||
// clears, so every slice is reachable without a second control.
|
||||
const cycle = () => {
|
||||
onPick?.(code);
|
||||
const at = ids.indexOf(selected);
|
||||
setSelected(at === ids.length - 1 ? null : ids[at + 1]);
|
||||
const next = at === ids.length - 1 ? null : ids[at + 1];
|
||||
onPick?.(code, next);
|
||||
setSelected(next);
|
||||
};
|
||||
|
||||
const name = `${AREA_NAMES[code] || code}: ${slices.map(s => s.name).join(" / ")}${
|
||||
|
|
@ -193,14 +198,14 @@ function Tile({
|
|||
return (
|
||||
<g
|
||||
onClick={cycle}
|
||||
onMouseEnter={() => setHovered(primary.regionId)}
|
||||
onMouseEnter={() => setHovered(primary.regionId, code)}
|
||||
onMouseLeave={() => setHovered(null)}
|
||||
{...(count
|
||||
? {
|
||||
role: "button",
|
||||
tabIndex: 0,
|
||||
"aria-label": name,
|
||||
onFocus: () => setHovered(primary.regionId),
|
||||
onFocus: () => setHovered(primary.regionId, code),
|
||||
onBlur: () => setHovered(null),
|
||||
onKeyDown: (e) => {
|
||||
if (e.key !== "Enter" && e.key !== " ") return;
|
||||
|
|
@ -241,9 +246,9 @@ function Tile({
|
|||
width={width}
|
||||
height={size}
|
||||
fill="none"
|
||||
stroke={active ? colorOf(primary) : "var(--color-surface)"}
|
||||
strokeOpacity={active ? 1 : 0.55}
|
||||
strokeWidth={active ? 4 : 2}
|
||||
stroke={here ? "var(--color-ink)" : active ? colorOf(primary) : "var(--color-surface)"}
|
||||
strokeOpacity={active || here ? 1 : 0.55}
|
||||
strokeWidth={here ? 6 : active ? 4 : 2}
|
||||
className="transition-all duration-200"
|
||||
/>
|
||||
|
||||
|
|
@ -304,11 +309,14 @@ function RegionMap({ slices, groupCounts, ...props }: any) {
|
|||
);
|
||||
}
|
||||
|
||||
function LegendButton({ region, selected, setSelected, hovered, setHovered }) {
|
||||
function LegendButton({ region, selected, setSelected, hovered, setHovered, onPickRegion }) {
|
||||
const on = selected === region.id || hovered === region.id;
|
||||
return (
|
||||
<button
|
||||
onClick={() => setSelected(selected === region.id ? null : region.id)}
|
||||
onClick={() => {
|
||||
if (selected !== region.id) onPickRegion(region.id);
|
||||
setSelected(selected === region.id ? null : region.id);
|
||||
}}
|
||||
onMouseEnter={() => setHovered(region.id)}
|
||||
onMouseLeave={() => setHovered(null)}
|
||||
onFocus={() => setHovered(region.id)}
|
||||
|
|
@ -386,9 +394,19 @@ function RegionBlock({
|
|||
setHovered,
|
||||
indent,
|
||||
regionRefs,
|
||||
groupRefs,
|
||||
stateRefs,
|
||||
}) {
|
||||
const on = selected === region.id;
|
||||
// Each state with groups, by name, its groups under it; groups with
|
||||
// no state (online, or not placed) last, with no subheading.
|
||||
const areas = new Map<string, any[]>();
|
||||
for (const c of groups) {
|
||||
const code = c.area_code ?? "";
|
||||
areas.set(code, [...(areas.get(code) ?? []), c]);
|
||||
}
|
||||
const byArea = [...areas].sort(([a], [b]) =>
|
||||
!a ? 1 : !b ? -1 : (AREA_NAMES[a] || a).localeCompare(AREA_NAMES[b] || b),
|
||||
);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
@ -428,13 +446,20 @@ function RegionBlock({
|
|||
No groups yet. Interested in starting one?
|
||||
</p>
|
||||
) : (
|
||||
<ul className="ml-5 mb-4 flex flex-col gap-3">
|
||||
{groups.map(c => (
|
||||
<div className="ml-5 mb-4 flex flex-col gap-4">
|
||||
{byArea.map(([code, list]) => (
|
||||
<div key={code} ref={el => { if (code) stateRefs.current[`${region.id}:${code}`] = el; }}>
|
||||
{code && (
|
||||
<h5 className="mb-2 text-xs font-bold uppercase tracking-wide" style={{ color: MUTED }}>
|
||||
{AREA_NAMES[code] || code}
|
||||
</h5>
|
||||
)}
|
||||
<ul className="flex flex-col gap-3">
|
||||
{list.map(c => (
|
||||
<li
|
||||
key={c.id}
|
||||
ref={el => groupRefs && (groupRefs.current[c.id] = el)}
|
||||
className="pl-3 flex items-start gap-3"
|
||||
style={{ borderLeft: `2px solid ${colorOf(region)}` }}
|
||||
className="bg-raised shadow-sm p-3 flex items-start gap-3"
|
||||
style={{ borderLeft: `3px solid ${colorOf(region)}` }}
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="font-bold">{c.name}</p>
|
||||
|
|
@ -479,6 +504,9 @@ function RegionBlock({
|
|||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
|
@ -865,26 +893,20 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
|||
|
||||
const [selected, setSelected] = useState<any>(null);
|
||||
const [hovered, setHovered] = useState<any>(null);
|
||||
const [hoveredArea, setHoveredArea] = useState<any>(null);
|
||||
const [openId, setOpenId] = useState<any>(null); // no card open on arrival
|
||||
const [query, setQuery] = useState("");
|
||||
const reading = useReadingMode();
|
||||
|
||||
// The list scrolls itself to whatever the map or legend points at.
|
||||
// The list scrolls itself to whatever the map or legend is clicked
|
||||
// on (never on hover: it would jump around as the pointer crosses).
|
||||
const listRef = useRef<any>(null);
|
||||
const regionRefs = useRef<any>({});
|
||||
const groupRefs = useRef<any>({});
|
||||
const stateRefs = useRef<any>({});
|
||||
|
||||
// Where the latest hover came from. The list follows the map and
|
||||
// the legend, but hovering the list itself must not move it: the
|
||||
// row would slide out from under the pointer.
|
||||
const hoverFromList = useRef(false);
|
||||
const hoverOnMap = id => {
|
||||
hoverFromList.current = false;
|
||||
setHovered(id);
|
||||
};
|
||||
const hoverInList = id => {
|
||||
hoverFromList.current = true;
|
||||
const hoverOn = (id, code = null) => {
|
||||
setHovered(id);
|
||||
setHoveredArea(code);
|
||||
};
|
||||
|
||||
const scrollListTo = el => {
|
||||
|
|
@ -896,30 +918,21 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
|||
box.scrollTo({ top: el.offsetTop - 8, behavior: scrollBehavior() });
|
||||
};
|
||||
|
||||
// Hovering or selecting a region on the map or legend brings its
|
||||
// block into view. After a hover in the list, nothing scrolls: not
|
||||
// on the way in, and not back to the selection on the way out.
|
||||
useEffect(() => {
|
||||
if (hoverFromList.current) return;
|
||||
const id = hovered || selected;
|
||||
if (id) scrollListTo(regionRefs.current[id]);
|
||||
}, [hovered, selected]);
|
||||
const pickRegion = id => scrollListTo(regionRefs.current[id]);
|
||||
|
||||
// Clicking a tile jumps to its first group when it has one,
|
||||
// otherwise to the region it belongs to.
|
||||
const pickArea = code => {
|
||||
const group = groups.find(c => c.area_code === code);
|
||||
if (group && groupRefs.current[group.id]) {
|
||||
return scrollListTo(groupRefs.current[group.id]);
|
||||
}
|
||||
const region = regionsForArea(code)[0];
|
||||
if (region) scrollListTo(regionRefs.current[region.id]);
|
||||
// Clicking a tile jumps to the state's subheading under the region
|
||||
// it selects when the state has groups there, otherwise to that
|
||||
// region. Clicked back to no selection: the state under whichever
|
||||
// region has its groups, else its first region.
|
||||
const pickArea = (code, regionId) => {
|
||||
const id = regionId ?? groups.find(c => c.area_code === code)?.region_id ?? regionsForArea(code)[0]?.id;
|
||||
if (!id) return;
|
||||
scrollListTo(stateRefs.current[`${id}:${code}`] ?? regionRefs.current[id]);
|
||||
};
|
||||
|
||||
/* The list column, built only when what it shows changes: hovering
|
||||
a map tile or legend entry changes `hovered`, which no row reads,
|
||||
so hundreds of groups aren't drawn again for every tile crossed.
|
||||
hoverInList only touches a ref and a state setter, both stable. */
|
||||
so hundreds of groups aren't drawn again for every tile crossed. */
|
||||
const list = useMemo(() => {
|
||||
const match = matcher(query);
|
||||
const block = (region, indent) => {
|
||||
|
|
@ -930,13 +943,13 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
|||
key={region.id}
|
||||
region={region}
|
||||
groups={inRegion}
|
||||
subtext={subtextFor(region)}
|
||||
subtext={region.map_note}
|
||||
indent={indent}
|
||||
regionRefs={regionRefs}
|
||||
groupRefs={groupRefs}
|
||||
stateRefs={stateRefs}
|
||||
selected={selected}
|
||||
setSelected={setSelected}
|
||||
setHovered={hoverInList}
|
||||
setHovered={setHovered}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
@ -976,7 +989,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
|||
)}
|
||||
</>
|
||||
);
|
||||
}, [domestic, international, virtual, groupsIn, subtextFor, selected, query]);
|
||||
}, [domestic, international, virtual, groupsIn, selected, query]);
|
||||
|
||||
const shell = children => (
|
||||
<div className="mx-auto px-8 md:px-12" style={{ maxWidth: CONTENT_MAX }}>
|
||||
|
|
@ -1023,7 +1036,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
|||
);
|
||||
}
|
||||
|
||||
const shared = { selected, setSelected, hovered, setHovered: hoverOnMap };
|
||||
const shared = { selected, setSelected, hovered, hoveredArea, setHovered: hoverOn };
|
||||
const onMapIds = new Set(regionAreas.map(a => a.region_id));
|
||||
|
||||
return (
|
||||
|
|
@ -1046,6 +1059,7 @@ export default function OrgListMap({ view = "map", accent = FALLBACK_COLOR }) {
|
|||
domestic={domestic}
|
||||
international={international}
|
||||
onMapIds={onMapIds}
|
||||
onPickRegion={pickRegion}
|
||||
{...shared}
|
||||
/>
|
||||
<p className="text-sm mt-4" style={{ color: MUTED }}>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue