Adding a "shared" property to gpxes and family.

This commit is contained in:
Eric van der Vlist 2023-02-12 18:14:14 +01:00
parent 8853ea4670
commit 9dacad9af3
6 changed files with 66 additions and 7 deletions

View File

@ -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' }}
/>
<TextField
label={t('gpxShared')}
multiline={true}
rows={5}
value={gpx()?.extensions?.shared || ''}
onChange={gpxSharedChangeHandler}
InputProps={{ inputComponent: 'textarea' }}
/>
<Button variant='contained' onClick={saveHandler}>
{t('gpxSave')}
</Button>

View File

@ -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();

View File

@ -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;
};

3
src/db/types.d.ts vendored
View File

@ -49,7 +49,8 @@ interface Extensions {
'dyo:batterylevel'?: number;
'dyo:useragent'?: string;
'dyo:minZoom'?: number;
address: any;
address?: any;
shared?: string;
}
interface Trk {

View File

@ -44,6 +44,7 @@ const dict = {
gpxNoName: 'No name',
gpxDesc: 'Description',
gpxTime: 'Start date',
gpxShared: 'Shared with',
gpxSave: 'Save',
newGpx: '-- new journey --',

View File

@ -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 --',