1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-02-19 20:55:55 +01:00

save to "code" key whenever currentItem is set so that it opens on next reload

This commit is contained in:
Kushagra Gour 2019-03-18 15:54:52 +05:30
parent 00a00d38ec
commit c5462aab4c
2 changed files with 9 additions and 2 deletions

View File

@ -416,7 +416,10 @@ export default class App extends Component {
item.jsMode = item.jsMode || this.state.prefs.jsMode || JsModes.JS;
}
this.setState({ currentItem: item }, d.resolve);
this.setState({ currentItem: item }, () => {
d.resolve();
this.saveCode('code');
});
// Reset auto-saving flag
this.isAutoSavingEnabled = false;

View File

@ -89,11 +89,14 @@ export const itemService = {
async setItem(id, item) {
const d = deferred();
log(`Starting to save item ${id}`);
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 }, () => {});
if (id === 'code') {
return Promise.resolve();
}
// NOT LOGGED IN
if (!window.user) {
@ -106,6 +109,7 @@ export const itemService = {
return d.promise;
}
// LOGGED IN
var remoteDb = await window.db.getDb();
item.createdBy = window.user.uid;
remoteDb