From ee14d60db73424f88ae31a88962aac281829990b Mon Sep 17 00:00:00 2001 From: Adrien Date: Sat, 15 Apr 2023 18:24:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Old=20stops=20still=20displayed?= =?UTF-8?q?=20on=20map=20once=20the=20stop=20search=20narrowed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/stopsSearchMenu.tsx | 127 +++++++++++++++++-------------- 1 file changed, 68 insertions(+), 59 deletions(-) diff --git a/frontend/src/stopsSearchMenu.tsx b/frontend/src/stopsSearchMenu.tsx index 7b8222a..5456a37 100644 --- a/frontend/src/stopsSearchMenu.tsx +++ b/frontend/src/stopsSearchMenu.tsx @@ -407,6 +407,52 @@ const StopsPanels: ParentComponent<{ maxStopsPerPanel: number }> = (props) => { ); } + +const StopPopup: ParentComponent<{ stop: Stop, show: boolean }> = (props) => { + const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext); + if (businessDataStore === undefined) + return
; + + const { getLine, getStopDestinations } = businessDataStore; + + let popupDiv: HTMLDivElement | undefined = undefined; + + const getDestinations = async (stop: Stop): Promise<{ lineId: string, destinations: string[] }[]> => { + let ret = []; + + if (stop !== undefined) { + const result = await getStopDestinations(stop.id); + for (const [lineId, destinations] of Object.entries(result)) { + const line = await getLine(lineId); + const linePicto = renderLinePicto(line); + ret.push({ lineId: linePicto, destinations: destinations }); + } + } + + return ret; + } + const [destinations] = createResource(() => props.stop, getDestinations); + + return ( +
+
{props.stop?.name}
+
+ + {(dst) => { + return
+ {dst.lineId} +
+ +
+
; + }} +
+
+
+ ); +} + + // TODO: Use boolean to set MapStop selected const MapStop: VoidComponent<{ stop: Stop, selected: Stop | undefined }> = (props) => { const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext); @@ -482,52 +528,7 @@ const MapStop: VoidComponent<{ stop: Stop, selected: Stop | undefined }> = (prop setMapFeature(props.stop.id, feature); }); - {stop => } -} - - -const StopPopup: ParentComponent<{ stop: Stop, show: boolean }> = (props) => { - const businessDataStore: BusinessDataStore | undefined = useContext(BusinessDataContext); - if (businessDataStore === undefined) - return
; - - const { getLine, getStopDestinations } = businessDataStore; - - let popupDiv: HTMLDivElement | undefined = undefined; - - const getDestinations = async (stop: Stop): Promise<{ lineId: string, destinations: string[] }[]> => { - let ret = []; - - if (stop !== undefined) { - const result = await getStopDestinations(stop.id); - for (const [lineId, destinations] of Object.entries(result)) { - const line = await getLine(lineId); - const linePicto = renderLinePicto(line); - ret.push({ lineId: linePicto, destinations: destinations }); - } - } - - return ret; - } - const [destinations] = createResource(() => props.stop, getDestinations); - - return ( -
-
{props.stop?.name}
-
- - {(dst) => { - return
- {dst.lineId} -
- -
-
; - }} -
-
-
- ); + return {stop => }; } @@ -601,9 +602,7 @@ const Map: ParentComponent<{}> = () => { const onClickedFeature = async (feature: OlFeatureLike): Promise => { const stopId: number = feature.getId(); - const stop = getStop(stopId); - // TODO: Handle StopArea (use center given by the backend) if (stop?.lat !== undefined && stop?.lon !== undefined) { setSelectedMapStop(stop); @@ -613,7 +612,8 @@ const Map: ParentComponent<{}> = () => { duration: 1000 }, // Display the popup once the animation finished - () => setPopupDisplayed(true)); + () => setPopupDisplayed(true) + ); } } @@ -621,20 +621,29 @@ const Map: ParentComponent<{}> = () => { // Filling the map with stops shape createEffect(() => { - const features = getAllMapFeatures(); + const stops = getFoundStops(); + const foundStopIds = new Set(); + for (const foundStop of stops) { + foundStopIds.add(foundStop.id); + foundStop.stops.forEach(s => foundStopIds.add(s.id)); + } - for (const [stopId, feature] of Object.entries(features)) { - if (!(stopId in displayedFeatures)) { - const stop = getStop(parseInt(stopId)); - stopVectorSource.addFeature(feature); - displayedFeatures[stopId] = feature; + for (const [stopIdStr, feature] of Object.entries(displayedFeatures)) { + const stopId = parseInt(stopIdStr); + if (!foundStopIds.has(stopId)) { + console.log(`Remove feature for ${stopId}`); + stopVectorSource.removeFeature(feature); + delete displayedFeatures[stopId]; } } - for (const [stopId, feature] of Object.entries(displayedFeatures)) { - if (!(stopId in features)) { - stopVectorSource.removeFeature(feature); - delete displayedFeatures[stopId]; + const features = getAllMapFeatures(); + for (const [stopIdStr, feature] of Object.entries(features)) { + const stopId = parseInt(stopIdStr); + if (foundStopIds.has(stopId) && !(stopId in displayedFeatures)) { + console.log(`Add feature for ${stopId}`); + stopVectorSource.addFeature(feature); + displayedFeatures[stopId] = feature; } }