Spaces:
Sleeping
Sleeping
File size: 5,036 Bytes
0e11366 71c1c9d 0e11366 71c1c9d 0e11366 71c1c9d 0e11366 71c1c9d 0e11366 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
import type { SelectMeta } from "../../lib/types";
const isEmoji = (s: string) => !!s && /\p{Extended_Pictographic}/u.test(s);
const cleanTitle = (t?: string) => {
if (!t) return t;
return t
.replace(/^(?:[a-z0-9]+-){1,3}(?=[A-Z])/i, "") // slug stuck to title (no space)
.replace(/^(?:[a-z0-9]+-){1,3}\s+/i, ""); // slug + space
};
export default function SelectedLocationCard({
selectedLL,
selectedMeta,
onClear,
reactionsById,
}: {
selectedLL: [number, number] | null;
selectedMeta: SelectMeta | null;
onClear: () => void;
reactionsById: Record<string, any>;
}) {
const photoSrc =
selectedMeta?.raw?.photo_url ??
selectedMeta?.raw?.photoUrl ??
selectedMeta?.raw?.image_url ??
selectedMeta?.raw?.imageUrl ??
(selectedMeta as any)?.photo_url ??
(selectedMeta as any)?.photoUrl ??
null;
const rid = selectedMeta?.rid || selectedMeta?.raw?.rid;
const rx = rid ? reactionsById[rid] : null;
const verifyCount = rx?.verify_count ?? 0;
const clearCount = rx?.clear_count ?? 0;
const showEmoji =
selectedMeta?.emoji && isEmoji(String(selectedMeta.emoji))
? String(selectedMeta.emoji)
: null;
const displayTitle = cleanTitle(selectedMeta?.title) || "Selected";
return (
<div className="block">
<label className="label">Selected location</label>
<div className="locationCard">
{selectedLL ? (
<>
<div className="locName flex items-center gap-2">
{showEmoji ? (
<span style={{ fontSize: 18, lineHeight: "18px" }}>
{showEmoji}
</span>
) : null}
<span>{displayTitle}</span>
</div>
{selectedMeta?.subtitle && (
<div className="muted">{selectedMeta.subtitle}</div>
)}
<div className="locLL">
{selectedLL[0].toFixed(4)}, {selectedLL[1].toFixed(4)}
</div>
<div className="mt-2 text-sm space-y-1">
{(selectedMeta?.category || selectedMeta?.raw?.category) && (
<div>
<b>Category:</b>{" "}
{selectedMeta.category || selectedMeta.raw?.category}
</div>
)}
{(selectedMeta?.severity !== undefined ||
selectedMeta?.raw?.severity !== undefined) && (
<div>
<b>Severity/Mag:</b>{" "}
{String(
selectedMeta?.severity ?? selectedMeta?.raw?.severity
)}
</div>
)}
<div>
<b>Confidence:</b>{" "}
{(() => {
const k = selectedMeta?.kind;
const fromMeta =
selectedMeta?.confidence ?? selectedMeta?.raw?.confidence;
const official =
k && ["nws", "quake", "eonet", "fire"].includes(k);
const val = fromMeta ?? (official ? 1 : undefined);
return val !== undefined ? String(val) : "—";
})()}
</div>
{selectedMeta?.raw?.source ? (
<div>
<b>Source:</b> {selectedMeta.raw.source}
</div>
) : selectedMeta?.kind &&
["nws", "quake", "eonet", "fire"].includes(
selectedMeta.kind
) ? (
<div>
<b>Source:</b> {selectedMeta.kind.toUpperCase()}
</div>
) : null}
{selectedMeta?.sourceUrl && (
<div>
<a
href={selectedMeta.sourceUrl}
className="link"
target="_blank"
rel="noreferrer"
>
Source
</a>
</div>
)}
</div>
</>
) : (
<div className="locDetecting">Use search, 📍, or click the map.</div>
)}
{rid ? (
<div className="text-xs muted">
Verified: {verifyCount} · Cleared: {clearCount}
</div>
) : null}
{photoSrc && (
<div className="mt-2" style={{ maxHeight: 220, overflow: "auto" }}>
<img
src={photoSrc}
alt="Attached"
style={{
width: "100%",
height: "auto",
borderRadius: 8,
objectFit: "contain",
display: "block",
}}
/>
</div>
)}
<div className="hint">
Only one point is active. Drag 📍 to fine-tune; chat uses this point.
</div>
{selectedLL && (
<div className="mt-2">
<button className="btn btn-ghost" onClick={onClear}>
Clear selection
</button>
</div>
)}
</div>
</div>
);
}
|