diff --git a/src/components/gpx-dialog/GpxDialog.tsx b/src/components/gpx-dialog/GpxDialog.tsx index 3b530dd..66a8e03 100644 --- a/src/components/gpx-dialog/GpxDialog.tsx +++ b/src/components/gpx-dialog/GpxDialog.tsx @@ -1,6 +1,6 @@ import { useI18n } from '@solid-primitives/i18n'; import { Box, Button, IconButton, SvgIcon, TextField } from '@suid/material'; -import { cloneDeep } from 'lodash'; +import { cloneDeep, isPlainObject } from 'lodash'; import { Component, createSignal, Show } from 'solid-js'; import { newEmptyGpx } from '../../db/gpx'; import { peekCachedSignal } from '../../workers/cached-signals'; @@ -93,6 +93,20 @@ const GpxDialog: Component<{}> = (props) => { gpx: gpx(), }); }; + const gpxSharedChangeHandler = (event: any) => { + const newGpx: Gpx = cloneDeep(gpx()) as Gpx; + if (!isPlainObject(newGpx.extensions)) { + newGpx.extensions = {}; + } + newGpx.extensions.shared = event.target.value; + setGpx(newGpx); + console.log({ + caller: 'GpxDialog / gpxSharedChangeHandler', + value: event.target.value, + gpx: gpx(), + newGpx, + }); + }; const gpxTimeChangeHandler = (event: any) => { const newGpx: Gpx = cloneDeep(gpx()) as Gpx; if (newGpx.metadata === undefined) { @@ -164,6 +178,14 @@ const GpxDialog: Component<{}> = (props) => { onChange={gpxDescChangeHandler} InputProps={{ inputComponent: 'textarea' }} /> + diff --git a/src/db/change-handler.ts b/src/db/change-handler.ts index b17a682..b804783 100644 --- a/src/db/change-handler.ts +++ b/src/db/change-handler.ts @@ -43,7 +43,7 @@ for (const property in methods) { } const changeHandler = async (change: any) => { - // console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches }); + // console.log({ caller: 'ChangeHandler', change, watches: globalThis.watches }); const { id } = change; if (!globalThis.watches) { globalThis.watches = new Map(); diff --git a/src/db/gpx.ts b/src/db/gpx.ts index ebe674f..36ac110 100644 --- a/src/db/gpx.ts +++ b/src/db/gpx.ts @@ -1,3 +1,4 @@ +import { Rowing } from '@suid/icons-material'; import { cloneDeep, isEmpty } from 'lodash'; import { PureComponent } from 'react'; import { $DEVCOMP } from 'solid-js'; @@ -423,9 +424,20 @@ export const getGpx = async (params: any) => { } //level 1 (extensions) if (target !== undefined && row.doc.type === 'extensions') { - target.splice(1); - appendToArray(target.at(-1), row.doc.type, row.doc.doc); - target.push(row.doc.doc); + console.log({ + caller: 'getGpx / extensions', + gpx, + row, + doc: row.doc.doc, + gpx_extensions: gpx?.extensions, + target, + }); + + gpx.extensions = row.doc.doc; + + // target.splice(1); + // appendToArray(target.at(-1), row.doc.type, row.doc.doc); + // target.push(row.doc.doc); } //level 1 (others) if ( @@ -477,7 +489,10 @@ export const putGpx = async (params: any) => { gpx: intToGpxId(date.valueOf()), }); } - console.log({ caller: 'putGpx', params, id, gpx }); + + const previousShared = (await get(`${id}/4extensions`)).doc?.shared; + + console.log({ caller: 'putGpx', params, id, gpx, previousShared }); const extensions = gpx?.extensions; gpx.extensions = undefined; @@ -494,5 +509,24 @@ export const putGpx = async (params: any) => { extensions ); } + + if (previousShared !== extensions?.shared) { + const shared = extensions?.shared.split(/\s*,\s*/); + const family = (await getFamily(id, { include_docs: true })).rows.map( + (row: any) => { + return { ...row.doc, shared }; + } + ); + console.log({ + caller: 'putGpx / updateShared', + params, + id, + gpx, + previousShared, + family, + }); + await db.bulkDocs(family); + } + return id; }; diff --git a/src/db/types.d.ts b/src/db/types.d.ts index 0c5e565..7e47127 100644 --- a/src/db/types.d.ts +++ b/src/db/types.d.ts @@ -49,7 +49,8 @@ interface Extensions { 'dyo:batterylevel'?: number; 'dyo:useragent'?: string; 'dyo:minZoom'?: number; - address: any; + address?: any; + shared?: string; } interface Trk { diff --git a/src/i18n/en.ts b/src/i18n/en.ts index b218790..1ad9749 100644 --- a/src/i18n/en.ts +++ b/src/i18n/en.ts @@ -44,6 +44,7 @@ const dict = { gpxNoName: 'No name', gpxDesc: 'Description', gpxTime: 'Start date', + gpxShared: 'Shared with', gpxSave: 'Save', newGpx: '-- new journey --', diff --git a/src/i18n/fr.ts b/src/i18n/fr.ts index 42e89ff..5d2a1e9 100644 --- a/src/i18n/fr.ts +++ b/src/i18n/fr.ts @@ -49,6 +49,7 @@ const dict = { gpxNoName: 'Pas de nom', gpxDesc: 'Description', gpxTime: 'Date de début', + gpxShared: 'Partagé avec', gpxSave: 'Sauvegarder', newGpx: '-- nouveau voyage --',