diff --git a/src/components/LockedContent.tsx b/src/components/LockedContent.tsx index 7f1a97a..258d50f 100644 --- a/src/components/LockedContent.tsx +++ b/src/components/LockedContent.tsx @@ -13,15 +13,26 @@ const incrementCounter = async (id: string | Generated) => const LocationButton = ({ contentId = "", - imageUrl = "#" + imageUrl = "#", + location = "" }: { contentId?: string | Generated imageUrl?: string + location?: string }) => { const [atTarget, setAtTarget] = useState(false) const [contentVisible, setContentVisible] = useState(false) const [hasPermission, setHasPermission] = useState(false) const [watchId, setWatchId] = useState() + const [distanceRemain, setDistanceRemain] = useState("") + + const targetCoordinates = JSON.parse(location).coordinates + const targetPos = { + lat: targetCoordinates[0], + lng: targetCoordinates[1] + } + + console.log(targetPos) const startWatchingLocation = () => { setHasPermission(true) @@ -33,9 +44,13 @@ const LocationButton = ({ lng: position.coords.longitude } - const totalDistanceInKM = distance(pos.lat, pos.lng, pos.lat, pos.lng).toFixed(0) + const totalDistanceInKM = distance(pos.lat, pos.lng, targetPos.lat, targetPos.lng) - if (totalDistanceInKM === "0") { + if (totalDistanceInKM > 1) { + setDistanceRemain(`${totalDistanceInKM.toFixed(0)} KM`) + } else if (totalDistanceInKM < 1 && totalDistanceInKM * 1000 > 50) { + setDistanceRemain(`${(totalDistanceInKM * 1000).toFixed(0)} Metre`) + } else { setAtTarget(true) } }, @@ -94,7 +109,10 @@ const LocationButton = ({ {hasPermission ? ( - İçeriği görmek için konuma gitmelisin! + +

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

+

Kalan mesafe {distanceRemain}

+
) : (
diff --git a/src/pages/[id].astro b/src/pages/[id].astro index e7cbd46..536734a 100644 --- a/src/pages/[id].astro +++ b/src/pages/[id].astro @@ -67,7 +67,12 @@ const dateFromNow = dayjs(data?.created_at).add(3, 'hour').from(dayjs.utc()); - +