mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-18 12:31:12 +02:00
itemservice: fix promise returning in setItem.
This commit is contained in:
@@ -89,16 +89,14 @@ export const itemService = {
|
||||
|
||||
async setItem(id, item) {
|
||||
const d = deferred();
|
||||
var remotePromise;
|
||||
log(`Starting to save item ${id}`);
|
||||
|
||||
// Always persist in `code` key for `preserveLastOpenItem` setting.
|
||||
// This key is used to retrieve content of last open item.
|
||||
db.local.set({ code: item }, () => {});
|
||||
|
||||
// NOT LOGGED IN
|
||||
// If `id` is `code`, this is a call on unloadbefore to save the last open thing,
|
||||
// which needs to be persisted locally only.
|
||||
if (!window.user || id === 'code') {
|
||||
if (!window.user) {
|
||||
const obj = {
|
||||
[id]: item
|
||||
};
|
||||
@@ -108,11 +106,9 @@ export const itemService = {
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
if (window.user) {
|
||||
var remoteDb = await window.db.getDb();
|
||||
log(`Starting to save item ${id}`);
|
||||
item.createdBy = window.user.uid;
|
||||
remotePromise = remoteDb
|
||||
remoteDb
|
||||
.collection('items')
|
||||
.doc(id)
|
||||
.set(item, {
|
||||
@@ -128,8 +124,7 @@ export const itemService = {
|
||||
// that you see the feedback msg immediately and not wait for
|
||||
// later sync.
|
||||
if (!navigator.onLine) return Promise.resolve();
|
||||
return remotePromise;
|
||||
}
|
||||
return d.promise;
|
||||
},
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user