From 346b9a1186497d313465992ec0838b448728f42b Mon Sep 17 00:00:00 2001 From: evlist Date: Sun, 27 Nov 2022 14:32:21 +0100 Subject: [PATCH] Creating a `` component. --- src/components/all-gpxes/AllGpxes.tsx | 33 +++++++++++++++++++++++++++ src/components/all-gpxes/index.ts | 1 + src/components/map/Map.tsx | 2 ++ src/db/gpx.ts | 4 ++++ src/workers/dispatcher-worker.ts | 4 +++- 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/components/all-gpxes/AllGpxes.tsx create mode 100644 src/components/all-gpxes/index.ts diff --git a/src/components/all-gpxes/AllGpxes.tsx b/src/components/all-gpxes/AllGpxes.tsx new file mode 100644 index 0000000..41df037 --- /dev/null +++ b/src/components/all-gpxes/AllGpxes.tsx @@ -0,0 +1,33 @@ +import { + Component, + createEffect, + createResource, + createSignal, +} from 'solid-js'; + +import OlMap from 'ol/Map'; + +import dispatch from '../../workers/dispatcher-main'; +// import Gpx from './Gpx'; + +interface Props { + map: OlMap | null; +} + +export const AllGpxes: Component = ({ map }) => { + const [allGpxes] = createResource( + async () => + await dispatch({ + action: 'getAllGpxes', + params: {}, + }) + ); + + createEffect(() => { + console.log({ caller: 'AllGpxes', allGpxes: allGpxes() }); + }); + + return <>; +}; + +export default AllGpxes; diff --git a/src/components/all-gpxes/index.ts b/src/components/all-gpxes/index.ts new file mode 100644 index 0000000..540dbdb --- /dev/null +++ b/src/components/all-gpxes/index.ts @@ -0,0 +1 @@ +export { default } from './AllGpxes'; diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 99dc30f..b205fdb 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -22,6 +22,7 @@ import GetLocation, { getCurrentLocation } from '../get-location'; import ShowLocationIcon from '../get-location/ShowLocationIcon.svg'; import { Back, Forward } from '../back-forward'; import GpxImport from '../gpx-import'; +import AllGpxes from '../all-gpxes'; const [getState, setState] = createSignal({ lon: 0, @@ -184,6 +185,7 @@ const Map: Component = () => { + ); }; diff --git a/src/db/gpx.ts b/src/db/gpx.ts index cd08027..bbb2e14 100644 --- a/src/db/gpx.ts +++ b/src/db/gpx.ts @@ -186,6 +186,10 @@ export const pruneAndSaveImportedGpx = async (params: any) => { } }; +export const getAllGpxes = async () => { + return await getDocsByType('gpx'); +}; + export const getGpxesForViewport = async (params: any) => { const { viewport, zoomLevel } = params; const zoomedViewport: Rectangle = { diff --git a/src/workers/dispatcher-worker.ts b/src/workers/dispatcher-worker.ts index a32090c..5393375 100644 --- a/src/workers/dispatcher-worker.ts +++ b/src/workers/dispatcher-worker.ts @@ -6,11 +6,12 @@ import { pruneAndSaveImportedGpx, getGpxesForViewport, getGpx, + getAllGpxes, } from '../db/gpx'; import { getTrk, putNewTrk } from '../db/trk'; import { getTrkseg } from '../db/trkseg'; -const self = globalThis as unknown as WorkerGlobalScope; +//const self = globalThis as unknown as WorkerGlobalScope; const actions = { initDb, @@ -18,6 +19,7 @@ const actions = { putNewTrk, existsGpx, pruneAndSaveImportedGpx, + getAllGpxes, getGpxesForViewport, getGpx, getTrk,