Browse Source

Review fixes

Co-Authored-By: Dan Ditomaso <[email protected]>
pull/850/head
philon- 10 months ago
parent
commit
163642fbf9
  1. 3
      packages/web/public/i18n/locales/en/common.json
  2. 4
      packages/web/src/components/PageComponents/Map/Layers/NodesLayer.tsx
  3. 42
      packages/web/src/components/PageComponents/Map/Layers/SNRLayer.tsx
  4. 4
      packages/web/src/components/PageComponents/Map/Layers/WaypointLayer.tsx
  5. 258
      packages/web/src/components/PageComponents/Map/Popups/WaypointDetail.tsx

3
packages/web/public/i18n/locales/en/common.json

@ -66,7 +66,8 @@
"year": { "one": "Year", "plural": "Years" }, "year": { "one": "Year", "plural": "Years" },
"snr": "SNR", "snr": "SNR",
"volt": { "one": "Volt", "plural": "Volts", "suffix": "V" }, "volt": { "one": "Volt", "plural": "Volts", "suffix": "V" },
"record": { "one": "Records", "plural": "Records" } "record": { "one": "Records", "plural": "Records" },
"degree": { "one": "Degree", "plural": "Degrees", "suffix": "°" }
}, },
"security": { "security": {
"0bit": "Empty", "0bit": "Empty",

4
packages/web/src/components/PageComponents/Map/Layers/NodesLayer.tsx

@ -83,7 +83,7 @@ export const NodesLayer = ({
: undefined; : undefined;
// Always render all node markers in the cluster // Always render all node markers in the cluster
nodes.forEach((node, i) => { for (const [i, node] of nodes.entries()) {
const isHead = i === 0; const isHead = i === 0;
rendered.push( rendered.push(
@ -109,7 +109,7 @@ export const NodesLayer = ({
}} }}
/>, />,
); );
}); }
if (nodes.length > 1) { if (nodes.length > 1) {
rendered.push( rendered.push(

42
packages/web/src/components/PageComponents/Map/Layers/SNRLayer.tsx

@ -165,6 +165,21 @@ function makeFeature(
}; };
} }
function pushIfFeature(
a: number,
b: number,
aPos: LngLat,
bPos: LngLat,
snr: number,
curved: boolean,
features: Feature[],
) {
const feat = makeFeature(a, b, aPos, bPos, snr, curved);
if (feat) {
features.push(feat);
}
}
function generateNeighborLines( function generateNeighborLines(
neighborInfos: NeighborInfos[], neighborInfos: NeighborInfos[],
): FeatureCollection { ): FeatureCollection {
@ -215,26 +230,15 @@ function generateNeighborLines(
if (pair.ab && pair.ba) { if (pair.ab && pair.ba) {
// both directions → two arcs // both directions → two arcs
const feat1 = makeFeature(pair.a, pair.b, aPos, bPos, pair.ab, true); pushIfFeature(pair.a, pair.b, aPos, bPos, pair.ab, true, features);
const feat2 = makeFeature(pair.b, pair.a, bPos, aPos, pair.ba, true); pushIfFeature(pair.b, pair.a, bPos, aPos, pair.ba, true, features);
} else {
if (feat1) { // only one direction → straight
features.push(feat1); if (pair.ab) {
} pushIfFeature(pair.a, pair.b, aPos, bPos, pair.ab, false, features);
if (feat2) {
features.push(feat2);
}
} else if (pair.ab) {
// only a->b, straight
const feat = makeFeature(pair.a, pair.b, aPos, bPos, pair.ab, false);
if (feat) {
features.push(feat);
} }
} else if (pair.ba) { if (pair.ba) {
// only b->a, straight pushIfFeature(pair.b, pair.a, bPos, aPos, pair.ba, false, features);
const feat = makeFeature(pair.b, pair.a, bPos, aPos, pair.ba, false);
if (feat) {
features.push(feat);
} }
} }
} }

4
packages/web/src/components/PageComponents/Map/Layers/WaypointLayer.tsx

@ -49,7 +49,7 @@ export const WaypointLayer = ({
return rendered; return rendered;
} }
waypoints.forEach((waypoint) => { for (const waypoint of waypoints) {
const [lng, lat] = toLngLat({ const [lng, lat] = toLngLat({
latitudeI: waypoint.latitudeI, latitudeI: waypoint.latitudeI,
longitudeI: waypoint.longitudeI, longitudeI: waypoint.longitudeI,
@ -66,7 +66,7 @@ export const WaypointLayer = ({
onClick={(_, e) => onMarkerClick(waypoint, e)} onClick={(_, e) => onMarkerClick(waypoint, e)}
/>, />,
); );
}); }
if (popupState?.type === "waypoint") { if (popupState?.type === "waypoint") {
const [lng, lat] = toLngLat({ const [lng, lat] = toLngLat({

258
packages/web/src/components/PageComponents/Map/Popups/WaypointDetail.tsx

@ -13,13 +13,11 @@ import {
ClockFadingIcon, ClockFadingIcon,
ClockPlusIcon, ClockPlusIcon,
CompassIcon, CompassIcon,
//Edit3Icon,
MapPinnedIcon, MapPinnedIcon,
MoveHorizontalIcon, MoveHorizontalIcon,
NavigationIcon, NavigationIcon,
RotateCwIcon, RotateCwIcon,
UserLockIcon, UserLockIcon,
UserPenIcon,
} from "lucide-react"; } from "lucide-react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -29,24 +27,7 @@ interface WaypointDetailProps {
onEdit: () => void; onEdit: () => void;
} }
const RowElement: React.FC<{ export const WaypointDetail = ({ waypoint, myNode }: WaypointDetailProps) => {
label: string;
value: React.ReactNode | string | number | undefined;
icon?: React.ReactNode;
}> = ({ label, value, icon }) => (
<div className="flex justify-between">
<span className="inline-flex items-center gap-2 text-slate-500 dark:text-slate-500">
{icon} {label}
</span>
<span className="inline-flex items-center gap-1">{value}</span>
</div>
);
export const WaypointDetail = ({
waypoint,
myNode,
//onEdit,
}: WaypointDetailProps) => {
const { t } = useTranslation("map"); const { t } = useTranslation("map");
const { getNode } = useNodeDB(); const { getNode } = useNodeDB();
@ -64,106 +45,147 @@ export const WaypointDetail = ({
: undefined; : undefined;
return ( return (
<div className="flex flex-col gap-2 px-1 text-sm dark:text-slate-900"> <article
<div className="flex items-center my-1 justify-between"> aria-labelledby={`wp-${waypoint.id}-title`}
<div className="flex items-center gap-2 font-semibold text-slate-900 "> className="flex flex-col gap-2 px-1 text-sm dark:text-slate-900"
{String.fromCodePoint(waypoint.icon) ?? "📍"} >
<header className="flex items-center my-1 justify-between">
<h3
id={`wp-${waypoint.id}-title`}
className="flex items-center gap-2 font-semibold text-slate-900"
>
<span aria-hidden>{String.fromCodePoint(waypoint.icon) ?? "📍"}</span>
<span>{waypoint.name}</span> <span>{waypoint.name}</span>
</div> </h3>
</div> </header>
{waypoint.description && ( {waypoint.description && (
<div> <p className="inline-flex items-center gap-1">{waypoint.description}</p>
<span className="inline-flex items-center gap-1">
{waypoint.description}
</span>
</div>
)}
<Separator className="dark:bg-slate-200" />
<div className="flex justify-between">
<span className="inline-flex items-start gap-2 text-slate-500 dark:text-slate-500">
<MapPinnedIcon size="20" />
<span>
{t("waypointDetail.longitude")} {t("waypointDetail.latitude")}
</span>
</span>
<span className="text-right">
{waypointLngLat[0]} {waypointLngLat[1]}
</span>
</div>
<RowElement
label={t("waypointDetail.createdDate")}
value={<TimeAgo timestamp={waypoint.metadata.created} />}
icon={<ClockPlusIcon size="14" />}
/>
{waypoint.metadata.updated && (
<RowElement
label={t("waypointDetail.updated")}
value={<TimeAgo timestamp={waypoint.metadata.updated} />}
icon={<RotateCwIcon size="14" />}
/>
)}
{waypoint.expire !== 0 && (
<RowElement
label={t("waypointDetail.expires")}
value={<TimeAgo timestamp={waypoint.expire * 1000} />}
icon={<ClockFadingIcon size="14" />}
/>
)} )}
{distance && (
<RowElement <Separator className="dark:bg-slate-200" role="separator" />
label={t("waypointDetail.distance")}
value={`${Math.round(distance)} ${distance === 1 ? t("unit.meter.one") : t("unit.meter.plural")}`} <section aria-label={t("waypointDetail.details")}>
icon={<MoveHorizontalIcon size="14" />} <dl className="space-y-1.5">
/> {/* Coordinates */}
)} <div className="flex flex-wrap items-start gap-x-3">
{bearing && ( <dt className="inline-flex items-top gap-2 text-slate-500 min-w-0">
<RowElement <MapPinnedIcon size={14} aria-hidden className="mt-1" />
label={t("waypointDetail.bearing")} <span className="truncate">
value={ {t("waypointDetail.longitude")}
<> <br />
<NavigationIcon {t("waypointDetail.latitude")}
size="16" </span>
aria-hidden </dt>
className="shrink-0 origin-center transition-transform" <dd className="ms-auto text-right">
style={{ transform: `rotate(${bearing - 45}deg)` }} <data value={waypointLngLat[0]}>{waypointLngLat[0]}</data>
/> <br />
{Math.round(bearing)}° <data value={waypointLngLat[1]}>{waypointLngLat[1]}</data>
</> </dd>
} </div>
icon={<CompassIcon size="14" />}
/> {/* Created */}
)} <div className="flex flex-wrap items-start gap-x-3">
<RowElement <dt className="inline-flex items-center gap-2 text-slate-500 min-w-0">
label={t("waypointDetail.createdBy")} <ClockPlusIcon size={14} aria-hidden />
value={ <span className="truncate">
getNode(waypoint.metadata.from)?.user?.longName ?? {t("waypointDetail.createdDate")}
t("unknown.longName") </span>
} </dt>
icon={<UserPenIcon size="14" />} <dd className="ms-auto text-right">
/> <time
{ dateTime={new Date(waypoint.metadata.created).toISOString()}
waypoint.lockedTo ? ( >
<RowElement <TimeAgo timestamp={waypoint.metadata.created} />
label={t("waypointDetail.lockedTo")} </time>
value={ </dd>
getNode(waypoint.lockedTo)?.user?.longName ?? </div>
t("unknown.longName")
} {/* Updated */}
icon={<UserLockIcon size="14" />} {waypoint.metadata.updated && (
/> <div className="flex flex-wrap items-start gap-x-3">
) : null /*( <dt className="inline-flex items-center gap-2 text-slate-500 min-w-0">
<div className="flex justify-end "> <RotateCwIcon size={14} aria-hidden />
<button <span className="truncate">{t("waypointDetail.updated")}</span>
type="button" </dt>
onClick={onEdit} <dd className="ms-auto text-right">
className="inline-flex items-center gap-1 rounded-md border border-slate-300 px-2 py-1 text-xs font-medium text-slate-700 hover:bg-slate-100 dark:border-slate-600 dark:text-slate-200 dark:hover:bg-slate-700" <time
> dateTime={new Date(waypoint.metadata.updated).toISOString()}
<Edit3Icon className="h-4 w-4" /> >
{t("waypointDetail.edit")} <TimeAgo timestamp={waypoint.metadata.updated} />
</button> </time>
</div> </dd>
)*/ </div>
} )}
</div>
{/* Expires */}
{waypoint.expire !== 0 && (
<div className="flex flex-wrap items-start gap-x-3">
<dt className="inline-flex items-center gap-2 text-slate-500 min-w-0">
<ClockFadingIcon size={14} aria-hidden />
<span className="truncate">{t("waypointDetail.expires")}</span>
</dt>
<dd className="ms-auto text-right">
<time dateTime={new Date(waypoint.expire * 1000).toISOString()}>
<TimeAgo timestamp={waypoint.expire * 1000} />
</time>
</dd>
</div>
)}
{/* Distance */}
{distance != null && (
<div className="flex flex-wrap items-start gap-x-3">
<dt className="inline-flex items-center gap-2 text-slate-500 min-w-0">
<MoveHorizontalIcon size={14} aria-hidden />
<span className="truncate">{t("waypointDetail.distance")}</span>
</dt>
<dd className="ms-auto text-right">
<data value={Math.round(distance)}>
{Math.round(distance)}{" "}
{distance === 1
? t("unit.meter.one")
: t("unit.meter.plural")}
</data>
</dd>
</div>
)}
{/* Bearing */}
{bearing != null && (
<div className="flex flex-wrap items-start gap-x-3">
<dt className="inline-flex items-center gap-2 text-slate-500 min-w-0">
<CompassIcon size={14} aria-hidden />
<span className="truncate">{t("waypointDetail.bearing")}</span>
</dt>
<dd className="ms-auto text-right inline-flex items-center ">
<NavigationIcon
size={16}
aria-hidden
className="shrink-0 origin-center transition-transform mr-2"
style={{ transform: `rotate(${bearing - 45}deg)` }}
/>
<data value={Math.round(bearing)}>{Math.round(bearing)}</data>
<span aria-hidden>{t("unit.degree.suffix")}</span>
</dd>
</div>
)}
{/* Locked To */}
{waypoint.lockedTo && (
<div className="flex flex-wrap items-start gap-x-3">
<dt className="inline-flex items-center gap-2 text-slate-500 min-w-0">
<UserLockIcon size={14} aria-hidden />
<span className="truncate">{t("waypointDetail.lockedTo")}</span>
</dt>
<dd className="ms-auto text-right">
{getNode(waypoint.lockedTo)?.user?.longName ??
t("unknown.longName")}
</dd>
</div>
)}
</dl>
</section>
</article>
); );
}; };

Loading…
Cancel
Save