All files / applications/go-by-transit/src/component/route RouteListItem.tsx

23.8% Statements 5/21
7.14% Branches 1/14
20% Functions 1/5
23.8% Lines 5/21

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 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                                                                                                                        9x       9x 9x   9x                                                   9x                                            
import {
  Card,
  CardBody,
  CardText,
  CardTitle
} from "@wintermuted/ui-react";
import cx from "classnames";
import { get, isEmpty } from "lodash";
import React from "react";
import { NavLink } from "react-router-dom";
import {
  BLUE_LINE_NUMBER,
  GREEN_LINE_NUMBER,
  ORANGE_LINE_NUMBER,
  RED_LINE_NUMBER,
  STREETCAR_A_LOOP,
  STREETCAR_B_LOOP,
  STREETCAR_CL_LINE_SHUTTLE,
  STREETCAR_S_LINE,
  YELLOW_LINE_NUMBER
} from "../../api/trimet/constants";
import { TrimetRoute } from "../../api/trimet/interfaces/types";
import { maxLightRail } from "../../data/trimet/schedules/maxLightRail";
import FrequentServiceIndicator from "./FrequentServiceIndicator";
import RouteIndicator from "./RouteIndicator";
 
export function getRouteIndicatorClassName(route: number, className: string) {
  const style = {
    "route-blue": route === BLUE_LINE_NUMBER,
    "route-cyan":
      route === STREETCAR_A_LOOP || route === STREETCAR_CL_LINE_SHUTTLE,
    "route-green": route === GREEN_LINE_NUMBER,
    "route-lightgreen": route === STREETCAR_S_LINE,
    "route-orange": route === ORANGE_LINE_NUMBER,
    "route-pink": route === STREETCAR_B_LOOP,
    "route-red": route === RED_LINE_NUMBER,
    "route-yellow": route === YELLOW_LINE_NUMBER
  };
 
  return cx("nearby-route", className, style);
}
 
function getFrequentServiceIndicator(routeId: number) {
  const frequentService = get(
    maxLightRail,
    `[${routeId}].frequentService`,
    false
  );
 
  return (
    <div className="route-indicator-schedule-wrapper">
      <FrequentServiceIndicator
        small={true}
        frequentService={frequentService}
      />
    </div>
  );
}
 
export default function RouteListItem({ route }: { route: TrimetRoute }) {
  Iif (isEmpty(route)) {
    return null;
  }
 
  const routeId = route.route;
  const onClick = () => {};
 
  const bg = color => {
    // console.log("color", color, route);
    switch (color) {
      case "D81526":
        return "danger";
      case "084C8D":
        return "primary";
      case "F8C213":
        return "warning";
      case "008852":
        return "success";
      case "F58220":
        return "secondary";
      case "0093B2":
        return "info";
      case "000000":
        return "dark";
      case "CE0F69":
        return "light";
      case "84BD00":
        return "light";
      default:
        return "light";
    }
  };
 
  return (
    <div className="transit-column">
      <Card>
        <CardBody>
          <CardTitle>
            <NavLink to={`/lines/${routeId}`}>
              <RouteIndicator
                routeId={routeId}
                route={undefined}
                verbose={true}
                routeColor={""}
                linked={false}
              />
            </NavLink>
            {route.route}
          </CardTitle>
          <CardText>{route.desc}</CardText>
        </CardBody>
      </Card>
    </div>
  );
}