Skip to content

Commit

Permalink
Merge pull request #977 from kartoza/use-local-variables-for-long-and…
Browse files Browse the repository at this point in the history
…-lat

Use local variables for long and lat
  • Loading branch information
tinashechiraya authored Apr 12, 2024
2 parents 42b3c00 + 352093f commit a477d8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ function DegreeInput({ label, value, onChange, disabled }: DegreeInputInterface)


useEffect(() => {
if (!isNaN(value)) {
if (!isNaN(value) && disabled) {
console.log('assigning value ',value)
onChange(value)
setCurrValue(value)
}
setCurrValue(value)
}, [value,currValue]);

return <div
Expand Down Expand Up @@ -80,6 +80,7 @@ function DegreeInput({ label, value, onChange, disabled }: DegreeInputInterface)
marginRight: '-2%'
}}
onChange={(evt) => {
console.log('on change in field')
let value = evt.target.value
if (!isNaN(parseFloat(evt.target.value))) {
if (value > max) {
Expand Down Expand Up @@ -159,12 +160,6 @@ export default function DegreeInputs(
setLocalLongitude(longitude);
}, [longitude]);

// useEffect to log changes in latitude, longitude, and disabled props
// useEffect(() => {
// console.log('Latitude:', localLatitude);
// console.log('Longitude:', localLongitude);
// console.log('Disabled:', disabled);
// }, [localLatitude, localLongitude, disabled]);

return <>
<DegreeInput
Expand All @@ -180,8 +175,8 @@ export default function DegreeInputs(
label='Longitude'
value={localLongitude}
onChange={(value) => {
setLocalLongitude(value); // Update local state
setLongitude(value); // Update parent state
setLocalLongitude(value);
setLongitude(value);
}}
disabled={disabled}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function CoordinatesInputForm(
}

useEffect(() => {
console.log('debug coordinates: ', selectedCoordinates)
// console.log('debug coordinates: ', selectedCoordinates)
setLatitude(selectedCoordinates.latitude)
setLongitude(selectedCoordinates.longitude)
}, [selectedCoordinates]);
Expand All @@ -64,7 +64,6 @@ export default function CoordinatesInputForm(
<RadioGroup
value={`Degree`}
onChange={(evt) => {
console.log('evt target value: ',evt.target.value); // testing
setType(evt.target.value);
}}
row
Expand All @@ -74,19 +73,12 @@ export default function CoordinatesInputForm(
)}
{selectOnMap ?
(

<DegreeInputs
latitude={selectedCoordinates.latitude.toFixed(6)}
longitude={selectedCoordinates.longitude.toFixed(6)}
disabled={disabled}
setLatitude={() => {
setFieldValue('latitude', selectedCoordinates.latitude);
handleMapClick(Number(selectedCoordinates.latitude), Number(values.longitude))
}}
setLongitude={() => {
setFieldValue('longitude', selectedCoordinates.longitude);
handleMapClick(Number(values.latitude), Number(selectedCoordinates.longitude))
}}
setLatitude={() => {setLatitude}
setLongitude={() => {setLongitude}
/>) :
type === 'Degree' ?
<DegreeInputs
Expand Down

0 comments on commit a477d8c

Please sign in to comment.