MCPcopy Create free account
hub / github.com/codealong-dev/ride-sharing / RiderMap

Function RiderMap

web/src/components/RiderMap.tsx:35–240  ·  view source on GitHub ↗
({ onRouteSelected }: RiderMapProps)

Source from the content-addressed store, hash-verified

33}
34
35export default function RiderMap({ onRouteSelected }: RiderMapProps) {
36 const [trip, setTrip] = useState<TripPreview | null>(null)
37 const [selectedCarPackage] = useState<RouteFare | null>(null)
38 const [destination, setDestination] = useState<[number, number] | null>(null)
39 const mapRef = useRef<L.Map>(null)
40 const userID = useMemo(() => crypto.randomUUID(), [])
41 const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null);
42
43 const location = {
44 latitude: 37.7749,
45 longitude: -122.4194,
46 };
47
48 const {
49 drivers,
50 error,
51 tripStatus,
52 assignedDriver,
53 paymentSession,
54 resetTripStatus
55 } = useRiderStreamConnection(location, userID);
56
57 console.log(tripStatus)
58
59 const handleMapClick = async (e: L.LeafletMouseEvent) => {
60 if (trip?.tripID) {
61 return
62 }
63
64 if (debounceTimeoutRef.current) {
65 clearTimeout(debounceTimeoutRef.current);
66 }
67
68 debounceTimeoutRef.current = setTimeout(async () => {
69 setDestination([e.latlng.lat, e.latlng.lng])
70
71 const data = await requestRidePreview({
72 pickup: [location.latitude, location.longitude],
73 destination: [e.latlng.lat, e.latlng.lng],
74 })
75 console.log(data)
76
77 const parsedRoute = data.route.geometry[0].coordinates
78 .map((coord) => [coord.longitude, coord.latitude] as [number, number])
79
80 setTrip({
81 tripID: "",
82 route: parsedRoute,
83 rideFares: data.rideFares,
84 distance: data.route.distance,
85 duration: data.route.duration,
86 })
87
88 // Call onRouteSelected with the route distance
89 onRouteSelected?.(data.route.distance)
90 }, 500);
91 }
92

Callers

nothing calls this directly

Calls 2

useRiderStreamConnectionFunction · 0.90
getGeohashBoundsFunction · 0.90

Tested by

no test coverage detected