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 | import { Table } from "@wintermuted/ui-react";
import { filter, flatten, includes, isEmpty, map, mapKeys } from "lodash";
import React from "react";
import FontAwesome from "react-fontawesome";
import { Link } from "react-router-dom";
import { Alert } from "../../../api/trimet/interfaces/alertsData";
import {
RouteDirectionStop,
RouteStopDirection,
TrimetRoute
} from "../../../api/trimet/interfaces/routes";
import Loading from "../../loading/Loading";
import "./LineDetailView.scss";
function getRouteDirectionStops(
stops: RouteDirectionStop[],
stopsWithAlerts: number[]
) {
return map(stops, stop => {
const stopHasAlert = includes(stopsWithAlerts, stop.locid);
return (
<tr>
<td>
<Link to={`/stop/${stop.locid}`}>
<small>{stop.locid}</small>
</Link>
</td>
<td>
<small>{stop.desc}</small>
</td>
<td>
<small>{stop.dir}</small>
</td>
<td>
{stopHasAlert && (
<span>
<FontAwesome name="bell-exclamation" /> Alerts
</span>
)}
</td>
</tr>
);
});
}
function getRouteDirections(
routeDirections: RouteStopDirection[],
stopsWithAlerts: number[]
) {
return map(routeDirections, routeDirection => {
return (
<div className="transit-column">
<header>
<h3 style={{ fontSize: "1rem" }}>{routeDirection.desc}</h3>
<Table responsive={true}>
<thead>
<tr>
<td>Stop ID</td>
<td>Name</td>
<td>Direction</td>
<td>Alerts</td>
</tr>
</thead>
<tbody>
{getRouteDirectionStops(routeDirection.stop, stopsWithAlerts)}
</tbody>
</Table>
</header>
</div>
);
});
}
interface Props {
route: TrimetRoute;
alertsData: Alert[];
}
export default function LineDetailViewStops(props: Props) {
const { route, alertsData } = props;
if (!route.dir) {
return <Loading />;
}
const mappedAlerts = flatten(
map(alertsData, (alert: Alert) =>
map(alert.location, location => location.id)
)
);
return (
<div className="transit-columns">
{getRouteDirections(route.dir, mappedAlerts)}
</div>
);
}
|