From d3530063f34192ec0bb07a54f061f3226ab4c20f Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 30 Jun 2024 11:13:32 +0100 Subject: [PATCH] Add near-to-me pre-feature --- src/lib/islands/near-to-me-island.svelte | 53 ++++++++++++++++++++++++ src/lib/scripts/getLocation.ts | 7 +++- src/lib/stores/location.ts | 26 ++++++++++++ src/lib/stores/version.ts | 2 +- src/routes/+page.svelte | 3 +- src/routes/more/privacy/+page.svelte | 1 + src/routes/more/settings/+page.svelte | 33 +++++++++++++++ src/routes/more/versions/+page.svelte | 2 +- 8 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 src/lib/islands/near-to-me-island.svelte create mode 100644 src/lib/stores/location.ts diff --git a/src/lib/islands/near-to-me-island.svelte b/src/lib/islands/near-to-me-island.svelte new file mode 100644 index 0000000..b3dde5d --- /dev/null +++ b/src/lib/islands/near-to-me-island.svelte @@ -0,0 +1,53 @@ + + + + {#if !$location} +

Coming Soon

+

+ {:else if $location} +

Coming Soon

+ {#await getCurrentLocation()} +

Fetching Location

+ {:then location} +

Lat: {location.latitude}, Long: {location.longitude}

+ {:catch err} +

Error: {err.message}

+ {/await} + {/if} +
+ + diff --git a/src/lib/scripts/getLocation.ts b/src/lib/scripts/getLocation.ts index becc801..99ae984 100644 --- a/src/lib/scripts/getLocation.ts +++ b/src/lib/scripts/getLocation.ts @@ -1,4 +1,4 @@ -export function getCurrentLocation() { +export function getCurrentLocation(): Promise { return new Promise((resolve, reject) => { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( @@ -17,3 +17,8 @@ export function getCurrentLocation() { } }); } + +export interface locationObj { + latitude: number + longitude: number +} diff --git a/src/lib/stores/location.ts b/src/lib/stores/location.ts new file mode 100644 index 0000000..297d791 --- /dev/null +++ b/src/lib/stores/location.ts @@ -0,0 +1,26 @@ +// src/stores.js +import { writable, type Writable } from 'svelte/store'; +import { browser } from '$app/environment'; + +// Initialize the store with a boolean value from local storage +export const location: Writable = writable(fromLocalStorage('location', false)); +toLocalStorage(location, 'location'); + +function fromLocalStorage(storageKey: string, fallback: boolean): boolean { + if (browser) { + const storedValue = localStorage.getItem(storageKey); + if (storedValue !== null && storedValue !== 'undefined') { + return storedValue === 'true'; + } + } + return fallback; +} + +function toLocalStorage(store: Writable, storageKey: string) { + if (browser) { + store.subscribe((value: boolean) => { + localStorage.setItem(storageKey, String(value)); + }); + } +} + diff --git a/src/lib/stores/version.ts b/src/lib/stores/version.ts index 19df22d..05e1a49 100644 --- a/src/lib/stores/version.ts +++ b/src/lib/stores/version.ts @@ -1,3 +1,3 @@ -export const version: string = "2024.06.4"; +export const version: string = "2024.06.5"; export const versionTag: string = ""; export const showWelcome: boolean = false; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 63a7929..c4321d7 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -9,6 +9,7 @@ import { featureDetect } from "$lib/scripts/featureDetect"; import { onMount } from "svelte"; import toast from "svelte-french-toast"; + import NearToMeIsland from "$lib/islands/near-to-me-island.svelte"; const title = "OwlBoard"; const inputIslands = [ @@ -46,7 +47,7 @@ {#each inputIslands as variables} {/each} - +