Skip to content

Commit

Permalink
Merge pull request #22 from spektrumrf/dev
Browse files Browse the repository at this point in the history
Allow admins to see GPS
  • Loading branch information
jonaswesterlund authored Mar 21, 2024
2 parents 448eed7 + a6410f7 commit aa0d3a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
43 changes: 24 additions & 19 deletions src/routes/[year]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,12 @@
.collection('event')
.subscribe($event.id, async (data) => ($event = data.record as any));
}
if ($account && $account.role === Role.TEAM && $account.allowGps) {
if ($account && $account.role === Role.ADMIN) {
await loadPositionsAndRegisterRealtime(client);
} else if ($account && $account.allowGps) {
navigator?.geolocation?.getCurrentPosition(async (pos) => {
if (pos) {
const loadedPositions = await fetch(`/api/positions?year=${$page.params.year}`).then(
(res) => res.json()
);
for (let position of loadedPositions) {
if (!$positions[position.team]) {
$positions[position.team] = position;
}
}
client.collection('position').subscribe(
'*',
async (event) => {
const position = event.record;
if (event.action === 'create') {
$positions[position.team] = position;
}
},
{ expand: 'team' }
);
await loadPositionsAndRegisterRealtime(client);
}
});
}
Expand All @@ -90,6 +75,26 @@
});
}
}
async function loadPositionsAndRegisterRealtime(client: any) {
const loadedPositions = await fetch(`/api/positions?year=${$page.params.year}`).then((res) =>
res.json()
);
for (let position of loadedPositions) {
if (!$positions[position.team]) {
$positions[position.team] = position;
}
}
client.collection('position').subscribe(
'*',
async (event: any) => {
const position = event.record;
if (event.action === 'create') {
$positions[position.team] = position;
}
},
{ expand: 'team' }
);
}
</script>

<div>
Expand Down
8 changes: 4 additions & 4 deletions src/routes/[year]/gps/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import L from 'leaflet';
import { onMount } from 'svelte';
import { account, positions, event } from '$lib/stores';
import { account, positions, event, Role } from '$lib/stores';
import Loading from '$lib/components/Loading.svelte';
import dayjs from 'dayjs';
let map: any;
Expand Down Expand Up @@ -46,7 +46,7 @@
</script>

<h3 class="font-bold text-2xl mb-5">GPS</h3>
{#if hasStarted}
{#if hasStarted && $account?.role === Role.TEAM}
<div class="max-w-xs">
<label class="label cursor-pointer">
<span class="label-text">Dela din position</span>
Expand All @@ -60,11 +60,11 @@
</Loading>
</label>
</div>
{:else}
{:else if $account?.role === Role.TEAM}
<p>Ladda om sidan då Vasagatan har börjat</p>
{/if}
<div id="map" bind:this={map}></div>
{#if allowGps}
{#if allowGps || $account?.role === Role.ADMIN}
<h4 class="font-bold text-xl mt-5 mb-2">Positioner</h4>
<p class="italic">Tryck på lag för att centrera karta</p>
<ul class="ml-5 mt-2 list-disc">
Expand Down

0 comments on commit aa0d3a9

Please sign in to comment.