From f3a66f6b14ffe9106d865a54bcbbc583436501c7 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Sun, 19 Mar 2023 02:27:11 -0400 Subject: [PATCH] small fixes - run server fn at dragend - double check cells that contain the circle entirely - promise.allSettled --- client/src/pages/map/markers/Point.tsx | 5 ++++- client/src/services/fetches.ts | 8 ++------ server/algorithms/src/s2.rs | 1 + 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client/src/pages/map/markers/Point.tsx b/client/src/pages/map/markers/Point.tsx index ebcecd1a..67a5d567 100644 --- a/client/src/pages/map/markers/Point.tsx +++ b/client/src/pages/map/markers/Point.tsx @@ -52,13 +52,16 @@ export function KojiPoint({ } }) circle.removeEventListener('pm:dragend') - circle.on('pm:dragend', function dragend({ layer }) { + circle.on('pm:dragend', async function dragend({ layer }) { if (layer instanceof L.Circle) { const { lat: newLat, lng: newLon } = circle.getLatLng() useShapes.getState().setters.update(type, id, { ...useShapes.getState().Point[id], geometry: { type: 'Point', coordinates: [newLon, newLat] }, }) + useShapes.setState({ + s2cellCoverage: await s2Coverage(id, newLat, newLon), + }) } }) if (usePersist.getState().setActiveMode === 'hover') { diff --git a/client/src/services/fetches.ts b/client/src/services/fetches.ts index a9e2d5b0..e18b73cd 100644 --- a/client/src/services/fetches.ts +++ b/client/src/services/fetches.ts @@ -425,15 +425,13 @@ export async function s2Coverage(id: Feature['id'], lat: number, lon: number) { ([, v]) => v !== id.toString(), ), ) - const aborts = s2cells.map(() => new AbortController()) - await Promise.all( - s2cells.map(async (level, i) => + await Promise.allSettled( + s2cells.map(async (level) => fetchWrapper>('/api/v1/s2/circle-coverage', { method: 'POST', headers: { 'Content-Type': 'application/json', }, - signal: aborts[i].signal, body: JSON.stringify({ lat, lon, radius, level }), }).then((res) => { if (res) { @@ -444,8 +442,6 @@ export async function s2Coverage(id: Feature['id'], lat: number, lon: number) { }), ), ) - aborts.forEach((a) => a.abort()) - return s2cellCoverage } return {} diff --git a/server/algorithms/src/s2.rs b/server/algorithms/src/s2.rs index 0490a823..945886e0 100644 --- a/server/algorithms/src/s2.rs +++ b/server/algorithms/src/s2.rs @@ -93,6 +93,7 @@ fn check_neighbors( ) { let center = s2::latlng::LatLng::from_degrees(lat, lon); let center_cell = CellID::from(center).parent(level as u64); + covered.lock().unwrap().insert(center_cell.0.to_string()); let mut next_neighbors: Vec<(f64, f64)> = Vec::new(); let current_neighbors = center_cell.edge_neighbors();