fix sortable

This commit is contained in:
vcoppe
2025-11-09 19:00:33 +01:00
parent 39b8d2e70d
commit 9df014e986
4 changed files with 11 additions and 18 deletions

View File

@@ -28,16 +28,7 @@
setContext('recursive', recursive); setContext('recursive', recursive);
onMount(() => { onMount(() => {
if (orientation === 'vertical') { if (orientation === 'horizontal') {
selection.update(($selection) => {
$selection.forEach((item) => {
if ($selection.hasAnyChildren(item, false)) {
$selection.toggle(item);
}
});
return $selection;
});
} else {
selection.update(($selection) => { selection.update(($selection) => {
$selection.forEach((item) => { $selection.forEach((item) => {
if (!(item instanceof ListFileItem)) { if (!(item instanceof ListFileItem)) {

View File

@@ -54,7 +54,7 @@
}); });
$effect(() => { $effect(() => {
if (sortable) { if (sortable && node) {
sortable.updateElements(); sortable.updateElements();
} }
}); });

View File

@@ -7,6 +7,7 @@ import { get, writable, type Readable } from 'svelte/store';
import { settings } from '$lib/logic/settings'; import { settings } from '$lib/logic/settings';
import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree'; import type { GPXFileWithStatistics } from '$lib/logic/statistics-tree';
import type { AnyGPXTreeElement, GPXTreeElement, Waypoint } from 'gpx'; import type { AnyGPXTreeElement, GPXTreeElement, Waypoint } from 'gpx';
import { tick } from 'svelte';
const { fileOrder } = settings; const { fileOrder } = settings;
@@ -89,7 +90,9 @@ export class SortableFileList {
writable: true, 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())); this._unsubscribes.push(fileOrder.subscribe(() => this.updateFromFileOrder()));
} }
@@ -172,9 +175,8 @@ export class SortableFileList {
} }
updateToSelection(e: Sortable.SortableEvent) { updateToSelection(e: Sortable.SortableEvent) {
if (this._updatingSelection) { if (!this._sortable) return;
return; if (this._updatingSelection) return;
}
this._updatingSelection = true; this._updatingSelection = true;
const changed = this.getChangedIds(); const changed = this.getChangedIds();
if (changed.length == 0) { if (changed.length == 0) {
@@ -200,7 +202,6 @@ export class SortableFileList {
$selection.clear(); $selection.clear();
$selection.set(this._item.extend(this.getRealId(changed[0])), true); $selection.set(this._item.extend(this.getRealId(changed[0])), true);
} }
return $selection; return $selection;
}); });
this._updatingSelection = false; this._updatingSelection = false;
@@ -255,6 +256,7 @@ export class SortableFileList {
} }
destroy() { destroy() {
this._sortable = null;
this._unsubscribes.forEach((unsubscribe) => unsubscribe()); this._unsubscribes.forEach((unsubscribe) => unsubscribe());
this._unsubscribes = []; this._unsubscribes = [];
} }

View File

@@ -52,13 +52,13 @@
}); });
} }
fileStateCollection.connectToDatabase(db);
settings.connectToDatabase(db); settings.connectToDatabase(db);
fileStateCollection.connectToDatabase(db);
}); });
onDestroy(() => { onDestroy(() => {
fileStateCollection.disconnectFromDatabase();
settings.disconnectFromDatabase(); settings.disconnectFromDatabase();
fileStateCollection.disconnectFromDatabase();
}); });
</script> </script>