Adding a basic mechanism to choose overlays (not operational yet)

This commit is contained in:
vdv committed 2023-01-21 17:13:25 +01:00
1 parent 82e38308a4
commit 8ddbe1bdee
9 files changed
+240 -45

No files matched your search

+5 -1
View File
@@ -3,6 +3,7 @@ import { getWpt } from '../db/wpt';
import { returnAgain } from '../workers/dispatcher-worker';
import { getAllGpxes, getGpx } from './gpx';
import { put } from './lib';
import { getOverlays } from './overlays';
import { getRte } from './rte';
import { getTrk } from './trk';
import { getTrkseg } from './trkseg';
@@ -18,6 +19,7 @@ const methods = {
getTrkseg,
getWpt,
getRte,
getOverlays,
};
const sendUpdate = async (params: any) => {
@@ -79,7 +81,9 @@ const changeHandler = async (change: any) => {
}
const parentParams = globalThis.watches.get(parentId);
debouncedSendUpdates[parentParams.method](parentParams);
if (parentParams) {
debouncedSendUpdates[parentParams.method](parentParams);
}
};
export default changeHandler;
+10
View File
@@ -136,6 +136,16 @@ export const initDb = async (params: any) => {
console.log({ caller: 'changes / complete', error });
});
const localDbChanges = localDb
.changes({ since: 'now', live: true, include_docs: false })
.on('change', changeHandler)
.on('complete', (info: any) => {
console.log({ caller: 'localDb changes / complete', info });
})
.on('error', (error: any) => {
console.log({ caller: 'localDb changes / complete', error });
});
// console.log({ caller: 'initDb / back from db.changes', changes });
// changes.cancel();
+18
View File
@@ -0,0 +1,18 @@
import { get, put } from './lib';
export const getOverlays = async (params: any) => {
const { id, defaultOverlays } = params;
try {
const overlays = await get(id, true);
return overlays.doc;
} catch (error: any) {
console.error({ caller: 'getOverlays', error });
return defaultOverlays;
}
};
export const putOverlays = async (params: any) => {
const { id, overlays } = params;
await put(id, 'overlays', (doc) => overlays, {}, true);
return overlays;
};