// ----------------------------------------------------------------------------- // Home-Ka — US real-estate aggregator (Groupe KA) // Author: Simon-Pierre Boucher — contact@spboucher.ai // components/PropertyImg.tsx : robust property image // · : elegant PER-PROPERTY-TYPE fallback in Home-Ka colors — // never a broken-image icon or a gray void. // · : with automatic fallback if the URL fails to load. // ----------------------------------------------------------------------------- import { useState } from "react"; import { Ico } from "./Icons"; const TYPE_ICONS: Record = { "Single Family": "home", "Single-Family": "home", "House": "home", "Townhouse": "home", "Mobile Home": "home", "Manufactured": "home", "Cabin": "tree", "Condo": "building", "Condominium": "building", "Apartment": "building", "Multi-Family": "building", "Duplex": "building", "Triplex": "building", "Land": "land", "Lot": "land", "Farm": "leaf", "Ranch": "leaf", "Commercial": "cart", }; /** Fallback image per property type (green gradient + icon + label). */ export function TypeFallback({ type, label = true }: { type?: string; label?: boolean }) { const ico = TYPE_ICONS[type ?? ""] ?? "home"; return (
{label && {type || "Photos coming soon"}}
); } /** that switches to the type fallback if loading fails. */ export default function PropertyImg({ src, alt, type, eager = false, }: { src?: string | null; alt: string; type?: string; eager?: boolean }) { const [broken, setBroken] = useState(false); if (!src || broken) return ; return ( {alt} setBroken(true)} /> ); }