Skip to content

Commit

Permalink
fix coordinates overlay edit
Browse files Browse the repository at this point in the history
  • Loading branch information
j8seangel committed Aug 5, 2024
1 parent 93d37a4 commit a511aff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
10 changes: 7 additions & 3 deletions apps/fishing-map/features/map/Map.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef } from 'react'
import { Fragment, useCallback, useEffect, useRef } from 'react'
import { useSelector } from 'react-redux'
import { DeckGL, DeckGLRef } from '@deck.gl/react'
import dynamic from 'next/dynamic'
Expand Down Expand Up @@ -135,11 +135,15 @@ const MapWrapper = () => {
>
<MapAnnotations />
</DeckGL>
{isMapDrawing && <DrawDialog />}
{isMapDrawing && (
<Fragment>
<CoordinateEditOverlay />
<DrawDialog />
</Fragment>
)}
<MapPopups />
<ErrorNotificationDialog />
<MapAnnotationsDialog />
<CoordinateEditOverlay />
<MapControls mapLoading={mapLoading || isReportAreaLoading} />
{isWorkspaceLocation && !isReportLocation && (
<Hint id="fishingEffortHeatmap" className={styles.helpHintLeft} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next'
import { useCallback, useState } from 'react'
import { useCallback, useEffect, useState } from 'react'
import { useSelector } from 'react-redux'
import { Feature, Polygon } from 'geojson'
import { Button, IconButton, InputText } from '@globalfishingwatch/ui-components'
Expand All @@ -25,6 +25,13 @@ export const CoordinateEditOverlay = () => {
const editingPointLongitude =
newPointLongitude !== null ? Number(newPointLongitude) : Number(currentPointCoordinates?.[0])

useEffect(() => {
if (!currentPointCoordinates?.length) {
setNewPointLatitude(null)
setNewPointLongitude(null)
}
}, [currentPointCoordinates])

const allowDeletePoint =
drawingMode === 'polygons'
? drawData &&
Expand Down Expand Up @@ -65,12 +72,6 @@ export const CoordinateEditOverlay = () => {
[drawLayer, editingPointLatitude]
)

const onDeletePoint = useCallback(() => {
if (allowDeletePoint) {
drawLayer?.deleteSelectedPosition()
}
}, [allowDeletePoint, drawLayer])

const resetEditingPoint = useCallback(() => {
// As this is triggered with clickOutside we need to wait to reset
// in case before the deleteSelectedPosition is called
Expand All @@ -81,6 +82,13 @@ export const CoordinateEditOverlay = () => {
}, 1)
}, [drawLayer])

const onDeletePoint = useCallback(() => {
if (allowDeletePoint) {
drawLayer?.deleteSelectedPosition()
resetEditingPoint()
}
}, [allowDeletePoint, drawLayer, resetEditingPoint])

const onConfirm = useCallback(() => {
drawLayer?.setCurrentPointCoordinates([editingPointLongitude, editingPointLatitude])
resetEditingPoint()
Expand Down

0 comments on commit a511aff

Please sign in to comment.