All files / applications/go-by-transit/src/view/nearby/components FollowedVehicleTrip.tsx

100% Statements 10/10
83.33% Branches 15/18
100% Functions 3/3
100% Lines 9/9

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                                      38x 38x 38x 38x   38x 38x 38x 13x   38x            
import React, { useEffect, useRef } from "react";
import { VehicleTripProgress } from "@overworld/ui/vehicles";
import { ROUTE_DISPLAY } from "../../../api/trimet/constants";
import type { VehiclePosition } from "../../../api/trimet/interfaces/vehicles";
import type { VehicleFeed } from "../util/useVehiclePositions";
import { useVehicleTrip } from "../util/useVehicleTrip";
import type { VehicleFollowView } from "../util/mapbox/vehicleLayer";
import { TopNavBar } from "./common/TopNavBar";
 
export { vehicleTripLegs } from "@overworld/trimet-client";
 
export default function FollowedVehicleTrip({ selection, feed, view, onViewChange, backTo, onBack }: {
  selection: VehiclePosition;
  feed: VehicleFeed;
  view: VehicleFollowView;
  onViewChange: (view: VehicleFollowView) => void;
  backTo: string;
  onBack: () => void;
}) {
  const vehicle = feed.vehicles.find(entry => entry.id === selection.id);
  const ended = Boolean(vehicle?.tripId && vehicle.tripId !== selection.tripId);
  const tracking = Boolean(vehicle && vehicle.tripId === selection.tripId);
  const result = useVehicleTrip(selection.blockId || "", selection.tripId || "", feed.updatedAt,
    tracking && !ended && feed.status !== "paused" && Boolean(selection.blockId && selection.tripId));
  const name = ROUTE_DISPLAY[selection.routeNumber] || (selection.routeNumber ? `Route ${selection.routeNumber}` : "Vehicle");
  const section = useRef<HTMLElement>(null);
  useEffect(() => {
    section.current?.querySelector<HTMLElement>(".transit-detail-back")?.focus({ preventScroll: true });
  }, [selection.id, selection.tripId]);
  return <VehicleTripProgress selection={selection} vehicle={vehicle} tracking={tracking} ended={ended}
    paused={feed.status === "paused"} result={result} view={view} onViewChange={onViewChange}
    sectionRef={section} timeZone="America/Los_Angeles"
    header={<TopNavBar id={`Following ${name}`} backTo={backTo} onBack={onBack} />}
  />;
}