diff --git a/src/components/LockedContent.tsx b/src/components/LockedContent.tsx index 258d50f..7d158ff 100644 --- a/src/components/LockedContent.tsx +++ b/src/components/LockedContent.tsx @@ -1,6 +1,5 @@ import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" -import distance from "@/utils/distance" import { LockClosedIcon, LockOpen1Icon } from "@radix-ui/react-icons" import { useEffect, useState } from "react" @@ -32,8 +31,6 @@ const LocationButton = ({ lng: targetCoordinates[1] } - console.log(targetPos) - const startWatchingLocation = () => { setHasPermission(true) if (!watchId) { @@ -44,18 +41,24 @@ const LocationButton = ({ lng: position.coords.longitude } - const totalDistanceInKM = distance(pos.lat, pos.lng, targetPos.lat, targetPos.lng) + // @ts-expect-error 3rd party script + const targetLatLng = L.latLng(targetPos) - if (totalDistanceInKM > 1) { - setDistanceRemain(`${totalDistanceInKM.toFixed(0)} KM`) - } else if (totalDistanceInKM < 1 && totalDistanceInKM * 1000 > 50) { - setDistanceRemain(`${(totalDistanceInKM * 1000).toFixed(0)} Metre`) + // @ts-expect-error 3rd party script + const currentLatLng = L.latLng(pos) + + const betweenMeters = currentLatLng.distanceTo(targetLatLng) + + if (betweenMeters > 1000) { + setDistanceRemain(`${(betweenMeters / 1000).toFixed()} KM`) + } else if (betweenMeters > 50) { + setDistanceRemain(`${betweenMeters.toFixed(0)} M`) } else { setAtTarget(true) } }, () => null, - { enableHighAccuracy: true, maximumAge: 30000, timeout: 27000 } + { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 } ) setWatchId(id) @@ -90,7 +93,11 @@ const LocationButton = ({
- @@ -111,7 +118,7 @@ const LocationButton = ({ {hasPermission ? (

İçeriği görmek için konuma gitmelisin!

-

Kalan mesafe {distanceRemain}

+

{distanceRemain && `Kalan mesafe: ${distanceRemain}`}

) : (
diff --git a/src/pages/[id].astro b/src/pages/[id].astro index 536734a..e575a67 100644 --- a/src/pages/[id].astro +++ b/src/pages/[id].astro @@ -33,6 +33,15 @@ dayjs.extend(relativeTime); dayjs.extend(utc); +console.log( + 'then', + data?.created_at, + 'now', + dayjs().format(), + 'now utc', + dayjs.utc().format() +); + // @ts-expect-error Generated is string const dateFromNow = dayjs(data?.created_at).add(3, 'hour').from(dayjs.utc()); --- diff --git a/src/scripts/initMap.js b/src/scripts/initMap.js index 6759903..001fcf1 100644 --- a/src/scripts/initMap.js +++ b/src/scripts/initMap.js @@ -19,7 +19,7 @@ function startWatchingLocation() { } }, () => null, - { enableHighAccuracy: true, maximumAge: 10000, timeout: 57000 } + { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 } ) } diff --git a/src/scripts/initSelectionMap.js b/src/scripts/initSelectionMap.js index 0afa126..f811953 100644 --- a/src/scripts/initSelectionMap.js +++ b/src/scripts/initSelectionMap.js @@ -39,7 +39,7 @@ function startWatchingLocation() { } }, () => null, - { enableHighAccuracy: true, maximumAge: 10000, timeout: 57000 } + { enableHighAccuracy: true, timeout: 5000, maximumAge: 0 } ) }