From 69b8d7475936b4452af286e85fc66eadd4128ad2 Mon Sep 17 00:00:00 2001 From: andz-bb Date: Thu, 25 May 2023 12:56:56 +0100 Subject: [PATCH] fix async, display loading state, style tweaks --- package.json | 2 +- src/Component.svelte | 71 ++++++++++++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 1fe675e..a28d8cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "geolocation", - "version": "0.3.3", + "version": "1.1.0", "description": "A form field that provides the user's current geolocation", "author": "andz-bb", "license": "MIT", diff --git a/src/Component.svelte b/src/Component.svelte index 718df68..1b55220 100644 --- a/src/Component.svelte +++ b/src/Component.svelte @@ -27,7 +27,7 @@ error = "Geolocation is not supported by your browser"; } else { isLoading = true; - navigator.geolocation.getCurrentPosition( + await navigator.geolocation.getCurrentPosition( (pos) => { latitude = pos.coords.latitude; longitude = pos.coords.longitude; @@ -95,25 +95,47 @@ {label || " "}
- {#if !disabled} - - {/if} -

{latitude}

-

{longitude}

+
+ {#if !disabled} +
+ {#if !isLoading} + + {:else} +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {/if} +
+ {/if} + +
+
{latitude}
+
{longitude}
+
+
- {#if isLoading} - - {/if} {#if !latitudeField || !longitudeField} -
Please select a field
+
Please select latitude and longitude fields
{/if} {#if error}
{error}
@@ -129,6 +151,18 @@