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

Function handleMapClick

web/src/components/RiderMap.tsx:59–91  ·  view source on GitHub ↗
(e: L.LeafletMouseEvent)

Source from the content-addressed store, hash-verified

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
93 const requestRidePreview = async (props: RequestRideProps): Promise<HTTPTripPreviewResponse> => {
94 const { pickup, destination } = props

Callers

nothing calls this directly

Calls 1

requestRidePreviewFunction · 0.85

Tested by

no test coverage detected