735de6ece9
Extends the prior Tibet/CountryFlag work so the Snow Lion flag wins
everywhere a CN-XZ post or page surfaces, not just in the Discover
country pulse strip.
- Comment context (NoteCard + PostDetailPage)
* Country pill on the card header swaps in the SVG via
CountryFlag (was bare emoji span).
* Pill hover card uses the subdivision's own name, drops the
parent-country sub-line, and labels it as 'Country' rather
than 'Region' for codes with a custom flag.
* CountryFlagBackdrop (the faded full-bleed flag behind a
country-rooted note) prefers the bundled SVG over the
Wikipedia lead image, which for Tibet returns an
administrative map.
- PostDetailPage 'country above the post' chip
* CountryPreview now routes through CountryFlag and prefers
info.subdivisionName when a custom flag is registered, so
the chip reads as 'Tibet' instead of 'China'.
- Country page (/i/iso3166:CN-XZ)
* Hero banner driven by customFlagAsset(code) when present,
sharing the same <img>+skyOverlay pipeline as Wikipedia
photos so the day/night tint and bottom fade still apply.
* Subline beneath the title no longer falls into the
'subdivision = show parent country' branch for custom-flag
codes; it now reads the Wikipedia description / official
name like other countries do.
* Big flag slot uses CountryFlag too, bypassing the Wikipedia
subdivision thumbnail.
- Helpers split out of CountryFlag.tsx into src/lib/customFlags.ts
(hasCustomFlag, customFlagAsset) so the component file only
exports a component — fixes the react-refresh warning that came
out of the first pass.
- Action cards (feed + detail) now render their country chip
through CountryFlag, picking up the SVG for any future Tibet-
tagged action.
36 lines
1.4 KiB
TypeScript
36 lines
1.4 KiB
TypeScript
/**
|
|
* Bundled flag assets for ISO codes that have a recognised flag but no
|
|
* Unicode emoji codepoint. The {@link CountryFlag} component renders
|
|
* these as `<img>` elements; callers that need the raw URL (e.g. a
|
|
* card backdrop, a CSS background) use {@link customFlagAsset}.
|
|
*
|
|
* Editorial choice: Tibet (ISO 3166-2 `CN-XZ`) is surfaced as a
|
|
* country-level entity with the Snow Lion flag, matching the older
|
|
* Agora codebase. Add additional entries here as new bundled assets
|
|
* land in `/public`.
|
|
*/
|
|
const CUSTOM_FLAG_ASSETS: Record<string, string> = {
|
|
'CN-XZ': '/flag-tibet.svg',
|
|
};
|
|
|
|
/**
|
|
* Whether `CountryFlag` will render a bundled SVG/image for this code
|
|
* instead of falling back to its emoji. Useful when a surrounding
|
|
* renderer has a separate "Wikipedia subdivision thumbnail" branch
|
|
* that should bow out so the custom flag wins.
|
|
*/
|
|
export function hasCustomFlag(code: string): boolean {
|
|
return code.toUpperCase() in CUSTOM_FLAG_ASSETS;
|
|
}
|
|
|
|
/**
|
|
* URL of the bundled flag asset for this code, or `null` when none is
|
|
* defined. Use this when a renderer needs to drop the flag into a
|
|
* non-`<img>` slot — a CSS background, a feed-card backdrop, or a
|
|
* blurred banner — instead of through the `CountryFlag` glyph
|
|
* component. Stays `null` for entries that fall back to emoji.
|
|
*/
|
|
export function customFlagAsset(code: string): string | null {
|
|
return CUSTOM_FLAG_ASSETS[code.toUpperCase()] ?? null;
|
|
}
|