1
0
mirror of https://github.com/chinchang/web-maker.git synced 2025-08-02 11:30:22 +02:00

get autosave working

This commit is contained in:
Kushagra Gour
2018-06-06 10:30:45 +05:30
parent 420cd63833
commit 1d29897193

View File

@@ -265,6 +265,7 @@ export default class App extends Component {
// Reset auto-saving flag // Reset auto-saving flag
this.isAutoSavingEnabled = false; this.isAutoSavingEnabled = false;
// Reset unsaved count, in UI also. // Reset unsaved count, in UI also.
this.setState({ unsavedEditCount: 0 }); this.setState({ unsavedEditCount: 0 });
return d.promise; return d.promise;
@@ -541,8 +542,7 @@ export default class App extends Component {
} else { } else {
alertsService.add('Item saved.'); alertsService.add('Item saved.');
} }
this.state.unsavedEditCount = 0; this.setState({ unsavedEditCount: 0 });
// saveBtn.classList.remove('is-marked');
} }
return itemService return itemService
@@ -678,10 +678,9 @@ export default class App extends Component {
); */ ); */
if (prefs.autoSave) { if (prefs.autoSave) {
if (!this.autoSaveInterval) { if (!this.autoSaveInterval) {
this.autoSaveInterval = setInterval( this.autoSaveInterval = setInterval(() => {
this.autoSaveLoop.bind(this), this.autoSaveLoop();
this.AUTO_SAVE_INTERVAL }, this.AUTO_SAVE_INTERVAL);
);
} }
} else { } else {
clearInterval(this.autoSaveInterval); clearInterval(this.autoSaveInterval);
@@ -692,7 +691,14 @@ export default class App extends Component {
'light-version' 'light-version'
); );
} }
autoSaveLoop() {}
// Keeps getting called after certain interval to auto-save current creation
// if it needs to be.
autoSaveLoop() {
if (this.isAutoSavingEnabled && this.state.unsavedEditCount) {
this.saveItem();
}
}
loginBtnClickHandler() { loginBtnClickHandler() {
this.setState({ isLoginModalOpen: true }); this.setState({ isLoginModalOpen: true });