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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | 326x 326x 6x 6x 10x 12x 18x 2x 2x | import React from "react";
import { PlannerDisclosure } from "@overworld/ui/journeys";
import { endpointLabel } from "@overworld/journeys";
import { Button, FieldGroup } from "@wintermuted/ui-react";
import { MultiSelect } from "@wintermuted/ui-react/select";
import FontAwesome from "react-fontawesome";
import type { RecentJourney } from "../../api/localstorage/recentJourneys";
import { EndpointMarker } from "./DirectionsStopPair";
import PlannerEndpointField from "./PlannerEndpointField";
import type { TripPlannerProps } from "./TripPlannerModel";
import type { TripPlannerState } from "./useTripPlannerState";
type TripPlannerFormProps = Pick<TripPlannerProps, "inSidebar" | "savedStops"> & {
state: TripPlannerState;
};
export default function TripPlannerForm({ state, inSidebar, savedStops }: TripPlannerFormProps) {
const {
stopSummary, editStopsButton, focusBoardingStop, setEditingStops, searchFields,
tripState, confirmPlace, fromNamedPlace, toNamedPlace, searchParams, recentTrips,
chooseRecentTrip, catalogState, catalog, submit, fromLocation, toLocation,
fromStop, toStop, swapEndpoints, locating, validationError,
} = state;
return (
<PlannerDisclosure title="Plan a trip" headingId="transit-planner-title" edit={stopSummary ? {
label: stopSummary.from.kind === "stop" && stopSummary.to.kind === "stop" ? "Edit stops" : "Edit locations",
buttonRef: editStopsButton,
onClick: () => {
focusBoardingStop.current = true;
setEditingStops(true);
},
} : undefined}>
{stopSummary ? (
<dl className={`transit-planner-stop-summary transit-planner-endpoint-pair${inSidebar ? " transit-planner-endpoint-pair--rail" : ""}`}>
<div className="transit-planner-endpoint">
<dt>{inSidebar && <EndpointMarker field="from" />}{stopSummary.from.kind === "stop" ? "Boarding stop" : "Origin"}</dt>
<dd>{endpointLabel(stopSummary.from, stopSummary.response.from)}</dd>
</div>
<div className="transit-planner-endpoint">
<dt>{inSidebar && <EndpointMarker field="to" />}{stopSummary.to.kind === "stop" ? "Destination stop" : "Destination"}</dt>
<dd>{endpointLabel(stopSummary.to, stopSummary.response.to)}</dd>
</div>
</dl>
) : (
<fieldset ref={searchFields} className="transit-planner-search-fields" disabled={tripState.status === "loading"}
aria-label="Trip search">
{!inSidebar && (
<p className="transit-planner-intro">
Plan between TriMet stops, street addresses, places, or coordinates.
</p>
)}
{confirmPlace && (fromNamedPlace || toNamedPlace) && <p role="status" className="transit-planner-message">
Confirm the approximate arrival point below, or enter a public entrance address. Finding trips does not verify public access.
{searchParams.get("fromOrigin") === "device" ? " Origin uses your previously selected device location, not live tracking." :
searchParams.get("fromOrigin") === "area" ? " Origin uses your previously selected map search center." :
searchParams.get("fromOrigin") === "pin" ? " Origin uses your previously dropped pin." : ""}
</p>}
{recentTrips?.unavailable ? (
<p className="transit-planner-message" role="status">Recent trips are unavailable on this device.</p>
) : recentTrips?.journeys.length > 0 && (
<div className="transit-planner-recent">
<FieldGroup label="Recent trips" htmlFor="planner-recent">
<MultiSelect<RecentJourney, false>
inputId="planner-recent"
isMulti={false}
options={recentTrips.journeys}
value={null}
onChange={chooseRecentTrip}
getOptionLabel={({ from, to }) => `${from.desc} (${from.locid}) to ${to.desc} (${to.locid})`}
getOptionValue={({ from, to }) => `${from.locid}-${to.locid}`}
placeholder="Choose a recent trip"
menuPortalTarget={document.body}
menuPosition="fixed"
menuPlacement="auto"
maxMenuHeight={240}
styles={{
control: base => ({ ...base, minHeight: "var(--wm-control-height)" }),
menu: base => ({ ...base, fontSize: "0.875rem" }),
menuPortal: base => ({ ...base, zIndex: 5 })
}}
/>
</FieldGroup>
</div>
)}
{catalogState.loading && (
<p role="status">
{catalog ? "Refreshing stops…" : "Loading TriMet stops…"}
</p>
)}
{catalogState.error && (
<div role="alert" className="transit-planner-message">
<p>
The TriMet stop catalog could not be loaded.
{catalog
? " The previously loaded stops are still available."
: " Check your connection and try again."}
</p>
<Button
type="button"
variant="secondary"
onClick={catalogState.refresh}
>
Retry loading stops
</Button>
</div>
)}
<form className="transit-planner-form" onSubmit={submit}>
<div className={`transit-planner-endpoint-pair transit-planner-endpoint-pair--editing${inSidebar ? " transit-planner-endpoint-pair--rail" : ""}`}>
<div className="transit-planner-endpoint">
{inSidebar && <EndpointMarker field="from" />}
<PlannerEndpointField field="from" state={state} savedStops={savedStops} />
</div>
<Button type="button" size="sm" variant="secondary" className="transit-planner-swap"
aria-label="Swap origin and destination"
title="Swap origin and destination"
disabled={!(fromLocation?.trim() || toLocation?.trim() ||
(fromLocation === undefined && fromStop) || (toLocation === undefined && toStop))}
onClick={swapEndpoints}>
<FontAwesome name="exchange" aria-hidden="true" />
</Button>
<div className="transit-planner-endpoint">
{inSidebar && <EndpointMarker field="to" />}
<PlannerEndpointField field="to" state={state} savedStops={savedStops} />
</div>
</div>
<p className="transit-planner-select-hint" id="planner-location-privacy">
Nearest stop uses your location on this device only.
</p>
{locating && <p className="transit-planner-select-hint" role="status">Finding nearest stop…</p>}
{(fromLocation === undefined || toLocation === undefined) &&
<p className="transit-planner-select-hint">Search by stop ID, stop name, route name, or common place.</p>}
{validationError && (
<p className="transit-planner-message" role="alert">
{validationError}
</p>
)}
<Button
type="submit"
disabled={Boolean(locating) ||
(fromLocation === undefined ? !fromStop || catalogState.loading : !fromLocation.trim()) ||
(toLocation === undefined ? !toStop || catalogState.loading : !toLocation.trim())}
>
Find trips
</Button>
</form>
</fieldset>
)}
</PlannerDisclosure>
);
}
|