All files / applications/go-by-transit/src/view/nearbyStops/components StopRouteListing.tsx

57.14% Statements 8/14
50% Branches 1/2
42.85% Functions 3/7
57.14% Lines 8/14

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                9x                                                                     5x   5x       5x                   9x 9x   9x                     9x                  
import { Button } from "@wintermuted/ui-react";
import { map, split } from "lodash";
import React, { Component } from "react";
import { TrimetRoute } from "../../../api/trimet/interfaces/types";
import RouteIndicator from "../../../component/route/RouteIndicator";
import "./StopRouteListing.scss";
 
function getSimpleRouteList(routes: TrimetRoute[]) {
  return map(routes, (route: TrimetRoute) => {
    return (
      <RouteIndicator key={route.route} routeId={route.route} route={route} />
    );
  });
}
 
function getDetailedRouteList(routes: TrimetRoute[], onClick) {
  return map(routes, (route: TrimetRoute) => {
    const description = split(route.desc, "-")[1];
 
    return (
      <li className="route-detail-list-item">
        <RouteIndicator key={route.route} routeId={route.route} route={route} />
        <span className="route-description">
          <span>{description}</span>
          <span className="route-description-divider">-</span>
          <span>{route.dir[0].desc}</span>
        </span>
      </li>
    );
  });
}
 
interface Props {
  routes: TrimetRoute[];
  onClick: (route: TrimetRoute) => void;
}
 
interface State {
  expanded: boolean;
}
 
export default class StopRouteListing extends Component<Props, State> {
  constructor(props) {
    super(props);
 
    this.state = {
      expanded: false
    };
 
    this.toggleDetails = this.toggleDetails.bind(this);
  }
 
  public toggleDetails() {
    this.setState({
      expanded: !this.state.expanded
    });
  }
 
  public render() {
    const { routes, onClick } = this.props;
    const { expanded } = this.state;
 
    Iif (expanded) {
      return (
        <div>
          <Button onClick={this.toggleDetails}>Details</Button>
          <ul className="route-detail-list">
            {getDetailedRouteList(routes, onClick)}
          </ul>
        </div>
      );
    }
 
    return (
      <div>
        <span className="serving-label">Routes: </span>
        <span className="route-indicators">{getSimpleRouteList(routes)}</span>
        <Button onClick={this.toggleDetails}>Details</Button>
      </div>
    );
  }
}