All files / projects-dev/apps/spacetraders/src/components location.svelte

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

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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77                                                                                                                                                         
<svelte:options customElement="st-location" />

<script lang="ts">
    import { onMount } from "svelte";
    import type { Waypoint } from "$models/waypoint";

    import Loader from "$ui/loader/src/loader.svelte";
    // eslint-disable-next-line import/no-mutable-exports
    export let waypoint: Partial<Waypoint>;

    let isLoading = true;

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

        fetch(
            `${import.meta.env.VITE_API_URL}/systems/${waypoint.system}/waypoints/${waypoint.system}-${
                waypoint.symbol
            }`,
            options,
        )
            .then((response) => response.json())
            .then((response) => {
                waypoint.faction = response.data.faction;
                waypoint.type = response.data.type;
                waypoint.coordinates = {
                    x: response.data.x,
                    y: response.data.y,
                };
                waypoint.orbitals = response.data.orbitals.map((orbital) => {
                    return {
                        symbol: orbital.symbol,
                    };
                });
                waypoint.traits = response.data.traits;

                isLoading = false;
            })
            .catch((error) => {
                // eslint-disable-next-line no-console
                console.error(error);
                isLoading = false;
            });
    });
</script>

{#if isLoading}
    <Loader />
{:else}
    <h2>Current location</h2>
    <div>
        System: {waypoint.system} <br />
        Waypoint: {waypoint.symbol} <br />
        Faction: {waypoint.faction.symbol} <br />
        Type: {waypoint.type} <br />
        Coordinates: {waypoint.coordinates.x}, {waypoint.coordinates.y} <br />
        Orbitals:
        <ul>
            {#each waypoint.orbitals as orbital}
                <li>{orbital.symbol}</li>
            {/each}
        </ul>
        Traits:
        <ul>
            {#each waypoint.traits as trait}
                <li>{trait.name}</li>
                <p>{trait.description}</p>
            {/each}
        </ul>
    </div>
{/if}