import { useMe } from '../hooks';
import latlongdist, { R_miles } from '../latlongdist';
import usePlace from '../usePlace';
import { IEvent, IEventSignup } from './Event';
import PersonAddIcon from '@material-ui/icons/PersonAdd';
export default function EventSignups({
event,
signups,
myPlaceId,
}: {
event: IEvent;
signups: IEventSignup[];
myPlaceId: string | null;
}) {
const placeDetails = usePlace(myPlaceId);
const locationLongitude = event.latitude;
const locationLatitude = event.longitude;
const me = useMe();
return (
People
{signups.map(({ latitude, longitude, user }) => {
if (user.id === me?.id) {
return null;
}
let extraDistance = null;
if (placeDetails != null) {
const myLatitude = placeDetails.latitude;
const myLongitude = placeDetails.longitude;
const meToThem = latlongdist(
latitude,
longitude,
locationLongitude,
locationLatitude,
R_miles
);
const themToLocation = latlongdist(
latitude,
longitude,
myLatitude,
myLongitude,
R_miles
);
const totalWithThem = meToThem + themToLocation;
const totalWithoutThem = latlongdist(
locationLongitude,
locationLatitude,
myLatitude,
myLongitude,
R_miles
);
extraDistance = totalWithThem - totalWithoutThem;
}
return (
{user.name}
{extraDistance ? `: +${extraDistance.toFixed(1)} miles` : ''}
);
})}
);
}