From 45f7c797e7cd6f85be658c4bec45d6a431ad12fa Mon Sep 17 00:00:00 2001 From: evlist Date: Sun, 8 Jan 2023 22:05:08 +0100 Subject: [PATCH] Implementing a delete method for tracks. --- src/components/trk/TrkViewer.tsx | 114 ++++++++++++++++++++++++------- src/db/trk.ts | 14 ++++ src/workers/dispatcher-worker.ts | 4 +- 3 files changed, 107 insertions(+), 25 deletions(-) diff --git a/src/components/trk/TrkViewer.tsx b/src/components/trk/TrkViewer.tsx index 7c7db67..cedcbee 100644 --- a/src/components/trk/TrkViewer.tsx +++ b/src/components/trk/TrkViewer.tsx @@ -1,8 +1,12 @@ -import { Component, For } from 'solid-js'; +import { Component, createSignal, For, Show } from 'solid-js'; import { peekCachedSignal } from '../../workers/cached-signals'; import Tree from '../tree'; import TrkIcon from '../../icons/human-footprints-svgrepo-com.svg?component-solid'; import { TrksegViewer } from '../trkseg'; +import { Alert, Button, IconButton } from '@suid/material'; +import DeleteIcon from '@suid/icons-material/Delete'; +import QuestionMarkIcon from '@suid/icons-material/QuestionMark'; +import dispatch from '../../workers/dispatcher-main'; interface Props { trkId: string; @@ -12,35 +16,97 @@ interface Props { const TrkViewer: Component = ({ trkId, restrictToHierarchy }) => { const trk = peekCachedSignal({ id: trkId, method: 'getTrk' }); console.log({ caller: 'TrkViewer', trkId, restrictToHierarchy, trk: trk() }); + + const [confirmDelete, setConfirmDelete] = createSignal(false); + const title = () => { return trk().name; }; + const confirmDeleteHandler = () => { + console.log({ + caller: 'TrkViewer / confirmDeleteHandler', + trkId, + }); + setConfirmDelete(true); + }; + + const deleteHandler = () => { + console.log({ + caller: 'TrkViewer / deleteHandler', + trkId, + }); + dispatch({ action: 'deleteTrk', params: { id: trkId } }); + setConfirmDelete(false); + }; + + const cancelDeleteHandler = () => { + console.log({ + caller: 'TrkViewer / cancelDeleteHandler', + trkId, + }); + setConfirmDelete(false); + }; + return ( - -
- - {title()} - -
-
x
- - } - content={
} - subTree={ - - key.startsWith('gpx/') - )} + <> + +
+ + {title()} + +
+
+ + + +
+ + } + content={
} + subTree={ + + key.startsWith('gpx/') + )} + > + {(key: string) => { + return ; + }} + + } + /> + + } + action={ + <> + + + + } > - {(key: string) => { - return ; - }} -
- } - /> + Delete this track ? + + + ); }; diff --git a/src/db/trk.ts b/src/db/trk.ts index f595a10..d42872a 100644 --- a/src/db/trk.ts +++ b/src/db/trk.ts @@ -52,3 +52,17 @@ export const getTrk = async (params: any) => { }); return trk; }; + +export const deleteTrk = async (params: any) => { + const { id } = params; + const docs = await getFamily(id, { include_docs: false }); + console.log({ caller: 'deleteTrk' }, id, docs); + const deletedDocs = docs.rows.map((doc: any) => ({ + _deleted: true, + _id: doc.id, + _rev: doc.value.rev, + })); + console.log({ caller: 'deleteTrk' }, id, docs, deletedDocs); + await db.bulkDocs(deletedDocs); + return id; +}; diff --git a/src/workers/dispatcher-worker.ts b/src/workers/dispatcher-worker.ts index 787da20..2ebc0bf 100644 --- a/src/workers/dispatcher-worker.ts +++ b/src/workers/dispatcher-worker.ts @@ -16,7 +16,7 @@ import { putRte } from '../db/rte'; import { putRtept } from '../db/rtept'; import { getSettings, putSettings } from '../db/settings'; import { getState, setState } from '../db/state'; -import { getTrk, putNewTrk } from '../db/trk'; +import { deleteTrk, getTrk, putNewTrk } from '../db/trk'; import { putTrkpt } from '../db/trkpt'; import { getTrkseg, appendTrkpt } from '../db/trkseg'; import { getWpt, putWpt } from '../db/wpt'; @@ -54,6 +54,8 @@ onmessage = async function (e) { putRtept, putTrkpt, + deleteTrk, + getState, setState,