From ab7374f3600b216a3a7de1320369f22737ef6f50 Mon Sep 17 00:00:00 2001 From: evlist Date: Sun, 27 Nov 2022 16:18:50 +0100 Subject: [PATCH] `` component --- src/components/trk/Trk.tsx | 14 +++++++++++--- src/components/trkseg/Trkseg.tsx | 32 ++++++++++++++++++++++++++++++++ src/components/trkseg/index.ts | 1 + src/db/trkseg.ts | 19 +++++++++++++++++-- 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 src/components/trkseg/Trkseg.tsx create mode 100644 src/components/trkseg/index.ts diff --git a/src/components/trk/Trk.tsx b/src/components/trk/Trk.tsx index f347c93..f1d9156 100644 --- a/src/components/trk/Trk.tsx +++ b/src/components/trk/Trk.tsx @@ -1,11 +1,11 @@ -import { Component, createEffect, createResource } from 'solid-js'; +import { Component, createEffect, createResource, For } from 'solid-js'; import OlMap from 'ol/Map'; import dispatch from '../../workers/dispatcher-main'; import getUri from '../../lib/ids'; -//import Trkseg from './Trkseg'; +import Trkseg from '../trkseg'; interface Props { trkId: string; @@ -27,7 +27,15 @@ export const Trk: Component = ({ map, trkId }) => { console.log({ caller: 'Trk', map: map(), trkId, trk: trk() }); }); - return <>; + return ( + // @ts-ignore + + {(trksegId: string) => { + console.log({ caller: 'Trk / loop', trksegId }); + return ; + }} + + ); }; export default Trk; diff --git a/src/components/trkseg/Trkseg.tsx b/src/components/trkseg/Trkseg.tsx new file mode 100644 index 0000000..b918449 --- /dev/null +++ b/src/components/trkseg/Trkseg.tsx @@ -0,0 +1,32 @@ +import { Component, createEffect, createResource } from 'solid-js'; + +import OlMap from 'ol/Map'; + +import dispatch from '../../workers/dispatcher-main'; +import getUri from '../../lib/ids'; + +interface Props { + trksegId: string; + map: () => OlMap | null; +} + +export const Trkseg: Component = ({ map, trksegId }) => { + const [trkseg] = createResource( + trksegId, + async () => + await dispatch({ + action: 'getTrkseg', + params: { + id: trksegId, + }, + }) + ); + + createEffect(() => { + console.log({ caller: 'Trkseg', map: map(), trksegId, trkseg: trkseg() }); + }); + + return <>; +}; + +export default Trkseg; diff --git a/src/components/trkseg/index.ts b/src/components/trkseg/index.ts new file mode 100644 index 0000000..fe197ad --- /dev/null +++ b/src/components/trkseg/index.ts @@ -0,0 +1 @@ +export { default } from './Trkseg'; diff --git a/src/db/trkseg.ts b/src/db/trkseg.ts index b6ad518..7c2946e 100644 --- a/src/db/trkseg.ts +++ b/src/db/trkseg.ts @@ -1,4 +1,5 @@ import getUri from '../lib/ids'; +import { appendToArray } from './gpx'; import { getFamily, put } from './lib'; import { putNewTrk } from './trk'; @@ -28,6 +29,20 @@ export const putNewTrkseg = async (id?: IdTrk | IdGpx | IdTrkseg) => { export const getTrkseg = async (params: any) => { const { id } = params; const docs = await getFamily(id, { include_docs: true }); - console.log(`getTrkseg, uri: ${id} docs: ${JSON.stringify(docs)}`); - return docs.rows; + let target: any[]; + let trkseg: Trkseg | undefined = undefined; + docs.rows.forEach((row: any) => { + // level 0 + if (row.doc.type === 'trkseg') { + target = [row.doc.doc]; + trkseg = row.doc.doc; + } + //level 1 + if (row.doc.type === 'trkpt') { + target.splice(1); + appendToArray(target.at(-1), row.doc.type, row.doc._id); + target.push(row.doc.doc); + } + }); + return trkseg; };