cleaner updates

This commit is contained in:
vcoppe
2024-04-22 17:33:30 +02:00
parent 8f6c1fc88d
commit 32b15feb0a
2 changed files with 34 additions and 19 deletions

View File

@@ -4,15 +4,17 @@
import { GPXStatistics } from 'gpx';
import { selectedFiles } from '$lib/stores';
import { fileCollection, selectedFiles } from '$lib/stores';
import { MoveDownRight, MoveUpRight, Ruler, Timer, Zap } from 'lucide-svelte';
let gpxData: GPXStatistics = new GPXStatistics();
$: {
gpxData = new GPXStatistics();
$selectedFiles.forEach((file) => {
gpxData.mergeWith(file.statistics);
$fileCollection.files.forEach((file) => {
if ($selectedFiles.has(file)) {
gpxData.mergeWith(file.statistics);
}
});
}

View File

@@ -72,26 +72,32 @@ export function duplicateFile(file: GPXFile) {
}
export function removeSelectedFiles() {
let index = 0;
while (index < get(fileCollection).files.length) {
if (get(selectedFiles).has(get(fileCollection).files[index])) {
fileCollection.update($files => {
$files.files.splice(index, 1);
return $files;
});
} else {
index++;
fileCollection.update($collection => {
let index = 0;
while (index < $collection.files.length) {
if (get(selectedFiles).has($collection.files[index])) {
$collection.files.splice(index, 1);
} else {
index++;
}
}
}
get(selectedFiles).clear();
return $collection;
});
selectedFiles.update($selected => {
$selected.clear();
return $selected;
});
}
export function removeAllFiles() {
fileCollection.update($files => {
$files.files.splice(0, $files.files.length);
return $files;
fileCollection.update($collection => {
$collection.files.splice(0, $collection.files.length);
return $collection;
});
selectedFiles.update($selected => {
$selected.clear();
return $selected;
});
get(selectedFiles).clear();
}
export function exportSelectedFiles() {
@@ -116,5 +122,12 @@ export function exportFile(file: GPXFile) {
}
export function reverseSelectedFiles() {
get(selectedFiles).forEach(file => file.reverse());
fileCollection.update($files => {
$files.files.forEach(file => {
if (get(selectedFiles).has(file)) {
file.reverse();
}
});
return $files;
});
}