Still working on trk delete.

This commit is contained in:
Eric van der Vlist 2023-01-09 14:23:41 +01:00
parent 45f7c797e7
commit 9931887f03
6 changed files with 41 additions and 14 deletions

View File

@ -1,10 +1,4 @@
import { import { Component, createEffect, For, onCleanup, Suspense } from 'solid-js';
Component,
createEffect,
For,
onCleanup,
Suspense,
} from 'solid-js';
import OlMap from 'ol/Map'; import OlMap from 'ol/Map';
@ -33,6 +27,13 @@ export const Gpx: Component<Props> = ({ map, gpxId }) => {
const gpx = createCachedSignal(params); const gpx = createCachedSignal(params);
onCleanup(() => { onCleanup(() => {
console.log({
caller: 'Gpx / onCleanup',
gpxId,
gpx: gpx(),
params,
});
destroyCachedSignal(params); destroyCachedSignal(params);
}); });

View File

@ -22,6 +22,13 @@ export const Rte: Component<Props> = ({ vectorSource, rteId, context }) => {
const rte = createCachedSignal(params); const rte = createCachedSignal(params);
onCleanup(() => { onCleanup(() => {
console.log({
caller: 'Rte / onCleanup',
rteId,
rte: rte(),
params,
});
destroyCachedSignal(params); destroyCachedSignal(params);
}); });

View File

@ -33,6 +33,7 @@ export const Trk: Component<Props> = ({ vectorSource, trkId, context }) => {
const trk = createCachedSignal(params); const trk = createCachedSignal(params);
onCleanup(() => { onCleanup(() => {
console.log({ caller: 'Trk / onCleanup', trkId, trk: trk(), params });
destroyCachedSignal(params); destroyCachedSignal(params);
}); });

View File

@ -25,8 +25,24 @@ export const Trkseg: Component<Props> = ({
}; };
const trkseg = createCachedSignal(params); const trkseg = createCachedSignal(params);
const clearFeatures = () => {
[`${trksegId}/start`, trksegId, `${trksegId}/end`].forEach((id) => {
const feature = vectorSource.getFeatureById(id);
if (feature) {
vectorSource.removeFeature(feature);
}
});
};
onCleanup(() => { onCleanup(() => {
console.log({
caller: 'Trkseg / onCleanup',
trksegId,
trkseg: trkseg(),
params,
});
destroyCachedSignal(params); destroyCachedSignal(params);
clearFeatures();
}); });
createEffect(() => { createEffect(() => {
@ -86,12 +102,7 @@ export const Trkseg: Component<Props> = ({
const features = new GeoJSON().readFeatures(geo); const features = new GeoJSON().readFeatures(geo);
console.log({ caller: 'Trkseg', features }); console.log({ caller: 'Trkseg', features });
[`${trksegId}/start`, trksegId, `${trksegId}/end`].forEach((id) => { clearFeatures();
const feature = vectorSource.getFeatureById(id);
if (feature) {
vectorSource.removeFeature(feature);
}
});
vectorSource.addFeatures(features); vectorSource.addFeatures(features);
} }
}); });

View File

@ -38,6 +38,13 @@ export const Wpt: Component<Props> = ({
const wpt = createCachedSignal(params); const wpt = createCachedSignal(params);
onCleanup(() => { onCleanup(() => {
console.log({
caller: 'Wpt / onCleanup',
wptId,
wpt: wpt(),
params,
});
destroyCachedSignal(params); destroyCachedSignal(params);
}); });

View File

@ -57,7 +57,7 @@ export const deleteTrk = async (params: any) => {
const { id } = params; const { id } = params;
const docs = await getFamily(id, { include_docs: false }); const docs = await getFamily(id, { include_docs: false });
console.log({ caller: 'deleteTrk' }, id, docs); console.log({ caller: 'deleteTrk' }, id, docs);
const deletedDocs = docs.rows.map((doc: any) => ({ const deletedDocs = docs.rows.reverse().map((doc: any) => ({
_deleted: true, _deleted: true,
_id: doc.id, _id: doc.id,
_rev: doc.value.rev, _rev: doc.value.rev,