Flesh out new NearToMeCard
This commit is contained in:
parent
7472f96b5d
commit
30240edf00
@ -6,50 +6,80 @@
|
|||||||
import type { NearestStationResponse } from "@owlboard/ts-types";
|
import type { NearestStationResponse } from "@owlboard/ts-types";
|
||||||
import { uuid } from "$lib/stores/uuid";
|
import { uuid } from "$lib/stores/uuid";
|
||||||
import { location } from "$lib/stores/location";
|
import { location } from "$lib/stores/location";
|
||||||
|
import InLineLoading from "$lib/navigation/InLineLoading.svelte";
|
||||||
|
import { apiGet } from "$lib/scripts/apiFetch";
|
||||||
|
import { onMount } from "svelte";
|
||||||
|
|
||||||
let stations: NearestStationResponse[];
|
let errorMessage: string;
|
||||||
|
let stations: NearestStationResponse[] = [];
|
||||||
|
|
||||||
let config: CardConfig = {
|
let config: CardConfig = {
|
||||||
title: "Near to Me",
|
title: "Near to Me",
|
||||||
showHelp: true,
|
showHelp: true,
|
||||||
showRefresh: true,
|
showRefresh: true,
|
||||||
helpText: "Your location may not be accurate, particularly on desktop and laptop devices.",
|
helpText: "Your location may not be accurate on desktop and laptop devices.",
|
||||||
onRefresh: refresh
|
onRefresh: refresh,
|
||||||
}
|
};
|
||||||
|
|
||||||
function turnOnLocation() {
|
function turnOnLocation() {
|
||||||
location.set(true)
|
location.set(true);
|
||||||
getCurrentLocation();
|
getCurrentLocation();
|
||||||
toast.success("Done\nTo disable location, go to settings")
|
toast.success("Done\nTo disable location, go to settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
function refresh() {getNearestStations()}
|
function refresh() {
|
||||||
|
stations = [];
|
||||||
|
getNearestStations();
|
||||||
|
}
|
||||||
|
|
||||||
async function getNearestStations() {
|
async function getNearestStations() {
|
||||||
// Get location, then fetch nearest stations and push to `stations` variable
|
// Get location, then fetch nearest stations and push to `stations` variable
|
||||||
|
const currentLocation = await getCurrentLocation();
|
||||||
|
const apiPath: string = `/api/v2/live/station/nearest/${currentLocation.latitude}/${currentLocation.longitude}`;
|
||||||
|
try {
|
||||||
|
const apiResponse = (await apiGet(apiPath)) as NearestStationResponse[];
|
||||||
|
stations = apiResponse;
|
||||||
|
} catch (err) {
|
||||||
|
errorMessage = err as string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if ($location) {
|
||||||
|
if ($uuid && $uuid != "null") {
|
||||||
|
getNearestStations();
|
||||||
|
} else {
|
||||||
|
errorMessage = "Register to use this feature";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card {config}>
|
<Card {config}>
|
||||||
{#if !$uuid || $uuid === "null"}
|
{#if !$uuid || $uuid === "null"}
|
||||||
<p><a href="/more/reg">Register to use this feature</a></p>
|
<p><a href="/more/reg">Register to use this feature</a></p>
|
||||||
{:else}
|
{:else if $location}
|
||||||
{#if $location}
|
{#if !stations.length}
|
||||||
{#if !stations}
|
{#if errorMessage}
|
||||||
<p>Fetching locations...</p>
|
<p>{errorMessage}</p>
|
||||||
{:else}
|
{:else}
|
||||||
{#each stations as station}
|
<InLineLoading />
|
||||||
<a href="/ldb?station={station["3ALPHA"]}">{station.NLCDESC} - {station.miles}mi</a>
|
|
||||||
{/each}
|
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
{:else}
|
||||||
<p><button on:click={turnOnLocation}>Turn on Location</button></p>
|
<div id="buttons">
|
||||||
|
{#each stations as station}
|
||||||
|
<a class="link" href="/ldb?station={station['3ALPHA']}">{station.NLCDESC} - {station.miles}mi</a>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{:else}
|
||||||
|
<p><button on:click={turnOnLocation}>Turn on Location</button></p>
|
||||||
{/if}
|
{/if}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
a, button {
|
a,
|
||||||
|
button {
|
||||||
color: aliceblue;
|
color: aliceblue;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
@ -61,8 +91,30 @@
|
|||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
a:hover, button:hover {
|
a:hover,
|
||||||
|
button:hover {
|
||||||
background-color: rgb(45, 45, 45);
|
background-color: rgb(45, 45, 45);
|
||||||
box-shadow: var(--box-shadow-dark);
|
box-shadow: var(--box-shadow-dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#buttons {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
width: 95%;
|
||||||
|
margin: auto;
|
||||||
|
padding-top: 5px;
|
||||||
|
}
|
||||||
|
.link {
|
||||||
|
display: inline-flex;
|
||||||
|
margin: 5px;
|
||||||
|
border: none;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 5px 10px;
|
||||||
|
font-family: urwgothic, "Lucida Sans", "Lucida Sans Regular", "Lucida Grande", "Lucida Sans Unicode", Geneva, Verdana, sans-serif;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 400;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
Loading…
Reference in New Issue
Block a user