Store the current gpx id in account docs
This commit is contained in:
parent
8d32fa253a
commit
51ab7c38e0
|
@ -19,6 +19,7 @@ const GpxDialog: Component<{}> = (props) => {
|
||||||
|
|
||||||
const [selectedGpxId, setSelectedGpxId] = createSignal<string>('');
|
const [selectedGpxId, setSelectedGpxId] = createSignal<string>('');
|
||||||
const [gpx, setGpx] = createSignal<Gpx>();
|
const [gpx, setGpx] = createSignal<Gpx>();
|
||||||
|
const [currentAccount, setCurrentAccount] = createSignal<any>();
|
||||||
|
|
||||||
console.log({ caller: 'GpxDialog', currentGpxId: currentGpxId() });
|
console.log({ caller: 'GpxDialog', currentGpxId: currentGpxId() });
|
||||||
|
|
||||||
|
@ -33,9 +34,15 @@ const GpxDialog: Component<{}> = (props) => {
|
||||||
return newGpx();
|
return newGpx();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dispatch({ action: 'getCurrentAccount' }).then((currentAccount: any) => {
|
||||||
|
console.log({ caller: 'GpxDialog / currentAccount', currentAccount });
|
||||||
|
setCurrentAccount(currentAccount);
|
||||||
|
setCurrentGpxId(currentAccount.currentGpxId);
|
||||||
|
setSelectedGpxId(currentAccount.currentGpxId);
|
||||||
|
});
|
||||||
|
|
||||||
const handleClickOpen = async () => {
|
const handleClickOpen = async () => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
setSelectedGpxId(currentGpxId());
|
|
||||||
if (currentGpxId() !== '') {
|
if (currentGpxId() !== '') {
|
||||||
setGpx(fetchGpx(currentGpxId()) as Gpx);
|
setGpx(fetchGpx(currentGpxId()) as Gpx);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +138,12 @@ const GpxDialog: Component<{}> = (props) => {
|
||||||
})) as string;
|
})) as string;
|
||||||
setCurrentGpxId(id);
|
setCurrentGpxId(id);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
await dispatch({
|
||||||
|
action: 'putCurrentAccount',
|
||||||
|
params: {
|
||||||
|
account: { ...currentAccount(), currentGpxId: currentGpxId() },
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getFamily, put } from './lib';
|
import { get, getFamily, put } from './lib';
|
||||||
import getUri from '../lib/ids';
|
import getUri from '../lib/ids';
|
||||||
|
import { getSettings, putSettings } from './settings';
|
||||||
|
|
||||||
export const initialAccount = {
|
export const initialAccount = {
|
||||||
id: 'initial',
|
id: 'initial',
|
||||||
|
@ -12,6 +13,12 @@ export const getAccounts = async () => {
|
||||||
return accountDocs.rows.map((row: any) => row.doc.doc);
|
return accountDocs.rows.map((row: any) => row.doc.doc);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAccount = async (params: any) => {
|
||||||
|
const { id } = params;
|
||||||
|
const uri = getUri('account', { account: id });
|
||||||
|
return (await get(uri, true)).doc;
|
||||||
|
};
|
||||||
|
|
||||||
export const putAccount = async (params: any) => {
|
export const putAccount = async (params: any) => {
|
||||||
const { id, account } = params;
|
const { id, account } = params;
|
||||||
const uri = getUri('account', { account: id });
|
const uri = getUri('account', { account: id });
|
||||||
|
@ -22,3 +29,14 @@ export const getAccountById = (accounts: any, id: string) => {
|
||||||
const targetAccounts: any[] = accounts.filter((acc: any) => acc.id === id);
|
const targetAccounts: any[] = accounts.filter((acc: any) => acc.id === id);
|
||||||
return targetAccounts[0];
|
return targetAccounts[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCurrentAccount = async (params: any) => {
|
||||||
|
const settings = await getSettings();
|
||||||
|
return await getAccount({ id: settings.currentAccountId });
|
||||||
|
};
|
||||||
|
|
||||||
|
export const putCurrentAccount = async (params: any) => {
|
||||||
|
const { account } = params;
|
||||||
|
const settings = await getSettings();
|
||||||
|
await putAccount({ id: settings.currentAccountId, account });
|
||||||
|
};
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
/// <reference lib="webworker" />
|
/// <reference lib="webworker" />
|
||||||
import { initDb } from '../db';
|
import { initDb } from '../db';
|
||||||
import { getAccounts, putAccount } from '../db/account';
|
import {
|
||||||
|
getAccounts,
|
||||||
|
getCurrentAccount,
|
||||||
|
putAccount,
|
||||||
|
putCurrentAccount,
|
||||||
|
} from '../db/account';
|
||||||
import { cancelWatch, getAndWatch } from '../db/change-handler';
|
import { cancelWatch, getAndWatch } from '../db/change-handler';
|
||||||
import {
|
import {
|
||||||
putNewGpx,
|
putNewGpx,
|
||||||
|
@ -65,6 +70,8 @@ onmessage = async function (e) {
|
||||||
|
|
||||||
getAccounts,
|
getAccounts,
|
||||||
putAccount,
|
putAccount,
|
||||||
|
getCurrentAccount,
|
||||||
|
putCurrentAccount,
|
||||||
};
|
};
|
||||||
|
|
||||||
// console.log({ caller: 'dispatcher-worker / onmessage', e });
|
// console.log({ caller: 'dispatcher-worker / onmessage', e });
|
||||||
|
|
Loading…
Reference in New Issue