diff --git a/client/common/types/state.ts b/client/common/types/state.ts index 693930d1..ab2bd8eb 100644 --- a/client/common/types/state.ts +++ b/client/common/types/state.ts @@ -3,7 +3,9 @@ import { StrapiStop } from 'transport-common/types/strapi'; export interface State { publicTransport: { - currentVehicle: Pick | null; + currentVehicle: + | (Pick & CurrentVehicleOptions) + | null; currentStop: string | null; currentRoute: Route & Pick & CurrentRouteOptions; stops: StrapiStop[]; @@ -14,10 +16,14 @@ export interface State { }; } +export interface CurrentVehicleSettings { + shouldFilterByRouteDirection?: boolean; +} export type CurrentVehiclePayload = State['publicTransport']['currentVehicle']; export interface CurrentVehicleOptions { shouldClear?: boolean; shouldFlyTo?: boolean; + shouldFilterByRouteDirection?: boolean; } export type CurrentVehiclePayloadWithOptions = CurrentVehiclePayload & CurrentVehicleOptions; export interface CurrentRouteOptions { diff --git a/client/components/Map/SearchBar/SearchBar.helpers.ts b/client/components/Map/SearchBar/SearchBar.helpers.ts index b378ae24..8fedf310 100644 --- a/client/components/Map/SearchBar/SearchBar.helpers.ts +++ b/client/components/Map/SearchBar/SearchBar.helpers.ts @@ -7,10 +7,10 @@ export function searchThroughUnits(units: Unit[], searchText: string) { return uniqBy( units .filter( - (troll) => - troll.lastStation.toLowerCase().includes(searchText) || - troll.firstStation.toLowerCase().includes(searchText) || - troll.num.toLowerCase().includes(searchText), + (unit) => + unit.lastStation.toLowerCase().includes(searchText) || + unit.firstStation.toLowerCase().includes(searchText) || + unit.num.toLowerCase().includes(searchText), ) .sort((a, b) => a.firstStation.localeCompare(b.firstStation, 'ru', { numeric: true })), uniqUnitsIteratee, diff --git a/client/components/Map/SearchBar/StopsResult/StopResult.tsx b/client/components/Map/SearchBar/StopsResult/StopResult.tsx index 62c58acf..56741ac0 100644 --- a/client/components/Map/SearchBar/StopsResult/StopResult.tsx +++ b/client/components/Map/SearchBar/StopsResult/StopResult.tsx @@ -21,31 +21,28 @@ export function MapSearchBarStopResult({ type, stopId, title }: Stop) { const allStops = useSelector((state: State) => state.publicTransport.stops); const currentStop = useSelector((state: State) => state.publicTransport.currentStop); - const setSelectedStop = useCallback( - (stopId: string) => { - const stop = allStops.find((stopFullData) => stopFullData.attributes.stopId === stopId); + const setSelectedStop = useCallback(() => { + const stop = allStops.find((stopFullData) => stopFullData.attributes.stopId === stopId); - if (!stop) { - return; - } + if (!stop) { + return; + } - const { attributes: stopData } = stop; + const { attributes: stopData } = stop; - dispatch( - setCurrentStop({ - currentStop: stopId, - }), - ); + dispatch( + setCurrentStop({ + currentStop: stopId, + }), + ); - map.flyTo(stopData.coords, 15); + map.flyTo(stopData.coords, 15); - sidebarService.open({ - component: , - onClose: () => dispatch(setCurrentStop(null)), - }); - }, - [dispatch, allStops], - ); + sidebarService.open({ + component: , + onClose: () => dispatch(setCurrentStop(null)), + }); + }, [dispatch, allStops, stopId]); const isSelected = useMemo(() => { return currentStop === stopId; @@ -56,7 +53,7 @@ export function MapSearchBarStopResult({ type, stopId, title }: Stop) { className={cn(styles.MapSearchBarStopResult__wrapper, { [styles.MapSearchBarStopResult__wrapper_selected]: isSelected, })} - onClick={() => setSelectedStop(stopId)} + onClick={() => setSelectedStop()} >

{title}

diff --git a/client/components/Map/SearchBar/UnitResult/UnitResult.tsx b/client/components/Map/SearchBar/UnitResult/UnitResult.tsx index 91f93adf..33c4af2e 100644 --- a/client/components/Map/SearchBar/UnitResult/UnitResult.tsx +++ b/client/components/Map/SearchBar/UnitResult/UnitResult.tsx @@ -18,22 +18,20 @@ export function MapSearchBarUnitResult(props: Unit) { const dispatch = useDispatch(); const currentVehicle = useSelector((state: State) => state.publicTransport.currentVehicle); - const setSelectedVehicle = useCallback( - (unit: Unit) => { - dispatch( - setCurrentVehicle({ - num: unit.num, - routeDirection: unit.routeDirection, - type: unit.type, - routeId: unit.routeId, - shouldFlyTo: true, - }), - ); - - sidebarService.close(); - }, - [dispatch], - ); + const setSelectedVehicle = useCallback(() => { + dispatch( + setCurrentVehicle({ + num: props.num, + routeDirection: props.routeDirection, + type: props.type, + routeId: props.routeId, + shouldFlyTo: true, + shouldFilterByRouteDirection: true, + }), + ); + + sidebarService.close(); + }, [dispatch, props.num, props.routeDirection, props.type, props.routeId]); const isSelected = useMemo(() => { return ( @@ -47,7 +45,7 @@ export function MapSearchBarUnitResult(props: Unit) { className={cn(styles.MapSearchBarUnitResult__wrapper, { [styles.MapSearchBarUnitResult__selected]: isSelected, })} - onClick={() => setSelectedVehicle(props)} + onClick={() => setSelectedVehicle()} >

) => { - const { currentVehicle, currentRoute, shouldClear } = action.payload; + const { currentVehicle, currentRoute, shouldClear, shouldFilterByRouteDirection } = + action.payload; state.currentVehicle = currentVehicle; + state.currentVehicle.shouldFilterByRouteDirection = shouldFilterByRouteDirection; state.currentRoute = currentRoute; if (!currentRoute) {