All files / applications/go-by-transit/src/component/modal ModalContent.tsx

100% Statements 7/7
100% Branches 2/2
100% Functions 5/5
100% Lines 7/7

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                      3x                         1x 1x                     3x 2x     1x                     3x              
import { Button } from "@wintermuted/ui-react";
import React from "react";
import FontAwesome from "react-fontawesome";
import { Direction, TrimetRoute } from "../../api/trimet/interfaces/types";
 
interface Props {
  route: TrimetRoute;
  closeModal: () => void;
}
 
function getHeader(closeModal: () => void) {
  return (
    <header className="info-header">
      <h4>Route Info</h4>
      <div className="close-button-container">
        <Button onClick={closeModal} name="Close" title="Close">
          <FontAwesome name="times" />
        </Button>
      </div>
    </header>
  );
}
 
function getRouteDirections(routeDirections: Direction[]) {
  return routeDirections.map((route: Direction) => {
    return (
      <ul key={route.dir}>
        <li>
          {route.desc} | {route.dir}
        </li>
      </ul>
    );
  });
}
 
function getSection(route: TrimetRoute) {
  if (!route) {
    return null;
  }
 
  return (
    <section>
      <h5>{route.desc}</h5>
      <p>Type: {route.type}</p>
      <h4>Directions:</h4>
      {getRouteDirections(route.dir)}
    </section>
  );
}
 
export default function ModalContent({ route, closeModal }: Props) {
  return (
    <div className="modal-content">
      {getHeader(closeModal)}
      {getSection(route)}
    </div>
  );
}