Files
gpx.studio/website/src/lib/components/gpx-layer/WaypointPopup.svelte

76 lines
2.6 KiB
Svelte
Raw Normal View History

<script lang="ts">
import * as Card from '$lib/components/ui/card';
2024-06-13 09:44:27 +02:00
import { Button } from '$lib/components/ui/button';
import Shortcut from '$lib/components/Shortcut.svelte';
import { waypointPopup, currentPopupWaypoint, deleteWaypoint } from './WaypointPopup';
2024-05-13 19:43:10 +02:00
import WithUnits from '$lib/components/WithUnits.svelte';
2024-06-13 09:44:27 +02:00
import { Dot, Trash2 } from 'lucide-svelte';
2024-05-13 19:43:10 +02:00
import { onMount } from 'svelte';
2024-06-13 09:44:27 +02:00
import { Tool, currentTool } from '$lib/stores';
import { getSymbolKey, symbols } from '$lib/assets/symbols';
import { _ } from 'svelte-i18n';
2024-05-13 19:43:10 +02:00
let popupElement: HTMLDivElement;
onMount(() => {
waypointPopup.setDOMContent(popupElement);
popupElement.classList.remove('hidden');
});
2024-08-08 17:52:11 +02:00
$: symbolKey = $currentPopupWaypoint ? getSymbolKey($currentPopupWaypoint[0].sym) : undefined;
</script>
2024-05-13 19:43:10 +02:00
<div bind:this={popupElement} class="hidden">
2024-06-12 18:48:03 +02:00
{#if $currentPopupWaypoint}
2024-06-13 09:44:27 +02:00
<Card.Root class="border-none shadow-md text-base max-w-80 p-2">
2024-05-13 19:43:10 +02:00
<Card.Header class="p-0">
2024-06-13 09:44:27 +02:00
<Card.Title class="text-md">{$currentPopupWaypoint[0].name}</Card.Title>
2024-05-13 19:43:10 +02:00
</Card.Header>
<Card.Content class="flex flex-col p-0 text-sm">
<div class="flex flex-row items-center text-muted-foreground text-xs whitespace-nowrap">
{#if symbolKey}
2024-08-08 17:52:11 +02:00
<span>
{#if symbols[symbolKey].icon}
<svelte:component
this={symbols[symbolKey].icon}
size="12"
class="inline-block mb-0.5"
/>
{:else}
<span class="w-4 inline-block" />
{/if}
{$_(`gpx.symbol.${symbolKey}`)}
</span>
<Dot size="16" />
{/if}
2024-06-13 09:44:27 +02:00
{$currentPopupWaypoint[0].getLatitude().toFixed(6)}&deg; {$currentPopupWaypoint[0]
2024-05-13 19:43:10 +02:00
.getLongitude()
.toFixed(6)}&deg;
2024-06-13 09:44:27 +02:00
{#if $currentPopupWaypoint[0].ele !== undefined}
2024-05-13 19:43:10 +02:00
<Dot size="16" />
2024-06-13 09:44:27 +02:00
<WithUnits value={$currentPopupWaypoint[0].ele} type="elevation" />
2024-05-13 19:43:10 +02:00
{/if}
</div>
2024-06-13 09:44:27 +02:00
{#if $currentPopupWaypoint[0].desc}
2024-07-17 23:05:17 +02:00
<span class="whitespace-pre-wrap">{$currentPopupWaypoint[0].desc}</span>
2024-06-13 09:44:27 +02:00
{/if}
{#if $currentPopupWaypoint[0].cmt && $currentPopupWaypoint[0].cmt !== $currentPopupWaypoint[0].desc}
2024-07-17 23:05:17 +02:00
<span class="whitespace-pre-wrap">{$currentPopupWaypoint[0].cmt}</span>
2024-05-13 19:43:10 +02:00
{/if}
2024-06-13 09:44:27 +02:00
{#if $currentTool === Tool.WAYPOINT}
2024-07-17 23:05:17 +02:00
<Button
class="mt-2 w-full px-2 py-1 h-8 justify-start"
variant="outline"
on:click={() =>
deleteWaypoint($currentPopupWaypoint[1], $currentPopupWaypoint[0]._data.index)}
>
<Trash2 size="16" class="mr-1" />
{$_('menu.delete')}
<Shortcut key="" shift={true} click={true} />
</Button>
2024-05-13 19:43:10 +02:00
{/if}
</Card.Content>
</Card.Root>
{/if}
</div>