11import compact from 'lodash/compact' ;
2+ import sortBy from 'lodash/sortBy' ;
23import uniq from 'lodash/uniq' ;
34import { FC } from 'react' ;
4- import { twJoin } from 'tailwind-merge' ;
55import { StopRegistryTransportModeType } from '../../../../../generated/graphql' ;
66import { StopWithDetails } from '../../../../../types' ;
77import { StopPlaceState } from '../../../../../types/stop-registry' ;
88import { PageTitle } from '../../../../common' ;
9- import { getTransportModeIcon } from '../../../utils/getTransportModeIcon' ;
9+ import { StopTransportModeIcon } from '../../../components' ;
10+ import { MirroredQuayDetails } from '../useGetStopDetails' ;
1011import { ExtraActions } from './ExtraActions' ;
1112import { OpenOnMapButton } from './OpenOnMapButton' ;
1213import { StopTimetablesButton } from './StopTimetablesButton' ;
@@ -16,37 +17,65 @@ const testIds = {
1617 names : 'StopTitleRow::names' ,
1718} ;
1819
20+ type ModeStatus = {
21+ readonly mode : StopRegistryTransportModeType | null ;
22+ readonly active : boolean ;
23+ readonly trunkLine : boolean ;
24+ readonly speedTram : boolean ;
25+ } ;
26+
27+ function getModeStatus (
28+ stop : MirroredQuayDetails | StopWithDetails ,
29+ ) : ModeStatus {
30+ const stopPlace = 'stopPlace' in stop ? stop . stopPlace : stop . stop_place ;
31+
32+ return {
33+ mode : stopPlace ?. transportMode ?? null ,
34+ active : stop . quay ?. stopState === StopPlaceState . InOperation ,
35+ trunkLine : ! ! stop . quay ?. stopType . trunkLineStop ,
36+ speedTram : ! ! stop . quay ?. stopType . speedTramStop ,
37+ } ;
38+ }
39+
40+ function resolveModes (
41+ stopDetails : StopWithDetails | null ,
42+ mirroredQuays : ReadonlyArray < MirroredQuayDetails > ,
43+ ) : Array < ModeStatus > {
44+ if ( ! stopDetails ) {
45+ return [ ] ;
46+ }
47+
48+ return sortBy (
49+ [ getModeStatus ( stopDetails ) , ...mirroredQuays . map ( getModeStatus ) ] ,
50+ ( status ) => status . mode ,
51+ ) ;
52+ }
53+
1954type StopTitleRowProps = {
2055 readonly stopDetails : StopWithDetails | null ;
2156 readonly label : string ;
22- readonly mirroredTransportModes ? : ReadonlyArray < StopRegistryTransportModeType > ;
57+ readonly mirroredQuays : ReadonlyArray < MirroredQuayDetails > ;
2358} ;
2459
2560export const StopTitleRow : FC < StopTitleRowProps > = ( {
2661 stopDetails,
2762 label,
28- mirroredTransportModes = [ ] ,
63+ mirroredQuays ,
2964} ) => {
30- const ownMode = stopDetails ?. stop_place ?. transportMode ;
31- const allModes = uniq ( compact ( [ ownMode , ...mirroredTransportModes ] ) ) ;
32-
3365 return (
3466 < div className = "flex items-center gap-2" >
35- { allModes . map ( ( mode ) => (
36- < i
37- key = { mode }
38- className = { twJoin (
39- getTransportModeIcon (
40- mode ,
41- ( stopDetails ?. quay ?. stopState ?? StopPlaceState . InOperation ) ===
42- StopPlaceState . InOperation ,
43- stopDetails ?. quay ?. stopType . trunkLineStop ,
44- stopDetails ?. quay ?. stopType . speedTramStop ,
45- ) ,
46- 'text-3xl' ,
47- ) }
48- />
49- ) ) }
67+ { resolveModes ( stopDetails , mirroredQuays ) . map (
68+ ( { mode, active, trunkLine, speedTram } ) => (
69+ < StopTransportModeIcon
70+ key = { mode }
71+ className = "text-3xl"
72+ mode = { mode }
73+ active = { active }
74+ trunkLine = { trunkLine }
75+ speedTram = { speedTram }
76+ />
77+ ) ,
78+ ) }
5079 < PageTitle . H1
5180 className = "mr-2"
5281 testId = { testIds . label }
0 commit comments