1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-05-31 06:29:12 +02:00

post getting settings to db service

This commit is contained in:
Kushagra Gour 2018-01-08 03:59:07 +05:30
parent bce45f9da2
commit 3f59777976
2 changed files with 30 additions and 17 deletions

View File

@ -23,13 +23,17 @@
Object.keys(obj).forEach(key => {
window.localStorage.setItem(key, JSON.stringify(obj[key]));
});
/* eslint-disable consistent-return */
setTimeout(() => {
if (cb) {
return cb();
}
}, FAUX_DELAY);
/* eslint-enable consistent-return */
}
};
const dbLocalAlias = chrome && chrome.storage ? chrome.storage.local : local;
const dbSyncAlias = chrome && chrome.storage ? chrome.storage.sync : local;
async function getDb() {
if (dbPromise) {
@ -67,19 +71,17 @@
async function getUserLastSeenVersion() {
const d = deferred();
if (window.IS_EXTENSION) {
chrome.storage.sync.get(
{
lastSeenVersion: ''
},
function syncGetCallback(result) {
d.resolve(result.lastSeenVersion);
}
);
}
local.get('lastSeenVersion', result => {
d.resolve(result.lastSeenVersion);
});
// Will be chrome.storage.sync in extension environment,
// otherwise will fallback to localstorage
dbSyncAlias.get(
{
lastSeenVersion: ''
},
result => {
d.resolve(result.lastSeenVersion);
}
);
return d.promise;
// Might consider getting actual value from remote db.
// Not critical right now.
}
@ -111,12 +113,23 @@
});
}
function getSettings(defaultSettings) {
const d = deferred();
// Will be chrome.storage.sync in extension environment,
// otherwise will fallback to localstorage
dbSyncAlias.get(defaultSettings, result => {
d.resolve(result);
});
return d.promise;
}
window.db = {
getDb,
getUser,
getUserLastSeenVersion,
setUserLastSeenVersion,
local: chrome && chrome.storage ? chrome.storage.local : local,
sync: chrome && chrome.storage ? chrome.storage.sync : local
getSettings,
local: dbLocalAlias,
sync: dbSyncAlias
};
})();

View File

@ -1710,7 +1710,7 @@ globalConsoleContainerEl, externalLibrarySearchInput, keyboardShortcutsModal
db.sync.set(obj, function() {
alertsService.add('Setting saved');
});
window.db.getDb(remoteDb => {
window.db.getDb().then(remoteDb => {
remoteDb
.collection('users')
.doc(window.user.uid)
@ -2376,7 +2376,7 @@ globalConsoleContainerEl, externalLibrarySearchInput, keyboardShortcutsModal
);
// Get synced `preserveLastCode` setting to get back last code (or not).
db.sync.get(defaultSettings, function syncGetCallback(result) {
db.getSettings(defaultSettings).then(result => {
if (result.preserveLastCode && lastCode) {
unsavedEditCount = 0;
if (lastCode.id) {