fix hiding

This commit is contained in:
vcoppe
2025-10-19 13:45:05 +02:00
parent 05df3ca064
commit 3f103323c7
7 changed files with 172 additions and 143 deletions

View File

@@ -14,7 +14,6 @@ import { settings } from '$lib/logic/settings';
import type { GPXFile } from 'gpx';
import { get, writable, type Readable, type Writable } from 'svelte/store';
import { SelectionTreeType } from '$lib/logic/selection-tree';
import { tick } from 'svelte';
export class Selection {
private _selection: Writable<SelectionTreeType>;
@@ -254,3 +253,33 @@ export function applyToOrderedItemsFromFile(
}
});
}
export class SelectedGPXFilesObserver {
private _fileStateCollectionObserver: GPXFileStateCollectionObserver;
private _unsubscribes: Map<string, () => void> = new Map();
constructor(onSelectedFileChange: () => void) {
this._unsubscribes = new Map();
this._fileStateCollectionObserver = new GPXFileStateCollectionObserver(
(fileId, fileState) => {
this._unsubscribes.set(
fileId,
fileState.subscribe(() => {
if (get(selection).hasAnyChildren(new ListFileItem(fileId))) {
onSelectedFileChange();
}
})
);
},
(fileId) => {
this._unsubscribes.get(fileId)?.();
this._unsubscribes.delete(fileId);
},
() => {
this._unsubscribes.forEach((unsubscribe) => unsubscribe());
this._unsubscribes.clear();
}
);
selection.subscribe(() => onSelectedFileChange());
}
}