mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-04-06 01:25:33 +00:00
set distance rule
This commit is contained in:
parent
ebfee13fd5
commit
d142c474ed
@ -60,16 +60,39 @@ export const LocateControl = (): JSX.Element => {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
// Check if user logged in while location is active and found
|
||||||
|
useEffect(() => {
|
||||||
|
if (
|
||||||
|
myProfile.myProfile &&
|
||||||
|
foundLocation &&
|
||||||
|
active &&
|
||||||
|
!hasUpdatedPosition &&
|
||||||
|
!showLocationModal
|
||||||
|
) {
|
||||||
|
if (myProfile.myProfile.position) {
|
||||||
|
const currentPos = myProfile.myProfile.position.coordinates
|
||||||
|
const distance = foundLocation.distanceTo([currentPos[1], currentPos[0]])
|
||||||
|
|
||||||
|
if (distance >= 100) {
|
||||||
|
setShowLocationModal(true)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Show modal if user has no current position
|
||||||
|
setShowLocationModal(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [myProfile.myProfile, foundLocation, active, hasUpdatedPosition, showLocationModal])
|
||||||
|
|
||||||
useMapEvents({
|
useMapEvents({
|
||||||
locationfound: (e) => {
|
locationfound: (e) => {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
setActive(true)
|
setActive(true)
|
||||||
setFoundLocation(e.latlng)
|
setFoundLocation(e.latlng)
|
||||||
|
|
||||||
// Only show modal if user is at least 100m away from their current profile position
|
// Only show modal if user is logged in and at least 100m away from their current profile position
|
||||||
// and hasn't just updated their position
|
// and hasn't just updated their position
|
||||||
if (!hasUpdatedPosition) {
|
if (!hasUpdatedPosition && myProfile.myProfile) {
|
||||||
if (myProfile.myProfile?.position) {
|
if (myProfile.myProfile.position) {
|
||||||
const currentPos = myProfile.myProfile.position.coordinates
|
const currentPos = myProfile.myProfile.position.coordinates
|
||||||
const distance = e.latlng.distanceTo([currentPos[1], currentPos[0]])
|
const distance = e.latlng.distanceTo([currentPos[1], currentPos[0]])
|
||||||
|
|
||||||
@ -199,11 +222,12 @@ export const LocateControl = (): JSX.Element => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DialogModal
|
<DialogModal
|
||||||
title='Location found!'
|
title='Location found'
|
||||||
isOpened={showLocationModal}
|
isOpened={showLocationModal}
|
||||||
onClose={() => setShowLocationModal(false)}
|
onClose={() => setShowLocationModal(false)}
|
||||||
showCloseButton={true}
|
showCloseButton={true}
|
||||||
closeOnClickOutside={true}
|
closeOnClickOutside={true}
|
||||||
|
className='tw:bottom-1/3 tw:mx-4 tw:sm:mx-auto'
|
||||||
>
|
>
|
||||||
<div className='tw:text-center'>
|
<div className='tw:text-center'>
|
||||||
<p className='tw:mb-4'>Do you like to place your profile at your current location?</p>
|
<p className='tw:mb-4'>Do you like to place your profile at your current location?</p>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user