Skip to content

Commit 0a2b1ab

Browse files
committed
front: de-duplicate extractMarkerInformation()
All branches of the if are very similar here. Unfortunately because of the MarkerProperties type definition we need this ternary and spread operator. Signed-off-by: Simon Ser <contact@emersion.fr>
1 parent 5e5c4a1 commit 0a2b1ab

File tree

1 file changed

+20
-23
lines changed
  • front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap

1 file changed

+20
-23
lines changed

front/src/modules/trainschedule/components/ManageTrainSchedule/ManageTrainScheduleMap/ItineraryMarkers.tsx

+20-23
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ const formatPointWithNoName = (
6565
</>
6666
);
6767

68+
const MARKER_IMAGES = {
69+
[MARKER_TYPE.ORIGIN]: originSVG,
70+
[MARKER_TYPE.DESTINATION]: destinationSVG,
71+
[MARKER_TYPE.VIA]: viaSVG,
72+
};
73+
74+
const STDCM_MARKER_IMAGES = {
75+
[MARKER_TYPE.ORIGIN]: stdcmOrigin,
76+
[MARKER_TYPE.DESTINATION]: stdcmDestination,
77+
[MARKER_TYPE.VIA]: stdcmVia,
78+
};
79+
6880
const extractMarkerInformation = (
6981
pathSteps: MarkerInformation[],
7082
showStdcmAssets: boolean,
@@ -78,33 +90,18 @@ const extractMarkerInformation = (
7890
? suggestedOP.find((op) => matchPathStepAndOp(pathStep, op))
7991
: undefined;
8092

81-
if (pathStep.pointType === MARKER_TYPE.ORIGIN) {
82-
return {
83-
coordinates: pathStep.coordinates,
84-
type: MARKER_TYPE.ORIGIN,
85-
imageSource: showStdcmAssets ? stdcmOrigin : originSVG,
86-
op: matchingOp,
87-
pathStep,
88-
};
89-
}
90-
91-
if (pathStep.pointType === MARKER_TYPE.DESTINATION) {
92-
return {
93-
coordinates: pathStep.coordinates,
94-
type: MARKER_TYPE.DESTINATION,
95-
imageSource: showStdcmAssets ? stdcmDestination : destinationSVG,
96-
op: matchingOp,
97-
pathStep,
98-
};
99-
}
100-
93+
const images = showStdcmAssets ? STDCM_MARKER_IMAGES : MARKER_IMAGES;
10194
return {
10295
coordinates: pathStep.coordinates,
103-
type: MARKER_TYPE.VIA,
104-
imageSource: showStdcmAssets ? stdcmVia : viaSVG,
105-
index,
96+
imageSource: images[pathStep.pointType],
10697
op: matchingOp,
10798
pathStep,
99+
...(pathStep.pointType === MARKER_TYPE.VIA
100+
? {
101+
type: MARKER_TYPE.VIA,
102+
index,
103+
}
104+
: { type: pathStep.pointType }),
108105
};
109106
})
110107
.filter((marker): marker is MarkerProperties => marker !== null);

0 commit comments

Comments
 (0)