@@ -48,6 +48,8 @@ import {
4848 trainLineNodeFinder ,
4949} from "@/maps/api" ;
5050import {
51+ extractStationLabel ,
52+ extractStationName ,
5153 geoSpatialVoronoi ,
5254 holedMask ,
5355 lngLatToText ,
@@ -93,6 +95,8 @@ export const ZoneSidebar = () => {
9395 const includeDefaultStations = useStore ( includeDefaultStationsAtom ) ;
9496 const $customStations = useStore ( customStationsAtom ) ;
9597 const [ commandValue , setCommandValue ] = useState < string > ( "" ) ;
98+ const [ stationSearch , setStationSearch ] = useState < string > ( "" ) ;
99+ const isStationSearchActive = stationSearch . trim ( ) . length > 0 ;
96100 const setStations = trainStations . set ;
97101 const sidebarRef = useRef < HTMLDivElement > ( null ) ;
98102 const [ importUrl , setImportUrl ] = useState ( "" ) ;
@@ -160,9 +164,7 @@ export const ZoneSidebar = () => {
160164
161165 marker . bindPopup (
162166 `<b>${
163- geoJsonPoint . properties [ "name:en" ] ||
164- geoJsonPoint . properties . name ||
165- "No Name Found"
167+ extractStationName ( geoJsonPoint ) || "No Name Found"
166168 } (${ lngLatToText (
167169 geoJsonPoint . geometry . coordinates as [ number , number ] ,
168170 ) } )</b>`,
@@ -331,11 +333,9 @@ export const ZoneSidebar = () => {
331333
332334 if ( nodes . length === 0 ) {
333335 toast . warning (
334- `No train line found for ${
335- nearestTrainStation . properties [
336- "name:en"
337- ] || nearestTrainStation . properties . name
338- } `,
336+ `No train line found for ${ extractStationName (
337+ nearestTrainStation ,
338+ ) } `,
339339 ) ;
340340 continue ;
341341 } else {
@@ -354,9 +354,7 @@ export const ZoneSidebar = () => {
354354 }
355355 }
356356
357- const englishName =
358- nearestTrainStation . properties [ "name:en" ] ||
359- nearestTrainStation . properties . name ;
357+ const englishName = extractStationName ( nearestTrainStation ) ;
360358
361359 if ( ! englishName )
362360 return toast . error ( "No English name found" ) ;
@@ -365,10 +363,7 @@ export const ZoneSidebar = () => {
365363 const letter = englishName [ 0 ] . toUpperCase ( ) ;
366364
367365 circles = circles . filter ( ( circle : any ) => {
368- const name =
369- circle . properties . properties [ "name:en" ] ||
370- circle . properties . properties . name ;
371-
366+ const name = extractStationName ( circle . properties ) ;
372367 if ( ! name ) return false ;
373368
374369 return question . data . same
@@ -380,10 +375,9 @@ export const ZoneSidebar = () => {
380375 const comparison = question . data . lengthComparison ;
381376
382377 circles = circles . filter ( ( circle : any ) => {
383- const name =
384- circle . properties . properties [ "name:en" ] ||
385- circle . properties . properties . name ;
378+ const name = extractStationName ( circle . properties ) ;
386379 if ( ! name ) return false ;
380+
387381 if ( comparison === "same" ) {
388382 return name . length === seekerLength ;
389383 } else if ( comparison === "shorter" ) {
@@ -942,16 +936,9 @@ export const ZoneSidebar = () => {
942936 x . properties . properties . id ===
943937 commandValue ,
944938 ) ;
945- const displayName =
946- selected ?. properties . properties [
947- "name:en"
948- ] ||
949- selected ?. properties . properties
950- . name ||
951- lngLatToText (
952- selected ?. properties . geometry
953- . coordinates ,
954- ) ;
939+ const displayName = extractStationLabel (
940+ selected ?. properties ,
941+ ) ;
955942 const id = selected ?. properties
956943 . properties . id as string ;
957944 const coords = selected ?. properties
@@ -1012,9 +999,18 @@ export const ZoneSidebar = () => {
1012999 </ SidebarMenuItem >
10131000 ) }
10141001 { $displayHidingZones && (
1015- < Command >
1002+ < Command
1003+ key = {
1004+ isStationSearchActive
1005+ ? "station-search-active"
1006+ : "station-search-idle"
1007+ }
1008+ shouldFilter = { isStationSearchActive }
1009+ >
10161010 < CommandInput
10171011 placeholder = "Search for a hiding zone..."
1012+ value = { stationSearch }
1013+ onValueChange = { setStationSearch }
10181014 disabled = { $isLoading }
10191015 />
10201016 < CommandList className = "max-h-full" >
@@ -1108,17 +1104,9 @@ export const ZoneSidebar = () => {
11081104 } }
11091105 disabled = { $isLoading }
11101106 >
1111- { station . properties
1112- . properties [
1113- "name:en"
1114- ] ||
1115- station . properties
1116- . properties . name ||
1117- lngLatToText (
1118- station . properties
1119- . geometry
1120- . coordinates ,
1121- ) }
1107+ { extractStationLabel (
1108+ station . properties ,
1109+ ) }
11221110 < button
11231111 onClick = { async ( ) => {
11241112 if ( ! map ) return ;
0 commit comments