forked from HSLdevcom/OpenTripPlanner
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
215 additions
and
21 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
client-next/src/components/ItineraryList/ItineraryDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { TripPattern } from '../../gql/graphql.ts'; | ||
import { ItineraryLegDetails } from './ItineraryLegDetails.tsx'; | ||
|
||
export function ItineraryDetails({ tripPattern }: { tripPattern: TripPattern }) { | ||
return ( | ||
<div> | ||
{tripPattern.systemNotices.length > 0 && ( | ||
<p>System tags: {tripPattern.systemNotices.map((systemNotice) => systemNotice.tag).join(', ')}</p> | ||
)} | ||
{tripPattern.legs.map((leg, i) => ( | ||
<ItineraryLegDetails key={leg.id ? leg.id : `noid_${i}`} leg={leg} isLast={i === tripPattern.legs.length - 1} /> | ||
))} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
client-next/src/components/ItineraryList/ItineraryLegDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Leg, Mode } from '../../gql/graphql.ts'; | ||
import { LegTime } from './LegTime.tsx'; | ||
import { formatDistance } from '../../util/formatDistance.ts'; | ||
import { formatDuration } from '../../util/formatDuration.ts'; | ||
|
||
export function ItineraryLegDetails({ leg, isLast }: { leg: Leg; isLast: boolean }) { | ||
return ( | ||
<div style={{ border: '1px dotted grey' }}> | ||
<LegTime aimedTime={leg.aimedStartTime} expectedTime={leg.expectedStartTime} />-{' '} | ||
<LegTime aimedTime={leg.aimedEndTime} expectedTime={leg.expectedEndTime} /> <b>{leg.mode}</b>{' '} | ||
{leg.line && ( | ||
<> | ||
<u> | ||
{leg.line.publicCode} {leg.toEstimatedCall?.destinationDisplay?.frontText} | ||
</u> | ||
, {leg.authority?.name} | ||
</> | ||
)}{' '} | ||
{formatDistance(leg.distance)}, {formatDuration(leg.duration)} | ||
{leg.mode !== Mode.Foot && <u>from {leg.fromPlace.name}</u>} {!isLast && <u>to {leg.toPlace.name}</u>} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
client-next/src/components/ItineraryList/ItineraryPaginationControl.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Button } from 'react-bootstrap'; | ||
|
||
export function ItineraryPaginationControl({ | ||
previousPageCursor, | ||
nextPageCursor, | ||
onPagination, | ||
}: { | ||
previousPageCursor?: string | null; | ||
nextPageCursor?: string | null; | ||
onPagination: (cursor: string) => void; | ||
}) { | ||
return ( | ||
<div style={{ display: 'flex', justifyContent: 'space-evenly', margin: '1rem 0 ' }}> | ||
<Button | ||
disabled={!previousPageCursor} | ||
onClick={() => { | ||
previousPageCursor && onPagination(previousPageCursor); | ||
}} | ||
> | ||
Previous page | ||
</Button>{' '} | ||
<Button | ||
disabled={!nextPageCursor} | ||
onClick={() => { | ||
nextPageCursor && onPagination(nextPageCursor); | ||
}} | ||
> | ||
Next page | ||
</Button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { formatTime } from '../../util/formatTime.ts'; | ||
|
||
export function LegTime({ aimedTime, expectedTime }: { aimedTime: string; expectedTime: string }) { | ||
return aimedTime !== expectedTime ? ( | ||
<> | ||
<span style={{ color: 'red' }}>{formatTime(expectedTime)}</span> | ||
<span style={{ textDecoration: 'line-through' }}>{formatTime(aimedTime)}</span> | ||
</> | ||
) : ( | ||
<span>{formatTime(expectedTime)}</span> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Format distance | ||
* | ||
* Adapted from src/client/js/otp/util/Geo.js#distanceStringMetric | ||
*/ | ||
export function formatDistance(meters: number) { | ||
let kilometers = meters / 1000; | ||
if (kilometers > 100) { | ||
//100 km => 999999999 km | ||
return `${kilometers.toFixed(0)} km`; | ||
} else if (kilometers > 1) { | ||
//1.1 km => 99.9 km | ||
return `${kilometers.toFixed(1)} km`; | ||
} else { | ||
//1m => 999m | ||
return `${meters.toFixed(0)} m`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Format duration in seconds | ||
* | ||
* Adapted from src/client/js/otp/util/Time.js#secsToHrMinSec | ||
*/ | ||
export function formatDuration(seconds: number) { | ||
const hrs = Math.floor(seconds / 3600); | ||
const mins = Math.floor(seconds / 60) % 60; | ||
const secs = seconds % 60; | ||
|
||
let formatted = ''; | ||
|
||
if (hrs === 1) { | ||
formatted = `${formatted}${hrs} hr `; | ||
} else if (hrs > 1) { | ||
formatted = `${formatted}${hrs} hrs `; | ||
} | ||
|
||
if (mins === 1) { | ||
formatted = `${formatted}${mins} min `; | ||
} else if (mins > 1) { | ||
formatted = `${formatted}${mins} mins `; | ||
} | ||
|
||
if (secs === 1) { | ||
formatted = `${formatted}${secs} sec `; | ||
} else if (secs > 1) { | ||
formatted = `${formatted}${secs} secs `; | ||
} | ||
|
||
return formatted; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Format departure and arrival times from scalar dateTime strings | ||
* | ||
* If style argument is provided formatted with ('medium') or without ('short') seconds, | ||
* otherwise seconds are shown if not 0. | ||
*/ | ||
export function formatTime(dateTime: string, style?: 'short' | 'medium') { | ||
const parsed = new Date(dateTime); | ||
return parsed.toLocaleTimeString('en-US', { | ||
timeStyle: style ? style : parsed.getSeconds() === 0 ? 'short' : 'medium', | ||
hourCycle: 'h24', | ||
}); | ||
} |