All files / projects-dev/apps/spacetraders/src/routes/system +page.svelte

0% Statements 0/46
0% Branches 0/1
0% Functions 0/1
0% Lines 0/46

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                                             
<svelte:options customElement="st-routes-system" />

<script lang="ts">
    import { onMount } from "svelte";
    import System from "$components/system.svelte";

    import Loader from "$ui/loader/src/loader.svelte";
    import type { Waypoint } from "$models/waypoint";

    let isLoading = true;
    let currentLocation: Partial<Waypoint>;

    onMount(async () => {
        const options = {
            headers: {
                "Content-Type": "application/json",
                Authorization: `Bearer ${import.meta.env.VITE_API_TOKEN}`,
            },
        };

        fetch(`${import.meta.env.VITE_API_URL}/my/agent`, options)
            .then((response) => response.json())
            .then((response) => {
                // eslint-disable-next-line prefer-const
                let sector: string;
                // eslint-disable-next-line prefer-const
                let system: string;
                // eslint-disable-next-line prefer-const
                let waypoint: string;

                // eslint-disable-next-line prefer-const
                [sector, system, waypoint] = response.data.headquarters.split("-");
                currentLocation = {
                    symbol: waypoint,
                    system: `${sector}-${system}`,
                };
                isLoading = false;
            });
    });
</script>

{#if isLoading}
    <Loader />
{:else}
    <System waypoint="{currentLocation}" />
{/if}