The app HAS a platform layer -- AnchoredPopover (22 importers, with arrows/typeahead/Escape/anchor-flip), QueryState (21), Modal (17), PageShell, DataTable, Tabs, Tooltip and ~26 more -- but it sat flat among ~160 feature components with nothing marking it as one. Several of those files describe themselves as 'the one place' or 'canonical' and were still bypassed by hand-rolled markup, because a layer nobody can see is a layer nobody uses; three separate inventory passes of this codebase misread it the same way. Moves the 33 domain-free modules into components/ui/, rewrites the imports in 89 files, and makes the boundary a lint rule rather than a convention: inside ui/ a one-level-up import (a feature component) and any lib/api slice are errors. The rule was verified to fire on both and to leave generic lib/ helpers alone. README.md states which side of the line a component belongs on and why. No behaviour change: 3x tsc, eslint, knip, prettier and 687 vitest tests all green; no backend file touched.
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
// Avatar image with a graceful fallback.
|
|
//
|
|
// Uses referrerPolicy="no-referrer" because Google's avatar CDNs
|
|
// (yt3.ggpht.com / lh3.googleusercontent.com) rate-limit bursts of
|
|
// referrer-bearing requests — when a feed page fires dozens of avatar loads at
|
|
// once, a random subset gets throttled (HTTP 429) and the browser shows its
|
|
// broken-image icon. Dropping the referrer makes those CDNs serve the images.
|
|
// If a load still fails we render a neutral placeholder (optionally an initial)
|
|
// instead of the broken-image icon.
|
|
export default function Avatar({
|
|
src,
|
|
alt = "",
|
|
fallback,
|
|
className = "",
|
|
}: {
|
|
src?: string | null;
|
|
alt?: string;
|
|
fallback?: string; // a name/title; its first letter is shown when there's no image
|
|
className?: string;
|
|
}) {
|
|
const [failed, setFailed] = useState(false);
|
|
useEffect(() => setFailed(false), [src]);
|
|
|
|
if (src && !failed) {
|
|
return (
|
|
<img
|
|
src={src}
|
|
alt={alt}
|
|
loading="lazy"
|
|
referrerPolicy="no-referrer"
|
|
onError={() => setFailed(true)}
|
|
className={className}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const initial = fallback?.trim()?.[0]?.toUpperCase() ?? "";
|
|
return (
|
|
<div
|
|
className={`bg-card grid place-items-center font-semibold text-muted select-none ${className}`}
|
|
aria-hidden
|
|
>
|
|
{initial}
|
|
</div>
|
|
);
|
|
}
|