From 9df014e986d98c7a983503493f29190c59555815 Mon Sep 17 00:00:00 2001 From: vcoppe Date: Sun, 9 Nov 2025 19:00:33 +0100 Subject: [PATCH] fix sortable --- website/src/lib/components/file-list/FileList.svelte | 11 +---------- .../components/file-list/FileListNodeContent.svelte | 2 +- .../lib/components/file-list/sortable-file-list.ts | 12 +++++++----- website/src/routes/[[language]]/app/+page.svelte | 4 ++-- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/website/src/lib/components/file-list/FileList.svelte b/website/src/lib/components/file-list/FileList.svelte index ad2b48e59..30d43dc13 100644 --- a/website/src/lib/components/file-list/FileList.svelte +++ b/website/src/lib/components/file-list/FileList.svelte @@ -28,16 +28,7 @@ setContext('recursive', recursive); onMount(() => { - if (orientation === 'vertical') { - selection.update(($selection) => { - $selection.forEach((item) => { - if ($selection.hasAnyChildren(item, false)) { - $selection.toggle(item); - } - }); - return $selection; - }); - } else { + if (orientation === 'horizontal') { selection.update(($selection) => { $selection.forEach((item) => { if (!(item instanceof ListFileItem)) { diff --git a/website/src/lib/components/file-list/FileListNodeContent.svelte b/website/src/lib/components/file-list/FileListNodeContent.svelte index 1d7d63848..0cb2afb7f 100644 --- a/website/src/lib/components/file-list/FileListNodeContent.svelte +++ b/website/src/lib/components/file-list/FileListNodeContent.svelte @@ -54,7 +54,7 @@ }); $effect(() => { - if (sortable) { + if (sortable && node) { sortable.updateElements(); } }); diff --git a/website/src/lib/components/file-list/sortable-file-list.ts b/website/src/lib/components/file-list/sortable-file-list.ts index bc67d8369..a0902dc19 100644 --- a/website/src/lib/components/file-list/sortable-file-list.ts +++ b/website/src/lib/components/file-list/sortable-file-list.ts @@ -7,6 +7,7 @@ import { get, writable, type Readable } from 'svelte/store'; import { settings } from '$lib/logic/settings'; import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree'; import type { AnyGPXTreeElement, GPXTreeElement, Waypoint } from 'gpx'; +import { tick } from 'svelte'; const { fileOrder } = settings; @@ -89,7 +90,9 @@ export class SortableFileList { writable: true, }); - this._unsubscribes.push(selection.subscribe(() => this.updateFromSelection())); + this._unsubscribes.push( + selection.subscribe(() => tick().then(() => this.updateFromSelection())) + ); this._unsubscribes.push(fileOrder.subscribe(() => this.updateFromFileOrder())); } @@ -172,9 +175,8 @@ export class SortableFileList { } updateToSelection(e: Sortable.SortableEvent) { - if (this._updatingSelection) { - return; - } + if (!this._sortable) return; + if (this._updatingSelection) return; this._updatingSelection = true; const changed = this.getChangedIds(); if (changed.length == 0) { @@ -200,7 +202,6 @@ export class SortableFileList { $selection.clear(); $selection.set(this._item.extend(this.getRealId(changed[0])), true); } - return $selection; }); this._updatingSelection = false; @@ -255,6 +256,7 @@ export class SortableFileList { } destroy() { + this._sortable = null; this._unsubscribes.forEach((unsubscribe) => unsubscribe()); this._unsubscribes = []; } diff --git a/website/src/routes/[[language]]/app/+page.svelte b/website/src/routes/[[language]]/app/+page.svelte index 4fe675c4b..d4765ba36 100644 --- a/website/src/routes/[[language]]/app/+page.svelte +++ b/website/src/routes/[[language]]/app/+page.svelte @@ -52,13 +52,13 @@ }); } - fileStateCollection.connectToDatabase(db); settings.connectToDatabase(db); + fileStateCollection.connectToDatabase(db); }); onDestroy(() => { - fileStateCollection.disconnectFromDatabase(); settings.disconnectFromDatabase(); + fileStateCollection.disconnectFromDatabase(); });