Added TypeScript for frontend
Added type definitions for components, functions, data Added guards for network responses fixes #8
This commit is contained in:
35
front/src/components/LocationMarker.tsx
Normal file
35
front/src/components/LocationMarker.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
import { Marker, Popup, useMapEvents } from "react-leaflet"
|
||||
import { LatLng } from 'leaflet'
|
||||
import { SetState } from "../utils/types"
|
||||
|
||||
type LocationMarkerProps = {
|
||||
address: string,
|
||||
position: LatLng,
|
||||
setPosition: SetState<LatLng>
|
||||
}
|
||||
|
||||
const LocationMarker = ({ address, position, setPosition }: LocationMarkerProps) => {
|
||||
|
||||
const map = useMapEvents({
|
||||
dragend: () => {
|
||||
setPosition(map.getCenter())
|
||||
},
|
||||
zoomend: () => {
|
||||
setPosition(map.getCenter())
|
||||
},
|
||||
resize: () => {
|
||||
setPosition(map.getCenter())
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<Marker position={position}>
|
||||
<Popup>
|
||||
{address}
|
||||
{position.lat.toFixed(4)}, {position.lng.toFixed(4)}
|
||||
</Popup>
|
||||
</Marker>
|
||||
)
|
||||
}
|
||||
|
||||
export default LocationMarker
|
Reference in New Issue
Block a user