Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Floating Vehicle Bunching #1333

Open
wants to merge 10 commits into
base: dev
Choose a base branch
from
2 changes: 1 addition & 1 deletion i18n/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ components:
itinerariesFound: >-
{itineraryNum, plural, one {# itinerary found} other {# itineraries found}
}
numIssues: "{issueNum, plural, one {# issue} other {# issues} }"
resultsSortedBy: >-
Trip results currently sorted by {sortSelected}. To change the way results
are sorted, use the "Sort Results" button below.
Expand All @@ -374,6 +373,7 @@ components:
signIn: Log in
signOut: Log out
NearbyView:
additionalVehicles: +{count} more nearby
bikeRentalStation: Bike Rental Station
bikesAvailable: "{bikesAvailable, plural, one {# bike} other {# bikes}} available"
companyBicycle: "{company} Bike"
Expand Down
2 changes: 1 addition & 1 deletion i18n/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ components:
changeSortDir: Changer l'ordre de tri
howToFindResults: Pour afficher les résultats, utilisez l'en-tête Trajets trouvés plus bas.
itinerariesFound: "{itineraryNum, plural, one {# trajet trouvé} other {# trajets trouvés} }"
numIssues: "{issueNum, plural, one {# problème} other {# problèmes} }"
resultsSortedBy: >-
Résultats triés par {sortSelected}. Pour modifier l'ordre, utilisez le
bouton "Trier les résultats" plus bas.
Expand All @@ -389,6 +388,7 @@ components:
signIn: Se connecter
signOut: Déconnexion
NearbyView:
additionalVehicles: +{count} autres à proximité
bikeRentalStation: Borne de location de vélos
bikesAvailable: >-
{bikesAvailable, plural, one {# vélo disponible} other {# vélos
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ export const fetchNearby = (position, radius, currentServiceWeek) => {
$radius: Int
$currentServiceWeek: LocalDateRangeInput
) {
nearest(lat:$lat, lon:$lon, maxDistance: $radius, first: 100, filterByPlaceTypes: [STOP, VEHICLE_RENT, BIKE_PARK, CAR_PARK]) {
nearest(lat:$lat, lon:$lon, maxDistance: $radius, first: 100, filterByPlaceTypes: [STOP, VEHICLE_RENT, BIKE_PARK, CAR_PARK], maxResults: 100) {
edges {
node {
id
Expand Down
54 changes: 44 additions & 10 deletions lib/components/viewers/nearby/nearby-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as locationActions from '../../../actions/location'
import * as mapActions from '../../../actions/map'
import * as uiActions from '../../../actions/ui'
import { AppReduxState } from '../../../util/state-types'
import { GeocoderConfig } from '../../../util/config-types'
import { GeocoderConfig, NearbyViewConfig } from '../../../util/config-types'
import { getCurrentServiceWeek } from '../../../util/current-service-week'
import {
PatternStopTime,
Expand Down Expand Up @@ -54,13 +54,15 @@ type Props = {
currentServiceWeek?: ServiceWeek
) => void
geocoderConfig: GeocoderConfig
getCurrentPosition: any // TODO
getCurrentPosition: any
// TODO
hideBackButton?: boolean
hideEmptyStops?: boolean
location: string
mobile?: boolean
// Todo: type nearby results
nearby: any
nearbyViewConfig?: NearbyViewConfig
nearbyViewCoords?: LatLonObj
radius?: number
routeSortComparator: (a: PatternStopTime, b: PatternStopTime) => number
Expand Down Expand Up @@ -133,6 +135,7 @@ function NearbyView({
location,
mobile,
nearby,
nearbyViewConfig,
nearbyViewCoords,
radius,
routeSortComparator,
Expand Down Expand Up @@ -253,14 +256,39 @@ function NearbyView({
)
)

// If configured, filter out stops that don't have any patterns
const filteredNearby = nearby?.filter((n: any) => {
if (n.place.__typename === 'Stop' && hideEmptyStops) {
const patternArray = patternArrayforStops(n.place, routeSortComparator)
return !(patternArray?.length === 0)
const scooterGroups = nearby?.reduce((acc: any, item: any) => {
if (item.place.__typename === 'RentalVehicle') {
const network = item.place.network
if (!acc[network]) {
acc[network] = {
count: 1,
nearest: item
}
} else {
acc[network].count++
}
}
return true
})
return acc
}, {})

// If configured, filter out stops that don't have any patterns
const filteredNearby = nearby
?.filter((n: any) => {
if (n.place.__typename === 'Stop' && nearbyViewConfig?.hideEmptyStops) {
const patternArray = patternArrayforStops(n.place, routeSortComparator)
return !(patternArray?.length === 0)
}
return true
})
.filter((n: any) => {
if (
Object.keys(scooterGroups).length > 0 &&
n.place.__typename === 'RentalVehicle'
) {
return scooterGroups[n.place?.network].nearest.id === n.id
}
return true
})

const nearbyItemList =
filteredNearby?.map &&
Expand All @@ -281,7 +309,12 @@ function NearbyView({
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
tabIndex={0}
>
{getNearbyItem({ ...n.place, distance: n.distance, nearbyRoutes })}
{getNearbyItem({
...n.place,
additionalCount: scooterGroups?.[n.place?.network]?.count,
distance: n.distance,
nearbyRoutes
})}
</div>
</li>
))
Expand Down Expand Up @@ -420,6 +453,7 @@ const mapStateToProps = (state: AppReduxState) => {
homeTimezone: config.homeTimezone,
location: state.router.location.hash,
nearby: nearby?.data,
nearbyViewConfig,
nearbyViewCoords,
radius: config.nearbyView?.radius,
routeSortComparator
Expand Down
30 changes: 29 additions & 1 deletion lib/components/viewers/nearby/styled.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DARK_TEXT_GREY, grey } from '../../util/colors'
import styled from 'styled-components'

import { DARK_TEXT_GREY, grey } from '../../util/colors'

export const FloatingLoadingIndicator = styled.div`
aspect-ratio: 1;
background: white;
Expand Down Expand Up @@ -108,3 +109,30 @@ export const Scrollable = styled.div`
height: 100%;
overflow-y: scroll;
`

export const CardFooter = styled.div`
background: rgba(0, 0, 0, 0.2);
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
color: ${grey[700]};
font-size: 15px;
padding: 5px 12px;
margin-top: -6px;

span {
padding-top: 5px;
display: block;
}

&::before {
background: white;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this for the margin between the footer and the body of the card, and can it be done using margin-top of CardFooter itself instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used to create the border radius effect on the body of the card, so it looks like the footer is peeking out from below it.
image

border-radius: 10px;
content: '';
display: block;
height: 12px;
margin-left: -12px;
margin-top: -12px;
padding: 0;
width: calc(100% + 24px);
}
`
18 changes: 16 additions & 2 deletions lib/components/viewers/nearby/vehicle-rent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Bicycle } from '@styled-icons/fa-solid/Bicycle'
import { Company } from '@opentripplanner/types'
import { connect } from 'react-redux'
import { IntlShape, useIntl } from 'react-intl'
import { FormattedMessage, IntlShape, useIntl } from 'react-intl'
// @ts-expect-error icons doesn't have typescript?
import { Micromobility } from '@opentripplanner/icons'
import React, { ReactElement } from 'react'
Expand All @@ -10,7 +10,7 @@ import { AppReduxState } from '../../../util/state-types'
import { IconWithText } from '../../util/styledIcon'
import CompanyIcon from '../../util/company-icon'

import { Card, CardBody, CardHeader, CardTitle } from './styled'
import { Card, CardBody, CardFooter, CardHeader, CardTitle } from './styled'
import DistanceDisplay from './distance-display'

type VehicleFormFactor =
Expand Down Expand Up @@ -74,6 +74,7 @@ const Vehicle = ({
companies?: Company[]
fromToSlot: JSX.Element
vehicle: {
additionalCount: number
distance: number
name: string
network: string
Expand All @@ -90,6 +91,7 @@ const Vehicle = ({
vehicle.name === 'Default vehicle type'
? getVehicleText(formFactor, companyLabel, intl)
: vehicle.name

return (
<Card>
<CardHeader>
Expand All @@ -116,6 +118,18 @@ const Vehicle = ({
)}
{fromToSlot}
</CardBody>
{vehicle.additionalCount > 0 && (
<CardFooter>
<span>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the span needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The span is keeping the text separate from the &::before

<FormattedMessage
id="components.NearbyView.additionalVehicles"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this layout more advantageous than placing this text underneath the distance label (see illustration)?
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this but it gets busy especially in the case of a 2-line title

values={{
count: vehicle.additionalCount
}}
/>
</span>
</CardFooter>
)}
</Card>
)
}
Expand Down
Loading