From 5097f70d90c710f7c949e1842bd91c90c2606af8 Mon Sep 17 00:00:00 2001 From: log101 Date: Wed, 24 Jul 2024 12:00:12 +0300 Subject: [PATCH] feat: increment counter on unlock button click --- bun.lockb | Bin 275545 -> 275545 bytes src/layouts/Layout.astro | 52 +++++++++++++++++------------------ src/pages/[id].astro | 8 ------ src/scripts/initMap.ts | 15 ++++++++++ src/scripts/lockedContent.ts | 11 ++++++-- 5 files changed, 49 insertions(+), 37 deletions(-) diff --git a/bun.lockb b/bun.lockb index 9b6bf30dd88a98fb1470cfcee04cfad3d0dcf510..fb03fc273e47ba71994b2cca155f20265ac5d012 100755 GIT binary patch delta 32 ocmcclLg3~Lfrb{wElkE|IT+&%^epuZjoPixGHtg$%Pf};0NDf!#Q*>R delta 32 jcmcclLg3~Lfrb{wElkE|IhYtApxyc`({}5#%yQ`f!$1l^ diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 8abea3f..ee8d6d6 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,50 +1,48 @@ - + - - - - + + + + + src='https://unpkg.com/leaflet@1.9.4/dist/leaflet.js' + integrity='sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=' + crossorigin=''> - - - + type='text/javascript' + src='https://cdn.jsdelivr.net/npm/toastify-js'> + + + - - + + Konulu Konum - + diff --git a/src/pages/[id].astro b/src/pages/[id].astro index 35d76e3..28cc2a1 100644 --- a/src/pages/[id].astro +++ b/src/pages/[id].astro @@ -68,12 +68,6 @@ const dateFromNow = dayjs.utc(data?.created_at).from(dayjs.utc()); - -
@@ -146,7 +139,6 @@ const dateFromNow = dayjs.utc(data?.created_at).from(dayjs.utc());

- diff --git a/src/scripts/initMap.ts b/src/scripts/initMap.ts index 2f1a77f..bd1f7b2 100644 --- a/src/scripts/initMap.ts +++ b/src/scripts/initMap.ts @@ -1,4 +1,5 @@ import L from "leaflet"; +import Toastify from "toastify-js"; type TargetLocation = [lat: number, lng: number] | null; @@ -59,6 +60,20 @@ const CurrentLocation = L.Control.extend({ locationButton.addEventListener("click", () => { if (currentLocationMarker) { map.setView(currentLocationMarker.getLatLng(), 12); + } else { + Toastify({ + text: "Konumunuza erişilemiyor, lütfen biraz bekleyip tekrar deneyin.", + duration: 3000, + gravity: "top", + position: "center", + stopOnFocus: true, + style: { + background: "black", + borderRadius: "6px", + margin: "16px", + }, + onClick: function () {}, + }).showToast(); } }); diff --git a/src/scripts/lockedContent.ts b/src/scripts/lockedContent.ts index 3745ef7..c7b85d1 100644 --- a/src/scripts/lockedContent.ts +++ b/src/scripts/lockedContent.ts @@ -2,6 +2,7 @@ import { calculateDistance, errorCallback, } from "@/components/LockedContent/geolocation"; +import { incrementUnlockCounter } from "@/components/LockedContent/serverUtils"; import { onLocationSuccess } from "@/scripts/initMap"; let watchId: number; @@ -18,6 +19,9 @@ const locationPermissionButton = document.getElementById( "location-permission-button" ); +if (locationPermissionButton) + locationPermissionButton.addEventListener("click", startWatchingLocation); + // Generates a human readable destination text according to // distance remaining function generateDistanceText(distance: number) { @@ -38,6 +42,7 @@ function updateCurrentLocation(position: GeolocationPosition) { [newPosition.latitude, newPosition.longitude], JSON.parse(targetLocation) ); + if (distance < 100) { // If user has arrived to destination // Transform locked button to reveal button @@ -46,7 +51,6 @@ function updateCurrentLocation(position: GeolocationPosition) { const lockIcon = document.getElementById("lock-icon"); const buttonText = document.getElementById("button-text"); const description = document.getElementById("locked-content-description"); - if (unlockButton) { if (buttonText) buttonText.innerText = "İçeriği Göster"; if (lockIcon) lockIcon.classList.add("hidden"); @@ -71,6 +75,7 @@ function updateCurrentLocation(position: GeolocationPosition) { const unlockButtonContainer = document.getElementById( "unlock-button-container" ); + incrementUnlockCounter(document.URL.slice(-12)); if (image) image.classList.remove("blur-2xl"); if (unlockButtonContainer) unlockButtonContainer.remove(); }); @@ -82,7 +87,9 @@ function updateCurrentLocation(position: GeolocationPosition) { descriptionElement.innerText = `Kalan mesafe: ${distanceText}`; } - if (locationPermissionButton) locationPermissionButton.remove(); + if (locationPermissionButton) { + locationPermissionButton.remove(); + } } // Update leaflet controls