+
Route Optimization
+ {path ? (
+
+ Best route: {path.distance.toFixed(1)} miles
+
+ {(() => {
+ const driver = path.path.from;
+ const waypoints = path.path.waypoints;
+
+ let previousLocation: Location = driver;
+
+ return (
+ <>
+ Driver: {driver.user.name}
+ {waypoints.map((waypoint, index) => {
+ const distance = getDistance(previousLocation, waypoint);
+ previousLocation = waypoint;
+ return (
+
+ Passenger #{index + 1}: {waypoint.user.name} (
+ {distance.toFixed(1)} miles)
+
+ );
+ })}
+
+ Destination: {carpool.event.name} (
+ {getDistance(carpool.event, previousLocation).toFixed(1)}{' '}
+ miles)
+
+ >
+ );
+ })()}
+
+ ) : (
+ 'No valid paths are available.'
+ )}
+
+ );
+}
diff --git a/src/components/Carpool/Members.tsx b/src/components/Carpool/Members.tsx
new file mode 100644
index 0000000..32d4206
--- /dev/null
+++ b/src/components/Carpool/Members.tsx
@@ -0,0 +1,12 @@
+import { ReactNode } from 'react';
+import useIsLocalUserMember from './useIsLocalUserMember';
+
+export default function Members({ children }: { children: ReactNode }) {
+ const isMember = useIsLocalUserMember();
+
+ if (isMember) {
+ return <>{children}>;
+ } else {
+ return null;
+ }
+}
diff --git a/src/components/Carpool/useIsLocalUserMember.ts b/src/components/Carpool/useIsLocalUserMember.ts
new file mode 100644
index 0000000..002af4c
--- /dev/null
+++ b/src/components/Carpool/useIsLocalUserMember.ts
@@ -0,0 +1,18 @@
+import { useContext, useDebugValue, useMemo } from 'react';
+import { useMe } from '../hooks';
+import { CarpoolContext } from './Carpool';
+
+export default function useIsLocalUserMember() {
+ const me = useMe();
+ const { carpool } = useContext(CarpoolContext);
+ const members = carpool.members;
+
+ const isMember = useMemo(
+ () => members.some(({ id }) => id === me?.id),
+ [me?.id, members]
+ );
+
+ useDebugValue(isMember);
+
+ return isMember;
+}
diff --git a/src/components/Event/EventSignups.tsx b/src/components/Event/EventSignups.tsx
index de5e512..0489375 100644
--- a/src/components/Event/EventSignups.tsx
+++ b/src/components/Event/EventSignups.tsx
@@ -93,8 +93,6 @@ export default function EventSignups() {
.map((id) => signups[id]);
}, [signups, carpools]);
- console.log(signups);
-
return (