mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
rename track when renaming file if it only contains one track, closes #75
This commit is contained in:
@@ -1,62 +1,65 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { Input } from '$lib/components/ui/input';
|
import { Input } from '$lib/components/ui/input';
|
||||||
import { Textarea } from '$lib/components/ui/textarea';
|
import { Textarea } from '$lib/components/ui/textarea';
|
||||||
import { Label } from '$lib/components/ui/label/index.js';
|
import { Label } from '$lib/components/ui/label/index.js';
|
||||||
import * as Popover from '$lib/components/ui/popover';
|
import * as Popover from '$lib/components/ui/popover';
|
||||||
import { dbUtils } from '$lib/db';
|
import { dbUtils } from '$lib/db';
|
||||||
import { Save } from 'lucide-svelte';
|
import { Save } from 'lucide-svelte';
|
||||||
import { ListFileItem, ListTrackItem, type ListItem } from './FileList';
|
import { ListFileItem, ListTrackItem, type ListItem } from './FileList';
|
||||||
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
import { GPXTreeElement, Track, type AnyGPXTreeElement, Waypoint, GPXFile } from 'gpx';
|
||||||
import { _ } from 'svelte-i18n';
|
import { _ } from 'svelte-i18n';
|
||||||
import { editMetadata } from '$lib/stores';
|
import { editMetadata } from '$lib/stores';
|
||||||
|
|
||||||
export let node: GPXTreeElement<AnyGPXTreeElement> | Waypoint[] | Waypoint;
|
export let node: GPXTreeElement<AnyGPXTreeElement> | Waypoint[] | Waypoint;
|
||||||
export let item: ListItem;
|
export let item: ListItem;
|
||||||
export let open = false;
|
export let open = false;
|
||||||
|
|
||||||
let name: string =
|
let name: string =
|
||||||
node instanceof GPXFile
|
node instanceof GPXFile
|
||||||
? node.metadata.name ?? ''
|
? node.metadata.name ?? ''
|
||||||
: node instanceof Track
|
: node instanceof Track
|
||||||
? node.name ?? ''
|
? node.name ?? ''
|
||||||
: '';
|
: '';
|
||||||
let description: string =
|
let description: string =
|
||||||
node instanceof GPXFile
|
node instanceof GPXFile
|
||||||
? node.metadata.desc ?? ''
|
? node.metadata.desc ?? ''
|
||||||
: node instanceof Track
|
: node instanceof Track
|
||||||
? node.desc ?? ''
|
? node.desc ?? ''
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
$: if (!open) {
|
$: if (!open) {
|
||||||
$editMetadata = false;
|
$editMetadata = false;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Popover.Root bind:open>
|
<Popover.Root bind:open>
|
||||||
<Popover.Trigger />
|
<Popover.Trigger />
|
||||||
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
<Popover.Content side="top" sideOffset={22} alignOffset={30} class="flex flex-col gap-3">
|
||||||
<Label for="name">{$_('menu.metadata.name')}</Label>
|
<Label for="name">{$_('menu.metadata.name')}</Label>
|
||||||
<Input bind:value={name} id="name" class="font-semibold h-8" />
|
<Input bind:value={name} id="name" class="font-semibold h-8" />
|
||||||
<Label for="description">{$_('menu.metadata.description')}</Label>
|
<Label for="description">{$_('menu.metadata.description')}</Label>
|
||||||
<Textarea bind:value={description} id="description" />
|
<Textarea bind:value={description} id="description" />
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
dbUtils.applyToFile(item.getFileId(), (file) => {
|
dbUtils.applyToFile(item.getFileId(), (file) => {
|
||||||
if (item instanceof ListFileItem && node instanceof GPXFile) {
|
if (item instanceof ListFileItem && node instanceof GPXFile) {
|
||||||
file.metadata.name = name;
|
file.metadata.name = name;
|
||||||
file.metadata.desc = description;
|
file.metadata.desc = description;
|
||||||
} else if (item instanceof ListTrackItem && node instanceof Track) {
|
if (file.trk.length === 1) {
|
||||||
file.trk[item.getTrackIndex()].name = name;
|
file.trk[0].name = name;
|
||||||
file.trk[item.getTrackIndex()].desc = description;
|
}
|
||||||
}
|
} else if (item instanceof ListTrackItem && node instanceof Track) {
|
||||||
});
|
file.trk[item.getTrackIndex()].name = name;
|
||||||
open = false;
|
file.trk[item.getTrackIndex()].desc = description;
|
||||||
}}
|
}
|
||||||
>
|
});
|
||||||
<Save size="16" class="mr-1" />
|
open = false;
|
||||||
{$_('menu.metadata.save')}
|
}}
|
||||||
</Button>
|
>
|
||||||
</Popover.Content>
|
<Save size="16" class="mr-1" />
|
||||||
|
{$_('menu.metadata.save')}
|
||||||
|
</Button>
|
||||||
|
</Popover.Content>
|
||||||
</Popover.Root>
|
</Popover.Root>
|
||||||
|
Reference in New Issue
Block a user