vertical and horizontal file list with same component

This commit is contained in:
vcoppe
2024-05-21 17:47:08 +02:00
parent 44b270e2c2
commit d50fdf20a7
7 changed files with 118 additions and 89 deletions

View File

@@ -4,8 +4,8 @@
import type { GPXFileWithStatistics } from '$lib/db';
import type { Readable } from 'svelte/store';
import FileListNodeContent from './FileListNodeContent.svelte';
import { createEventDispatcher } from 'svelte';
import FileListNodeLabel from './FileListNodeLabel.svelte';
import { getContext } from 'svelte';
export let node:
| Map<string, Readable<GPXFileWithStatistics | undefined>>
@@ -14,30 +14,27 @@
export let id: string;
export let index: number = 0;
const dispatch = createEventDispatcher();
let recursive = getContext<boolean>('recursive');
function forwardId() {
dispatch('click', { id });
}
let label =
node instanceof GPXFile
? node.metadata.name
: node instanceof Track
? node.name ?? `Track ${index + 1}`
: Array.isArray(node) && node.length > 0 && node[0] instanceof Waypoint
? 'Waypoints'
: '';
</script>
{#if node instanceof Map}
<FileListNodeContent {node} {id} />
{:else}
<CollapsibleTreeNode {id} on:click={forwardId}>
<FileListNodeLabel
{id}
label={node instanceof GPXFile
? node.metadata.name
: node instanceof Track
? node.name ?? `Track ${index + 1}`
: Array.isArray(node) && node.length > 0 && node[0] instanceof Waypoint
? 'Waypoints'
: ''}
slot="trigger"
/>
{:else if recursive}
<CollapsibleTreeNode {id}>
<FileListNodeLabel {id} {label} slot="trigger" />
<div slot="content">
<FileListNodeContent {node} {id} />
</div>
</CollapsibleTreeNode>
{:else}
<FileListNodeLabel {id} {label} />
{/if}