From 1108970a6aeb98a2f113383c6437dd4d862dae10 Mon Sep 17 00:00:00 2001 From: Logan Hunt Date: Fri, 1 Apr 2022 14:16:35 -0600 Subject: Updates --- client/components/home/_home.jsx | 4 ++-- client/components/map/chat_room_geoman.jsx | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'client/components') diff --git a/client/components/home/_home.jsx b/client/components/home/_home.jsx index 213d43e..a31fd63 100644 --- a/client/components/home/_home.jsx +++ b/client/components/home/_home.jsx @@ -28,8 +28,8 @@ export const Home = () => { }; const joinRoom = async (id, userPosition) => { - const res = await api.get(`/chat_rooms/${id}/joinable?lat=${userPosition.lat}&lng=${userPosition.lng}`); - if (res) { + const joinable = await api.get(`/chat_rooms/${id}/joinable?lat=${userPosition.lat}&lng=${userPosition.lng}`); + if (joinable) { navigate(`/rooms/${id}`); } }; diff --git a/client/components/map/chat_room_geoman.jsx b/client/components/map/chat_room_geoman.jsx index c4655ee..a39b45a 100644 --- a/client/components/map/chat_room_geoman.jsx +++ b/client/components/map/chat_room_geoman.jsx @@ -53,17 +53,12 @@ export const Geoman = ({ user, userPos, joinRoom }) => { let dontRedirect = true; const circleAndMarkerFromChatroom = (chatRoom) => { const circle = new L.Circle(chatRoom.center, chatRoom.radius); - const marker = new L.Marker(chatRoom.center, { pmIgnore: !chatRoom.isEditable, icon }); - circle.setStyle( - chatRoom.isEditable - ? editable - : haversine(userPos, { lat: chatRoom.latitude, lng: chatRoom.longitude }) < chatRoom.radius - ? joinable - : unjoinable, - ); + const marker = new L.Marker(chatRoom.center, { pmIgnore: !chatRoom.editable, icon }); + console.log(chatRoom); + circle.setStyle(chatRoom.editable ? editable : chatRoom.joinable ? joinable : unjoinable); // We only send the id when user is in the radius marker.addEventListener('click', () => { setTimeout(() => { - if (dontRedirect) { + if (!dontRedirect) { joinRoom(chatRoom.id, userPos); return; } @@ -74,7 +69,7 @@ export const Geoman = ({ user, userPos, joinRoom }) => { marker.on('mouseover', (e) => { e.target.openPopup(); }); - if (chatRoom.isEditable) { + if (chatRoom.editable) { [circle, marker].map((x) => { x.on('pm:edit', (e) => { const coords = e.target.getLatLng(); @@ -122,7 +117,6 @@ export const Geoman = ({ user, userPos, joinRoom }) => { circleAndMarkerFromChatroom({ center: [x.latitude, x.longitude], ...x, - isEditable: user && x.userId == user.id, }); }); layersToRemove.map((x) => context.map.removeLayer(x)); -- cgit v1.2.3-70-g09d2