-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1276 from opentripplanner/pass-operator-logos-to-…
…map-popup Pass transit operator logos to map-popup
- Loading branch information
Showing
9 changed files
with
4,032 additions
and
197 deletions.
There are no files selected for viewing
3,963 changes: 3,829 additions & 134 deletions
3,963
__tests__/components/viewers/__snapshots__/nearby-view.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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,38 @@ | ||
import { connect } from 'react-redux' | ||
import { TransitOperator } from '@opentripplanner/types' | ||
import React from 'react' | ||
|
||
import { AppReduxState } from '../../util/state-types' | ||
import { FETCH_STATUS } from '../../util/constants' | ||
|
||
import { StopData } from './types' | ||
import TransitOperatorLogos from './transit-operator-icons' | ||
|
||
interface Props { | ||
stopData?: StopData | ||
transitOperators: TransitOperator[] | ||
} | ||
|
||
function TransitOperatorIcons({ stopData, transitOperators }: Props) { | ||
const loading = stopData?.fetchStatus === FETCH_STATUS.FETCHING | ||
return ( | ||
<TransitOperatorLogos | ||
loading={loading} | ||
stopData={stopData} | ||
transitOperators={transitOperators} | ||
/> | ||
) | ||
} | ||
|
||
const mapStateToProps = ( | ||
state: AppReduxState, | ||
ownProps: Props & { stopId: string } | ||
) => { | ||
const stops = state.otp.transitIndex.stops | ||
return { | ||
stopData: stops?.[ownProps.stopId], | ||
transitOperators: state.otp.config.transitOperators || [] | ||
} | ||
} | ||
|
||
export default connect(mapStateToProps)(TransitOperatorIcons) |
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,83 @@ | ||
import { MapPin } from '@styled-icons/fa-solid' | ||
import { useIntl } from 'react-intl' | ||
import React from 'react' | ||
import Skeleton from 'react-loading-skeleton' | ||
import type { TransitOperator } from '@opentripplanner/types' | ||
|
||
import InvisibleA11yLabel from './invisible-a11y-label' | ||
import OperatorLogo from './operator-logo' | ||
import type { StopData } from './types' | ||
|
||
const Operator = ({ operator }: { operator?: TransitOperator }) => { | ||
const intl = useIntl() | ||
|
||
if (!operator) { | ||
return null | ||
} else { | ||
const operatorLogoAriaLabel = intl.formatMessage( | ||
{ | ||
id: 'components.StopViewer.operatorLogoAriaLabel' | ||
}, | ||
{ | ||
operatorName: operator.name | ||
} | ||
) | ||
return operator.logo ? ( | ||
// Span with agency classname allows optional contrast/customization in user | ||
// config for logos with poor contrast. Class name is hyphenated agency name | ||
// e.g. "sound-transit" | ||
<span | ||
className={ | ||
operator.name ? operator.name.replace(/\s+/g, '-').toLowerCase() : '' | ||
} | ||
> | ||
<OperatorLogo alt={operatorLogoAriaLabel} operator={operator} styled /> | ||
</span> | ||
) : ( | ||
// If operator exists but logo is missing, | ||
// we still need to announce the operator name to screen readers. | ||
<> | ||
<MapPin /> | ||
<InvisibleA11yLabel>{operatorLogoAriaLabel}</InvisibleA11yLabel> | ||
</> | ||
) | ||
} | ||
} | ||
|
||
const TransitOperatorLogos = ({ | ||
loading = false, | ||
stopData, | ||
transitOperators | ||
}: { | ||
loading?: boolean | ||
stopData?: StopData | ||
transitOperators?: TransitOperator[] | ||
}): JSX.Element => { | ||
const agencies = | ||
(stopData && | ||
stopData.stoptimesForPatterns?.reduce<Set<string>>((prev, cur) => { | ||
// @ts-expect-error The agency type is not yet compatible with OTP2 | ||
const agencyGtfsId = cur.pattern.route.agency?.gtfsId | ||
return agencyGtfsId ? prev.add(agencyGtfsId) : prev | ||
}, new Set())) || | ||
new Set() | ||
|
||
return ( | ||
<> | ||
{loading ? ( | ||
<Skeleton height={20} style={{ marginRight: '0.5ch' }} width={20} /> | ||
) : ( | ||
transitOperators | ||
?.filter((to) => Array.from(agencies).includes(to.agencyId)) | ||
// Second pass to remove duplicates based on name | ||
.filter( | ||
(to, index, arr) => | ||
index === arr.findIndex((t) => t?.name === to?.name) | ||
) | ||
.map((to) => <Operator key={to.agencyId} operator={to} />) | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
export default TransitOperatorLogos |
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