Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight buses on route #101

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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