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 117 118 119 | 63x 63x 63x 6x 1380x 1380x | import { Accordion, Button, ListGroup, ListItem } from "@wintermuted/ui-react";
import React from "react";
import FontAwesome from "react-fontawesome";
import { useTimeDisplay } from "./TimeDisplay";
import "./StopPredictionList.scss";
export interface StopPredictionItem {
id: string;
name: string;
stopId: string | number;
prediction?: { at: number; kind: "Estimated" | "Scheduled" };
predictionLabel: string;
stale?: boolean;
routes?: React.ReactNode;
}
export interface StopPredictionListProps {
stops: readonly StopPredictionItem[];
updateNote?: React.ReactNode;
onRefresh?: () => void;
refreshLabel?: string;
loading?: boolean;
error?: React.ReactNode;
notices?: readonly React.ReactNode[];
title?: React.ReactNode;
emptyContent?: React.ReactNode;
defaultTimezone?: string;
now?: number;
}
export function StopPredictionList({
stops,
updateNote,
onRefresh,
refreshLabel = "Refresh",
loading = false,
error,
notices = [],
title = (
<>
<FontAwesome name="map-marker" aria-hidden="true" /> Stops
</>
),
emptyContent,
defaultTimezone = "America/Los_Angeles",
now = Date.now(),
}: StopPredictionListProps) {
const { formatTime, formatDay } = useTimeDisplay();
const today = formatDay(now, defaultTimezone);
return (
<Accordion
open
className="transit-stop-panel ow-stop-prediction-list"
title={title}
>
{(updateNote || onRefresh) && (
<div className="transit-stop-prediction-status">
<span className="transit-trip-note">{updateNote}</span>
{onRefresh && (
<Button variant="secondary" onClick={onRefresh}>
{refreshLabel}
</Button>
)}
</div>
)}
{loading && (
<p role="status" className="transit-stop-prediction-message">
Loading stop predictions...
</p>
)}
{error && (
<p role="alert" className="transit-stop-prediction-message">
{error}
</p>
)}
{notices.map((notice, index) => (
<p key={index} className="transit-stop-prediction-message">
{notice}
</p>
))}
{!stops.length ? (
emptyContent
) : (
<ListGroup>
{stops.map((stop) => {
const day =
stop.prediction && formatDay(stop.prediction.at, defaultTimezone);
return (
<ListItem key={stop.id}>
<span>{stop.name}</span>
<small className="ow-stop-prediction-id">
{" "}
({stop.stopId})
</small>
<div className="transit-stop-prediction">
{stop.prediction ? (
<>
<time
dateTime={new Date(stop.prediction.at).toISOString()}
>
{formatTime(stop.prediction.at, defaultTimezone)}
</time>
{day !== today && ` ${day}`} {stop.prediction.kind}
{stop.stale && " ยท Last received"}
</>
) : (
stop.predictionLabel
)}
</div>
{stop.routes}
</ListItem>
);
})}
</ListGroup>
)}
</Accordion>
);
}
|