Skip to content

Commit

Permalink
Highlight buses on route
Browse files Browse the repository at this point in the history
  • Loading branch information
SumitNalavade committed Jan 19, 2024
1 parent 6847ada commit 8c654e1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/components/map/markers/BusMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import BusCallout from '../BusCallout';
import { getLighterColor } from '../../../utils';
import { IVehicle } from 'utils/interfaces';

import useAppStore from '../../../stores/useAppStore';

interface Props {
bus: IVehicle,
tintColor: string,
Expand All @@ -13,6 +15,11 @@ interface Props {

// Bus Marker with icon and callout
const BusMarker: React.FC<Props> = ({ bus, tintColor, routeName }) => {
const selectedRouteDestination = useAppStore(state => state.selectedRouteDestination);

const busColor = selectedRouteDestination === bus.directionName ? tintColor : '#808080';
const borderColor = getLighterColor(busColor);

return (
<Marker
key={bus.key}
Expand All @@ -22,7 +29,7 @@ const BusMarker: React.FC<Props> = ({ bus, tintColor, routeName }) => {
pointerEvents="auto"
>
{/* Bus Icon on Map*/}
<BusMapIcon color={tintColor} borderColor={getLighterColor(tintColor)} heading={bus.location.heading} />
<BusMapIcon color={busColor} borderColor={borderColor} heading={bus.location.heading} />
<BusCallout directionName={bus.directionName} fullPercentage={Math.round(bus.passengersOnboard / bus.passengerCapacity)} amenities={bus.amenities} tintColor={tintColor ?? "#500000"} routeName={routeName} />
</Marker>
);
Expand Down
10 changes: 10 additions & 0 deletions app/components/sheets/RouteDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const RouteDetails: React.FC<SheetProps> = ({ sheetRef }) => {
const currentSelectedRoute = useAppStore((state) => state.selectedRoute);
const clearSelectedRoute = useAppStore((state) => state.clearSelectedRoute);

const setSelectedRouteDestination = useAppStore(state => state.setSelectedRouteDestination);

const stopEstimates = useAppStore((state) => state.stopEstimates);
const setStopEstimates = useAppStore(state => state.setStopEstimates);

Expand Down Expand Up @@ -71,9 +73,15 @@ const RouteDetails: React.FC<SheetProps> = ({ sheetRef }) => {
if (!currentSelectedRoute) return;
setSelectedRoute(currentSelectedRoute);

setSelectedRouteDestination(currentSelectedRoute.directionList[0]?.destination ?? null);

loadStopEstimates();
}, [currentSelectedRoute])

useEffect(() => {
return () => setSelectedRouteDestination(null);
}, []);

async function loadStopEstimates() {
if (!currentSelectedRoute || !authToken) return;
let allStops: IStop[] = [];
Expand Down Expand Up @@ -115,6 +123,8 @@ const RouteDetails: React.FC<SheetProps> = ({ sheetRef }) => {

const handleSetSelectedDirection = (evt: NativeSyntheticEvent<NativeSegmentedControlIOSChangeEvent>) => {
setSelectedDirectionIndex(evt.nativeEvent.selectedSegmentIndex);

setSelectedRouteDestination(selectedRoute?.directionList[evt.nativeEvent.selectedSegmentIndex]?.destination ?? null);
}

const snapPoints = ['25%', '45%', '85%'];
Expand Down
6 changes: 6 additions & 0 deletions app/stores/useAppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ interface AppState {
setSelectedRoute: (selectedRoute: IMapRoute) => void,
clearSelectedRoute: () => void,

selectedRouteDestination: string | null,
setSelectedRouteDestination: (selectedRouteDirection: string | null) => void,

selectedRouteCategory: "favorites" | "all",
setSelectedRouteCategory: (selectedRouteCategory: "favorites" | "all") => void

Expand Down Expand Up @@ -82,6 +85,9 @@ const useAppStore = create<AppState>()((set) => ({
return { selectedRoute: null };
}),

selectedRouteDestination: null,
setSelectedRouteDestination: (selectedRouteDirection) => set(() => ({ selectedRouteDestination: selectedRouteDirection })),

selectedRouteCategory: 'all',
setSelectedRouteCategory: (selectedRouteCategory) => set(() => ({ selectedRouteCategory })),

Expand Down

0 comments on commit 8c654e1

Please sign in to comment.