Skip to content

Commit

Permalink
Merge pull request #979 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 8917cd7 + 7128671 commit f68b9fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,18 @@ function DegreeInput({ label, value, onChange, disabled }: DegreeInputInterface)
);


useEffect(() => {
if (!isNaN(currValue)) {
onChange(currValue)
}
}, [currValue]);

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

return <div
className="flex sm:flex-col flex-row gap-3 items-center justify-between w-[541px] sm:w-full"
Expand Down Expand Up @@ -146,39 +151,18 @@ export default function DegreeInputs(
}
}, [latitude, longitude,globalVariables.checkIsLand]);


const [localLatitude, setLocalLatitude] = useState(latitude);
const [localLongitude, setLocalLongitude] = useState(longitude);

// Update local latitude state when latitude prop changes
useEffect(() => {
setLocalLatitude(latitude);
}, [latitude]);

// Update local longitude state when longitude prop changes
useEffect(() => {
setLocalLongitude(longitude);
}, [longitude]);


return <>
<DegreeInput
label='Latitude'
value={localLatitude}
onChange={(value) => {
setLocalLatitude(value); // Update local state
setLatitude(value); // Update parent state
}}
disabled={disabled}
/>
<DegreeInput
label='Longitude'
value={localLongitude}
onChange={(value) => {
setLocalLongitude(value);
setLongitude(value);
}}
disabled={disabled}
/>
label='Latitude'
value={latitude}
onChange={setLatitude}
disabled={disabled}
/>
<DegreeInput
label='Longitude'
value={longitude}
onChange={setLongitude}
disabled={disabled}
/>
</>
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ export default function CoordinatesInputForm(
{selectOnMap ?
(
<DegreeInputs
latitude={selectedCoordinates.latitude.toFixed(6)}
longitude={selectedCoordinates.longitude.toFixed(6)}
latitude={selectedCoordinates.latitude !== null ? selectedCoordinates.latitude.toFixed(6) : 0.000000}
longitude={selectedCoordinates.longitude !== null ? selectedCoordinates.longitude.toFixed(6) : 0.000000}
disabled={disabled}
setLatitude={setLatitude}
setLongitude={setLongitude}
/>) :
/>
) :
type === 'Degree' ?
<DegreeInputs
latitude={values.latitude}
Expand Down

0 comments on commit f68b9fa

Please sign in to comment.