Compare commits

..

4 Commits

Author SHA1 Message Date
36a2466210 chore: add icon
All checks were successful
/ Build (push) Successful in 34s
2024-09-03 12:20:10 +03:00
04a5ec30c2 feat: change logo
All checks were successful
/ Build (push) Successful in 40s
2024-09-03 12:14:26 +03:00
1d06a06697 feat: stop geoloaction callback after user has arrived
All checks were successful
/ Build (push) Successful in 34s
feat: automatically start watching if gelocation permission is given
2024-09-03 10:54:09 +03:00
5445f62e2e i18n: translate dayjs date
All checks were successful
/ Build (push) Successful in 37s
2024-09-03 10:08:59 +03:00
8 changed files with 37 additions and 29 deletions

1
.gitignore vendored
View File

@ -20,3 +20,4 @@ pnpm-debug.log*
# macOS-specific files # macOS-specific files
.DS_Store .DS_Store
TODO TODO
public/konulu-konum-logo2.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 266 KiB

View File

@ -56,7 +56,7 @@ function locationSuccessCallback(
// Reveal image when the unlock button is clicked // Reveal image when the unlock button is clicked
const unlockButton = document.getElementById("unlock-content-button") const unlockButton = document.getElementById("unlock-content-button")
unlockButton?.addEventListener("click", revealContent) unlockButton?.addEventListener("click", (ev) => revealContent(ev.target))
} else { } else {
const distanceText = generateDistanceText(distance) const distanceText = generateDistanceText(distance)
updateText("locked-content-description", `Kalan mesafe: ${distanceText}`) updateText("locked-content-description", `Kalan mesafe: ${distanceText}`)

View File

@ -9,7 +9,7 @@ import "toastify-js/src/toastify.css"
<meta charset='UTF-8' /> <meta charset='UTF-8' />
<meta name='description' content='Astro description' /> <meta name='description' content='Astro description' />
<meta name='viewport' content='width=device-width' /> <meta name='viewport' content='width=device-width' />
<link rel='icon' type='image/jpg' href='/konulu-konum-logo.jpg' /> <link rel='icon' type='image/jpg' href='/konulu-konum-icon.jpg' />
<meta property='og:title' content='Konulu Konum' /> <meta property='og:title' content='Konulu Konum' />
<meta property='og:description' content='Sevdiklerinizi şaşırtın!' /> <meta property='og:description' content='Sevdiklerinizi şaşırtın!' />
<meta property='og:url' content='https://konulukonum.com' /> <meta property='og:url' content='https://konulukonum.com' />

View File

@ -43,7 +43,11 @@ function addAttribute(elemId: string, attribute: string, value: string) {
else console.error("Element could not be found!") else console.error("Element could not be found!")
} }
function revealContent() { function revealContent(el: EventTarget | null) {
// dispatch user arrived custom event to stop geolocation callback
const userArrivedEvent = new Event("userarrived", { bubbles: true })
el?.dispatchEvent(userArrivedEvent)
incrementUnlockCounter(document.URL.slice(-12)) incrementUnlockCounter(document.URL.slice(-12))
removeClasses("content", "blur-2xl") removeClasses("content", "blur-2xl")
removeElement("unlock-button-container") removeElement("unlock-button-container")

View File

@ -116,9 +116,11 @@ import { CalendarIcon } from "@radix-ui/react-icons"
import dayjs from "dayjs" import dayjs from "dayjs"
import relativeTime from "dayjs/plugin/relativeTime" import relativeTime from "dayjs/plugin/relativeTime"
import utc from "dayjs/plugin/utc" import utc from "dayjs/plugin/utc"
import "dayjs/locale/tr"
// Map // Map
import { initMap } from "@/scripts/initMap" import { initMap } from "@/scripts/initMap"
import { startWatchingLocation } from "@/scripts/lockedContent"
const url = new URL(document.URL).searchParams const url = new URL(document.URL).searchParams
const id = url.get("id") const id = url.get("id")
@ -132,8 +134,8 @@ import { CalendarIcon } from "@radix-ui/react-icons"
const data: Content | null = res.status === 200 ? await res.json() : null const data: Content | null = res.status === 200 ? await res.json() : null
dayjs.extend(relativeTime) dayjs.extend(relativeTime)
dayjs.extend(utc) dayjs.extend(utc)
dayjs.locale("tr")
const dateFromNow = dayjs.utc(data?.created_at).from(dayjs.utc()) const dateFromNow = dayjs.utc(data?.created_at).from(dayjs.utc())
@ -164,6 +166,22 @@ import { CalendarIcon } from "@radix-ui/react-icons"
const counter = document.getElementById("counter") const counter = document.getElementById("counter")
if (counter) counter.innerText = data?.unlocked_counter.toString() ?? "" if (counter) counter.innerText = data?.unlocked_counter.toString() ?? ""
// When the web page is loaded, check if user has given geolocation
// permission before
navigator.permissions
.query({ name: "geolocation" })
.then((permissionStatus) => {
switch (permissionStatus.state) {
case "granted":
startWatchingLocation()
break
case "denied":
case "prompt":
default:
break
}
})
</script> </script>
<script src='@/scripts/initMap.ts'></script> <script src='@/scripts/initMap.ts'></script>
<script src='@/scripts/lockedContent.ts'></script> <script src='@/scripts/lockedContent.ts'></script>

View File

@ -30,7 +30,7 @@ locationPermissionButton.addEventListener("click", startWatchingLocation)
lockedContentContainer.addEventListener("askpermission", startWatchingLocation) lockedContentContainer.addEventListener("askpermission", startWatchingLocation)
// Get target position from container's dataset // Get target position from container's dataset
function getTargetPosition() { function getTargetPosition(): LatLngTuple | void {
const lockedContentContainer = document.getElementById( const lockedContentContainer = document.getElementById(
"locked-content-container" "locked-content-container"
) )
@ -59,36 +59,21 @@ function getRadius() {
} }
// Call Geolocation API to start watching user location // Call Geolocation API to start watching user location
function startWatchingLocation() { export function startWatchingLocation() {
const TARGET_POSITION = getTargetPosition() const TARGET_POSITION = getTargetPosition()
const radius = getRadius() const radius = getRadius()
if (!watchId) { if (!watchId && TARGET_POSITION) {
watchId = window.navigator.geolocation.watchPosition( watchId = window.navigator.geolocation.watchPosition(
(position) => locationSuccessCallback(position, TARGET_POSITION, radius), (position) => locationSuccessCallback(position, TARGET_POSITION, radius),
errorCallback errorCallback
) )
}
}
// When the web page is loaded, check if user has given geolocation const imageContainer = document.getElementById("locked-content-container")
// permission before if (imageContainer) {
navigator.permissions imageContainer.addEventListener("userarrived", () => {
.query({ name: "geolocation" }) window.navigator.geolocation.clearWatch(watchId)
.then((permissionStatus) => {
switch (permissionStatus.state) {
case "granted":
const TARGET_POSITION = getTargetPosition()
const radius = getRadius()
watchId = window.navigator.geolocation.watchPosition(
(position) =>
locationSuccessCallback(position, TARGET_POSITION, radius),
errorCallback
)
break
case "denied":
case "prompt":
default:
break
}
}) })
}
}
}