2024-06-27 17:14:35 +02:00
|
|
|
<script lang="ts">
|
2024-09-10 16:52:21 +02:00
|
|
|
import { Button } from '$lib/components/ui/button';
|
|
|
|
|
import { Input } from '$lib/components/ui/input';
|
|
|
|
|
import { Textarea } from '$lib/components/ui/textarea';
|
|
|
|
|
import { Label } from '$lib/components/ui/label/index.js';
|
|
|
|
|
import * as Popover from '$lib/components/ui/popover';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { Save } from '@lucide/svelte';
|
2025-10-05 19:34:05 +02:00
|
|
|
import { ListFileItem, ListTrackItem, type ListItem } from '../file-list';
|
2024-09-10 16:52:21 +02:00
|
|
|
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
2025-06-21 21:07:36 +02:00
|
|
|
import { i18n } from '$lib/i18n.svelte';
|
|
|
|
|
import { editMetadata } from '$lib/components/file-list/metadata/utils.svelte';
|
2025-10-25 17:44:41 +02:00
|
|
|
import { fileActionManager } from '$lib/logic/file-action-manager';
|
2024-06-27 17:14:35 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
let {
|
|
|
|
|
node,
|
|
|
|
|
item,
|
|
|
|
|
open = $bindable(),
|
|
|
|
|
}: {
|
|
|
|
|
node: GPXTreeElement<AnyGPXTreeElement> | Waypoint[] | Waypoint;
|
|
|
|
|
item: ListItem;
|
|
|
|
|
open: boolean;
|
|
|
|
|
} = $props();
|
2024-06-27 17:14:35 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
let name: string = $derived(
|
2024-09-10 16:52:21 +02:00
|
|
|
node instanceof GPXFile
|
2025-02-02 11:17:22 +01:00
|
|
|
? (node.metadata.name ?? '')
|
2024-09-10 16:52:21 +02:00
|
|
|
: node instanceof Track
|
2025-02-02 11:17:22 +01:00
|
|
|
? (node.name ?? '')
|
2025-06-21 21:07:36 +02:00
|
|
|
: ''
|
|
|
|
|
);
|
|
|
|
|
let description: string = $derived(
|
2024-09-10 16:52:21 +02:00
|
|
|
node instanceof GPXFile
|
2025-02-02 11:17:22 +01:00
|
|
|
? (node.metadata.desc ?? '')
|
2024-09-10 16:52:21 +02:00
|
|
|
: node instanceof Track
|
2025-02-02 11:17:22 +01:00
|
|
|
? (node.desc ?? '')
|
2025-06-21 21:07:36 +02:00
|
|
|
: ''
|
|
|
|
|
);
|
2024-06-27 18:23:11 +02:00
|
|
|
|
2025-06-21 21:07:36 +02:00
|
|
|
$effect(() => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
editMetadata.current = false;
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-06-27 17:14:35 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Popover.Root bind:open>
|
2025-10-26 12:12:23 +01:00
|
|
|
<Popover.Trigger class="-mx-1" />
|
2024-09-10 16:52:21 +02:00
|
|
|
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="name">{i18n._('menu.metadata.name')}</Label>
|
2024-09-10 16:52:21 +02:00
|
|
|
<Input bind:value={name} id="name" class="font-semibold h-8" />
|
2025-06-21 21:07:36 +02:00
|
|
|
<Label for="description">{i18n._('menu.metadata.description')}</Label>
|
2024-09-10 16:52:21 +02:00
|
|
|
<Textarea bind:value={description} id="description" />
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
2025-06-21 21:07:36 +02:00
|
|
|
onclick={() => {
|
2025-10-25 17:44:41 +02:00
|
|
|
fileActionManager.applyToFile(item.getFileId(), (file) => {
|
2024-09-10 16:52:21 +02:00
|
|
|
if (item instanceof ListFileItem && node instanceof GPXFile) {
|
|
|
|
|
file.metadata.name = name;
|
|
|
|
|
file.metadata.desc = description;
|
|
|
|
|
if (file.trk.length === 1) {
|
|
|
|
|
file.trk[0].name = name;
|
|
|
|
|
}
|
|
|
|
|
} else if (item instanceof ListTrackItem && node instanceof Track) {
|
|
|
|
|
file.trk[item.getTrackIndex()].name = name;
|
|
|
|
|
file.trk[item.getTrackIndex()].desc = description;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
open = false;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Save size="16" class="mr-1" />
|
2025-06-21 21:07:36 +02:00
|
|
|
{i18n._('menu.metadata.save')}
|
2024-09-10 16:52:21 +02:00
|
|
|
</Button>
|
|
|
|
|
</Popover.Content>
|
2024-06-27 17:14:35 +02:00
|
|
|
</Popover.Root>
|