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

Feat/halufot routes better indicator #266

Merged
merged 5 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/locale/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,15 @@
"bug_attachments": "קבצים מצורפים/ צילומי מסך",
"bug_attachments_upload_button": "לחץ להעלאה",
"bug_submit": "שלח את הדוח",
"bug_contact_name":"שם מלא",
"bug_contact_name_message":"אנא הזן את שמך!",
"bug_contact_email":"אי-מייל",
"bug_contact_email_message":"אנא הזן כתובת אי-מייל!",
"bug_form_description":"טופס זה נועד על מנת שנוכל לקבל פידבק ולשפר את האפליקציה.",
"bug_type":"סוג הבקשה",
"bug_type_message":"אנא הזן סוג בקשה!",
"bug_type_bug":"באג",
"bug_type_feature":"בקשה לפיתוח",
"funding_paragraph": "דאטאבוס פותח בסדנא לידע ציבורי, בעבודת מתנדבים, ומבוסס על"
"bug_contact_name": "שם מלא",
"bug_contact_name_message": "אנא הזן את שמך!",
"bug_contact_email": "אי-מייל",
"bug_contact_email_message": "אנא הזן כתובת אי-מייל!",
"bug_form_description": "טופס זה נועד על מנת שנוכל לקבל פידבק ולשפר את האפליקציה.",
"bug_type": "סוג הבקשה",
"bug_type_message": "אנא הזן סוג בקשה!",
"bug_type_bug": "באג",
"bug_type_feature": "בקשה לפיתוח",
"funding_paragraph": "דאטאבוס פותח בסדנא לידע ציבורי, בעבודת מתנדבים, ומבוסס על",
"halufa_ride": "נסיעה חלופית מס"
}
2 changes: 2 additions & 0 deletions src/model/busRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type BusRoute = {
direction: string
routeIds: number[]
lineRef: number
routeAlternative: string
}

export function fromGtfsRoute(gtfsRoute: GtfsRoutePydanticModel): BusRoute {
Expand All @@ -26,5 +27,6 @@ export function fromGtfsRoute(gtfsRoute: GtfsRoutePydanticModel): BusRoute {
direction: gtfsRoute.routeDirection!,
routeIds: [gtfsRoute.id],
lineRef: gtfsRoute.lineRef,
routeAlternative: gtfsRoute.routeAlternative!,
}
}
28 changes: 24 additions & 4 deletions src/pages/components/RouteSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
import { formatted, TEXTS } from 'src/resources/texts'
import { BusRoute } from 'src/model/busRoute'
import { Autocomplete, TextField } from '@mui/material'
import { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { TFunction } from 'i18next'

type RouteSelectorProps = {
routes: BusRoute[]
routeKey: string | undefined
setRouteKey: (routeKey: string) => void
}

const getRouteTitle = (route: BusRoute) =>
`${route.fromName} ${TEXTS.direction_arrow} ${route.toName}`
const getRouteTitle = (route: BusRoute, t: TFunction<'translation', undefined>) =>
`${route.fromName} ${TEXTS.direction_arrow} ${route.toName} ${
route.routeAlternative === '#' || route.routeAlternative === '0'
? ''
: `(${t('halufa_ride')} ${route.routeAlternative})`
}`

const RouteSelector = ({ routes, routeKey, setRouteKey }: RouteSelectorProps) => {
const valueFinned = routes.find((route) => route.key === routeKey)
const value = valueFinned ? valueFinned : null

const { t } = useTranslation()
useEffect(() => {
routes.sort((a, b) => {
if (
a.fromName === b.fromName &&
a.routeAlternative !== '#' &&
a.routeAlternative !== '0' &&
a.routeAlternative > b.routeAlternative
) {
return 1
}
return a.fromName > b.fromName ? 1 : -1
})
}, [routes])
return (
<Autocomplete
disablePortal
Expand All @@ -25,7 +45,7 @@ const RouteSelector = ({ routes, routeKey, setRouteKey }: RouteSelectorProps) =>
renderInput={(params) => (
<TextField {...params} label={formatted(TEXTS.choose_route, routes.length.toString())} />
)}
getOptionLabel={(route) => getRouteTitle(route)}
getOptionLabel={(route) => getRouteTitle(route, t)}
/>
)
}
Expand Down
Loading