Set lon/lat on data fetch
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
toqvist 2024-02-21 16:36:39 +01:00
parent 26eb75646b
commit f152476d8f

View File

@ -1,15 +1,13 @@
import * as React from 'react'; import * as React from 'react';
import { useField, Label, TextInput } from 'payload/components/forms'; import { useField } from 'payload/components/forms';
export const GeoPicker: React.FC<{ path: string }> = ({ path }) => { export const GeoPicker: React.FC<{ path: string }> = ({ path }) => {
const { value, setValue } = useField<string>({ path }); const { value, setValue } = useField<string>({ path });
const [latitude, setLatitude] = React.useState(""); const [longitude, setLongitude] = React.useState(value[0]);
const [longitude, setLongitude] = React.useState(""); const [latitude, setLatitude] = React.useState(value[1]);
const handleCityEnter = async (e) => { const handleCityEnter = async (e) => {
console.log("Handle key")
if (e.key === 'Enter') { if (e.key === 'Enter') {
console.log("Enter: " + e.target.value)
try { try {
const response = await fetch( const response = await fetch(
`https://nominatim.openstreetmap.org/search?format=json&q=${e.target.value}` `https://nominatim.openstreetmap.org/search?format=json&q=${e.target.value}`
@ -20,7 +18,6 @@ export const GeoPicker: React.FC<{ path: string }> = ({ path }) => {
setLatitude(lat); setLatitude(lat);
setLongitude(lon); setLongitude(lon);
setValue([lon, lat]); setValue([lon, lat]);
console.log(data)
} }
} catch (error) { } catch (error) {
console.error('Error fetching geolocation:', error); console.error('Error fetching geolocation:', error);