mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-02 16:52:31 +00:00
remove duplicate logic
This commit is contained in:
@@ -26,7 +26,6 @@
|
|||||||
// remove controls for deleted files
|
// remove controls for deleted files
|
||||||
routingControls.forEach((controls, fileId) => {
|
routingControls.forEach((controls, fileId) => {
|
||||||
if (!get(filestore).find((file) => file._data.id === fileId)) {
|
if (!get(filestore).find((file) => file._data.id === fileId)) {
|
||||||
console.log('remove controls for deleted file', fileId);
|
|
||||||
controls.remove();
|
controls.remove();
|
||||||
routingControls.delete(fileId);
|
routingControls.delete(fileId);
|
||||||
|
|
||||||
@@ -38,7 +37,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: if ($map && $selectedFiles) {
|
$: if ($map && $selectedFiles) {
|
||||||
console.log('selectedFiles', $selectedFiles);
|
|
||||||
// update selected file
|
// update selected file
|
||||||
if ($selectedFiles.size == 0 || $selectedFiles.size > 1 || !active) {
|
if ($selectedFiles.size == 0 || $selectedFiles.size > 1 || !active) {
|
||||||
if (selectedId) {
|
if (selectedId) {
|
||||||
@@ -54,14 +52,12 @@
|
|||||||
selectedId = newSelectedId;
|
selectedId = newSelectedId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log('selectedId', selectedId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if ($map && selectedId) {
|
$: if ($map && selectedId) {
|
||||||
if (!routingControls.has(selectedId)) {
|
if (!routingControls.has(selectedId)) {
|
||||||
let selectedFileStore = filestore.getFileStore(selectedId);
|
let selectedFileStore = filestore.getFileStore(selectedId);
|
||||||
if (selectedFileStore) {
|
if (selectedFileStore) {
|
||||||
console.log('add controls for selected file', selectedId);
|
|
||||||
routingControls.set(
|
routingControls.set(
|
||||||
selectedId,
|
selectedId,
|
||||||
new RoutingControls(get(map), selectedFileStore, popup, popupElement)
|
new RoutingControls(get(map), selectedFileStore, popup, popupElement)
|
||||||
|
@@ -88,7 +88,6 @@ export function createGPXFileStore(): GPXFileStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (global) {
|
if (global) {
|
||||||
console.log("Global patch", patch);
|
|
||||||
notify();
|
notify();
|
||||||
}
|
}
|
||||||
updateUndoRedo();
|
updateUndoRedo();
|
||||||
@@ -181,19 +180,11 @@ export function createGPXFileStore(): GPXFileStore {
|
|||||||
draft.delete(fileId);
|
draft.delete(fileId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
selectedFiles.update($selected => {
|
|
||||||
$selected.clear();
|
|
||||||
return $selected;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
deleteAllFiles: () => {
|
deleteAllFiles: () => {
|
||||||
applyToGlobalStore((draft) => {
|
applyToGlobalStore((draft) => {
|
||||||
draft.clear();
|
draft.clear();
|
||||||
});
|
});
|
||||||
selectedFiles.update($selected => {
|
|
||||||
$selected.clear();
|
|
||||||
return $selected;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getFileStore: (id: string) => {
|
getFileStore: (id: string) => {
|
||||||
return filestores.get(id);
|
return filestores.get(id);
|
||||||
|
@@ -14,7 +14,7 @@ export const fileOrder = writable<string[]>([]);
|
|||||||
export const selectedFiles = writable<Set<string>>(new Set());
|
export const selectedFiles = writable<Set<string>>(new Set());
|
||||||
export const selectFiles = writable<{ [key: string]: (fileId?: string) => void }>({});
|
export const selectFiles = writable<{ [key: string]: (fileId?: string) => void }>({});
|
||||||
|
|
||||||
filestore.subscribe((files) => { // Update selectedFiles if a file is deleted
|
filestore.subscribe((files) => { // Update selectedFiles automatically when files are deleted (either by action or by undo-redo)
|
||||||
let deletedFileIds: string[] = [];
|
let deletedFileIds: string[] = [];
|
||||||
get(selectedFiles).forEach((fileId) => {
|
get(selectedFiles).forEach((fileId) => {
|
||||||
if (!files.find((f) => f._data.id === fileId)) {
|
if (!files.find((f) => f._data.id === fileId)) {
|
||||||
|
Reference in New Issue
Block a user