mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-27 00:30:09 +02:00
show correct save item notifcation at correct time.
This commit is contained in:
@@ -54,22 +54,46 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
async setItem(id, item) {
|
async setItem(id, item) {
|
||||||
if (!window.user) {
|
const d = deferred();
|
||||||
return new Promise(resolve => resolve());
|
var remotePromise;
|
||||||
|
// TODO: check why we need to save locally always?
|
||||||
|
const obj = {
|
||||||
|
[id]: item
|
||||||
|
};
|
||||||
|
db.local.set(obj, () => {
|
||||||
|
// Is extension OR is app but logged out OR is logged in but offline
|
||||||
|
// If logged in but offline, resolve immediately so
|
||||||
|
// that you see the feedback msg immediately and not wait for
|
||||||
|
// later sync.
|
||||||
|
if (window.IS_EXTENSION || !window.user || !navigator.onLine) {
|
||||||
|
d.resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// If `id` is `code`, this is a call on unloadbefore to save the last open thing.
|
||||||
|
// Do not presist that on remote.
|
||||||
|
if (id === 'code') {
|
||||||
|
// No deferred required here as this gets called on unloadbefore
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
var remoteDb = await window.db.getDb();
|
if (window.user) {
|
||||||
utils.log(`Starting to save item ${id}`);
|
var remoteDb = await window.db.getDb();
|
||||||
item.createdBy = window.user.uid;
|
utils.log(`Starting to save item ${id}`);
|
||||||
return remoteDb
|
item.createdBy = window.user.uid;
|
||||||
.collection('items')
|
remotePromise = remoteDb
|
||||||
.doc(id)
|
.collection('items')
|
||||||
.set(item, {
|
.doc(id)
|
||||||
merge: true
|
.set(item, {
|
||||||
})
|
merge: true
|
||||||
.then(arg => {
|
})
|
||||||
utils.log('Document written', arg);
|
.then(arg => {
|
||||||
})
|
utils.log('Document written', arg);
|
||||||
.catch(error => utils.log(error));
|
d.resolve();
|
||||||
|
})
|
||||||
|
.catch(d.reject);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (window.user && navigator.onLine) ? remotePromise : d.promise;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -423,18 +423,19 @@ loginModal, profileModal, profileAvatarImg, profileUserName
|
|||||||
currentItem.mainSizes = getMainPaneSizes();
|
currentItem.mainSizes = getMainPaneSizes();
|
||||||
|
|
||||||
utils.log('saving key', key || currentItem.id, currentItem);
|
utils.log('saving key', key || currentItem.id, currentItem);
|
||||||
saveSetting(key || currentItem.id, currentItem);
|
|
||||||
// If key is `code`, this is a call on unloadbefore to save the last open thing.
|
function onSaveComplete() {
|
||||||
// Do not presist that on remote.
|
if (window.user && !navigator.onLine) {
|
||||||
if (key === 'code') {
|
alertsService.add('Item saved locally. Will save to account when you are online.');
|
||||||
// No deferred required here as this gets called on unloadbefore
|
} else {
|
||||||
return false;
|
alertsService.add('Item saved.');
|
||||||
}
|
|
||||||
return itemService.setItem(key || currentItem.id, currentItem).then(() => {
|
}
|
||||||
alertsService.add('Item saved.');
|
|
||||||
unsavedEditCount = 0;
|
unsavedEditCount = 0;
|
||||||
saveBtn.classList.remove('is-marked');
|
saveBtn.classList.remove('is-marked');
|
||||||
});
|
}
|
||||||
|
|
||||||
|
return itemService.setItem(key || currentItem.id, currentItem).then(onSaveComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
function populateItemsInSavedPane(items) {
|
function populateItemsInSavedPane(items) {
|
||||||
|
Reference in New Issue
Block a user