Skip to content

Commit

Permalink
fix direction selection
Browse files Browse the repository at this point in the history
  • Loading branch information
bwees committed Mar 14, 2024
1 parent ff98f7e commit 7437e3f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
11 changes: 7 additions & 4 deletions app/components/map/MapView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ const Map: React.FC = () => {


function selectRoute(route: IMapRoute, directionKey: string) {

if (selectedRouteDirection !== directionKey) {
setSelectedDirection(directionKey);
return;
}

if (selectedRoute?.key === route.key) return;
console.log(directionKey)

setSelectedRoute(route);
setDrawnRoutes([route]);
presentSheet("routeDetails");

if (selectedRouteDirection !== directionKey)
setSelectedDirection(route.key);

}

Expand Down
10 changes: 2 additions & 8 deletions app/components/map/markers/BusMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { Marker } from 'react-native-maps';
import BusMapIcon from '../BusMapIcon';
import BusCallout from '../BusCallout';
import { IVehicle } from 'utils/interfaces';

import useAppStore from '../../../data/app_state';
import { getLighterColor } from 'app/utils';

interface Props {
bus: IVehicle,
Expand All @@ -18,10 +16,6 @@ const BusMarker: React.FC<Props> = ({ bus, tintColor, routeName }) => {
const selectedRouteDirection = useAppStore(state => state.selectedRouteDirection);
const setSelectedDirection = useAppStore(state => state.setSelectedRouteDirection);

const busColor = selectedRouteDirection === bus.directionKey ? tintColor : tintColor+"70";
const borderColor = selectedRouteDirection === bus.directionKey ? getLighterColor(tintColor) : undefined;
const iconColor = selectedRouteDirection === bus.directionKey ? "white" : "#ffffffcc";

//if direction is not selected and route is inactive, then call setSelectedDirection w/ parameter bus.directionKey
const busDefaultDirection = () => {
if (selectedRouteDirection !== bus.directionKey)
Expand All @@ -43,7 +37,7 @@ const BusMarker: React.FC<Props> = ({ bus, tintColor, routeName }) => {
>
{/* Bus Icon on Map*/}
<BusMapIcon
tintColor={busColor}
tintColor={tintColor}
heading={bus.location.heading}
active={selectedRouteDirection === bus.directionKey}
/>
Expand All @@ -52,7 +46,7 @@ const BusMarker: React.FC<Props> = ({ bus, tintColor, routeName }) => {
directionName={bus.directionName}
fullPercentage={Math.round((bus.passengersOnboard / bus.passengerCapacity)*100)}
amenities={bus.amenities}
tintColor={busColor ?? "#500000"}
tintColor={tintColor}
routeName={routeName}
busId={bus.name}
/>
Expand Down
13 changes: 13 additions & 0 deletions app/components/sheets/RouteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const RouteDetails: React.FC<SheetProps> = ({ sheetRef }) => {
const setSelectedRouteDirection = useAppStore(state => state.setSelectedRouteDirection);
const setSelectedStop = useAppStore(state => state.setSelectedStop);
const setPoppedUpStopCallout = useAppStore(state => state.setPoppedUpStopCallout);
const selectedRouteDirection = useAppStore(state => state.selectedRouteDirection);
const theme = useAppStore(state => state.theme);

const { data: stopEstimates } = useStopEstimate(
Expand Down Expand Up @@ -87,6 +88,18 @@ const RouteDetails: React.FC<SheetProps> = ({ sheetRef }) => {

}, [currentSelectedRoute])


// update the segmented control when the selected direction changes
useEffect(() => {
if (!selectedRoute) return;

const directionIndex = selectedRoute.directionList.findIndex(direction => direction.direction.key === selectedRouteDirection);

if (directionIndex === -1) return;

setSelectedDirectionIndex(directionIndex);
}, [selectedRouteDirection]);

useEffect(() => {
return () => setSelectedRouteDirection(null);
}, []);
Expand Down

0 comments on commit 7437e3f

Please sign in to comment.