All files / presentation/ui/src WalkingDistance.tsx

100% Statements 3/3
100% Branches 13/13
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                            258x 27x                     231x                              
import React from "react";
import "./WalkingDistance.scss";
 
export type WalkingDistanceEstimate =
  | { status: "ready"; meters: number; seconds: number }
  | { status: "unreachable" | "uncertain" };
 
export interface WalkingDistanceProps {
  enabled: boolean;
  loading?: boolean;
  estimate?: WalkingDistanceEstimate;
  straightLine: string;
  formatDistance: (meters: number) => string;
}
 
export function WalkingDistance({
  enabled,
  loading = false,
  estimate,
  straightLine,
  formatDistance,
}: WalkingDistanceProps) {
  if (enabled && estimate?.status === "ready") {
    return (
      <span className="transit-simple-route-distance">
        <span>{formatDistance(estimate.meters)} walk</span>
        <small>
          {estimate.seconds < 60
            ? "Under 1 min"
            : `About ${Math.ceil(estimate.seconds / 60)} min`}
        </small>
      </span>
    );
  }
  return (
    <span className="transit-simple-route-distance">
      {enabled && (
        <span>
          {loading
            ? "Calculating walk..."
            : estimate?.status === "unreachable"
              ? "No walking route found"
              : "Walking distance unavailable"}
        </span>
      )}
      <small>{straightLine} (straight-line)</small>
    </span>
  );
}