Still working on the account dialog.

This commit is contained in:
vdv committed 2022-12-26 17:31:05 +01:00
1 parent 1d6c3a858d
commit 8a4396fb20
6 files changed
+94 -41

No files matched your search

+2 -1
View File
@@ -12,7 +12,8 @@ export const getAccounts = async () => {
return accountDocs.rows.map((row: any) => row.doc.doc);
};
export const putAccount = async (id: string, account: any) => {
export const putAccount = async (params: any) => {
const { id, account } = params;
const uri = getUri('account', { account: id });
return await put(uri, 'account', (_: any) => account, {}, true);
};
+36 -36
View File
@@ -39,21 +39,21 @@ export const initDb = async (params: any) => {
if (accounts.length === 0) {
accounts[0] = initialAccount;
await putAccount(initialAccount.id, initialAccount);
await putAccount({ id: initialAccount.id, account: initialAccount });
}
const settings = await getSettings();
let currentAccount = getAccountById(accounts, settings.currentAccountId);
if (currentAccount === undefined) {
settings.currentAccountId = accounts[0].id;
await putSettings(settings);
await putSettings({ settings });
currentAccount = accounts[0];
}
console.log({ caller: 'initDb', settings, currentAccount });
if (globalThis.db === undefined) {
globalThis.db = new PouchDB('dyomedea', {
globalThis.db = new PouchDB(currentAccount.localDb, {
auto_compaction: false,
});
}
@@ -81,40 +81,40 @@ export const initDb = async (params: any) => {
}
//await await db.compact();
const sync = PouchDB.sync(
'dyomedea',
'http://admin:password@localhost:5984/dyomedea',
{
live: true,
retry: true,
}
)
.on('change', function (info) {
// handle change
console.log({ caller: 'Sync / change', info });
})
.on('paused', function (err) {
// replication paused (e.g. replication up to date, user went offline)
console.log({ caller: 'Sync / paused', err });
})
.on('active', function () {
// replicate resumed (e.g. new changes replicating, user went back online)
console.log({ caller: 'Sync / active' });
})
.on('denied', function (err) {
// a document failed to replicate (e.g. due to permissions)
console.error({ caller: 'Sync / denied', err });
})
.on('complete', function (info) {
// handle complete
console.log({ caller: 'Sync / complete', info });
})
.on('error', function (err) {
// handle error
console.error({ caller: 'Sync / error', err });
});
// const sync = PouchDB.sync(
// 'dyomedea',
// 'http://admin:password@localhost:5984/dyomedea',
// {
// live: true,
// retry: true,
// }
// )
// .on('change', function (info) {
// // handle change
// console.log({ caller: 'Sync / change', info });
// })
// .on('paused', function (err) {
// // replication paused (e.g. replication up to date, user went offline)
// console.log({ caller: 'Sync / paused', err });
// })
// .on('active', function () {
// // replicate resumed (e.g. new changes replicating, user went back online)
// console.log({ caller: 'Sync / active' });
// })
// .on('denied', function (err) {
// // a document failed to replicate (e.g. due to permissions)
// console.error({ caller: 'Sync / denied', err });
// })
// .on('complete', function (info) {
// // handle complete
// console.log({ caller: 'Sync / complete', info });
// })
// .on('error', function (err) {
// // handle error
// console.error({ caller: 'Sync / error', err });
// });
console.log({ caller: 'initDb / before db.changes' });
// console.log({ caller: 'initDb / before db.changes' });
const changes = db
.changes({ since: 'now', live: true, include_docs: false })
+2 -1
View File
@@ -11,6 +11,7 @@ export const getSettings = async () => {
}
};
export const putSettings = async (settings: any) => {
export const putSettings = async (params: any) => {
const { settings } = params;
return await put('settings', 'settings', (_: any) => settings, {}, true);
};