diff --git a/astro.config.mjs b/astro.config.mjs index 306289b..55a3752 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -9,8 +9,5 @@ export default defineConfig({ integrations: [react(), tailwind({ applyBaseStyles: false })], - output: "server", - adapter: node({ - mode: "standalone" - }), + output: "static" }); diff --git a/src/components/LockedContent/geolocation.ts b/src/components/LockedContent/geolocation.ts index 49b2a57..6030648 100644 --- a/src/components/LockedContent/geolocation.ts +++ b/src/components/LockedContent/geolocation.ts @@ -61,7 +61,7 @@ function locationSuccessCallback( updateText("locked-content-description", `Kalan mesafe: ${distanceText}`) } - removeElement("location-permission-button") + removeElement("location-permission-button", true) // Update leaflet controls mapLocationSuccessCallback(position) diff --git a/src/pages/index.astro b/src/pages/index.astro index dfd955f..8cc9a67 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,6 +1,4 @@ --- -export const prerender = true - import "@/styles/globals.css" import "../styles/locked-page.css" diff --git a/src/pages/[id].astro b/src/pages/x/index.astro similarity index 66% rename from src/pages/[id].astro rename to src/pages/x/index.astro index 0fd9988..5a9b492 100644 --- a/src/pages/[id].astro +++ b/src/pages/x/index.astro @@ -1,12 +1,12 @@ --- // Styles import "@/styles/globals.css" -import "../styles/locked-page.css" -import "../styles/locked-content.css" +import "@/styles/locked-page.css" +import "@/styles/locked-content.css" // Components -import Layout from "../layouts/Layout.astro" -import ShareButton from "../components/ShareButton" +import Layout from "@/layouts/Layout.astro" +import ShareButton from "@/components/ShareButton" import { Card, CardContent, @@ -15,26 +15,6 @@ import { CardTitle, } from "@/components/ui/card" import { CalendarIcon } from "@radix-ui/react-icons" -import type { ContentTable } from "@/lib/db" - -// Dayjs -import dayjs from "dayjs" -import relativeTime from "dayjs/plugin/relativeTime" -import utc from "dayjs/plugin/utc" - -type Content = ContentTable - -const { id } = Astro.params - -const res = await fetch(`http://localhost:3000/api/location/${id}`) - -const data: Content | null = res.status === 200 ? await res.json() : null - -dayjs.extend(relativeTime) - -dayjs.extend(utc) - -const dateFromNow = dayjs.utc(data?.created_at).from(dayjs.utc()) --- @@ -52,25 +32,24 @@ const dateFromNow = dayjs.utc(data?.created_at).from(dayjs.utc()) - {data?.author} + -

{data?.description}

+

-

{dateFromNow}

+
-
-
- +

- Fotoğrafın kilidi şu ana dek {data?.unlocked_counter} kez açıldı + Fotoğrafın kilidi şu ana dek kez açıldı

- - + + + diff --git a/src/scripts/index.ts b/src/scripts/index.ts index ea53ef4..63f6098 100644 --- a/src/scripts/index.ts +++ b/src/scripts/index.ts @@ -52,7 +52,7 @@ const handleSubmit = async (e: SubmitEvent) => { if (res.status === 200) { const data = await res.json() - if (data.url) location.assign("/" + data.url) + if (data.url) location.assign(`/x?id="${data.url}"`) } else { toast("Konulu konum oluşturulamadı, lütfen tekrar deneyin.") } diff --git a/src/scripts/initMap.ts b/src/scripts/initMap.ts index df77c29..51b5ba1 100644 --- a/src/scripts/initMap.ts +++ b/src/scripts/initMap.ts @@ -5,25 +5,10 @@ import { import { toast } from "@/lib/utils" import L from "leaflet" -type TargetLocation = [lat: number, lng: number] | null - +var map: L.Map const mapEl = document.getElementById("map") -const targetLocation = mapEl?.dataset.targetLocation - -const data = targetLocation ? JSON.parse(targetLocation) : null - -const TARGET_LOCATION = data as TargetLocation - -var map = L.map("map") - -if (TARGET_LOCATION) map.setView(TARGET_LOCATION, 13) - -L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", { - maxZoom: 19, - attribution: - '© OpenStreetMap', -}).addTo(map) +type TargetLocation = [lat: number, lng: number] | null let currentLocationMarker: L.Marker @@ -74,7 +59,8 @@ const GoToTargetLocation = L.Control.extend({ locationButton.classList.add("custom-map-control-button") locationButton.addEventListener("click", () => { - if (TARGET_LOCATION) map.setView(TARGET_LOCATION, 12) + const targetLocation = getTargetLocation() + if (targetLocation) map.setView(targetLocation, 12) }) return locationButton @@ -102,6 +88,32 @@ function addTargetLocationMarker(target: TargetLocation) { } } -addTargetLocationMarker(TARGET_LOCATION) -targetLocationControl.addTo(map) -goToCurrentLocationControl.addTo(map) +function getTargetLocation(): TargetLocation | null { + const targetLocation = mapEl?.dataset.targetLocation + + const data = targetLocation ? JSON.parse(targetLocation) : null + + return data +} + +export function initMap() { + map = L.map("map") + + const targetLocation = mapEl?.dataset.targetLocation + + const data = targetLocation ? JSON.parse(targetLocation) : null + + const TARGET_LOCATION = data as TargetLocation + + if (TARGET_LOCATION) map.setView(TARGET_LOCATION, 13) + + L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", { + maxZoom: 19, + attribution: + '© OpenStreetMap', + }).addTo(map) + + addTargetLocationMarker(TARGET_LOCATION) + targetLocationControl.addTo(map) + goToCurrentLocationControl.addTo(map) +} diff --git a/src/scripts/lockedContent.ts b/src/scripts/lockedContent.ts index 824aa1d..67db49c 100644 --- a/src/scripts/lockedContent.ts +++ b/src/scripts/lockedContent.ts @@ -29,15 +29,26 @@ locationPermissionButton.addEventListener("click", startWatchingLocation) lockedContentContainer.addEventListener("askpermission", startWatchingLocation) -const targetPositionString = lockedContentContainer.dataset.targetPosition +// Get target position from container's dataset +function getTargetPosition() { + const lockedContentContainer = document.getElementById( + "locked-content-container" + ) -// TARGET_POSITION is required to calculate distance -if (!targetPositionString) throw new Error("Target position is not provided!") + const targetPositionString = lockedContentContainer?.dataset.targetPosition -const TARGET_POSITION = JSON.parse(targetPositionString) as LatLngTuple + // TARGET_POSITION is required to calculate distance + if (!targetPositionString) throw new Error("Target position is not provided!") + + const data = JSON.parse(targetPositionString) as LatLngTuple + + return data +} // Call Geolocation API to start watching user location function startWatchingLocation() { + const TARGET_POSITION = getTargetPosition() + if (!watchId) { watchId = window.navigator.geolocation.watchPosition( (position) => locationSuccessCallback(position, TARGET_POSITION), @@ -53,6 +64,7 @@ navigator.permissions .then((permissionStatus) => { switch (permissionStatus.state) { case "granted": + const TARGET_POSITION = getTargetPosition() watchId = window.navigator.geolocation.watchPosition( (position) => locationSuccessCallback(position, TARGET_POSITION), errorCallback