Ensure to clear timeout in autosave

We are still trying to ensure autosave is not called outside the /implement route.

Relates to CODEOCEAN-G1
This commit is contained in:
Sebastian Serth
2023-02-28 12:31:22 +01:00
parent 6c1bfb6815
commit 252704b083
2 changed files with 11 additions and 10 deletions

View File

@ -204,7 +204,7 @@ CodeOceanEditorSubmissions = {
const button = $(event.target) || $('#submit');
this.createSubmission(button, null, function (response) {
if (response.redirect) {
this.unloadAutoSave();
this.autosaveIfChanged();
this.editors = [];
Turbolinks.clearCache();
Turbolinks.visit(response.redirect);
@ -228,13 +228,6 @@ CodeOceanEditorSubmissions = {
this.autosaveTimer = setTimeout(this.autosave.bind(this), this.AUTOSAVE_INTERVAL);
},
unloadAutoSave: function() {
if(this.autosaveTimer != null){
clearTimeout(this.autosaveTimer);
this.autosave();
}
},
updateSaveStateLabel: function() {
var date = new Date();
var autosaveLabel = $(this.autosaveLabel);
@ -243,7 +236,15 @@ CodeOceanEditorSubmissions = {
autosaveLabel.text(date.toLocaleTimeString());
},
autosaveIfChanged: function() {
// Only save if the user has changed the code in the meantime (represented by an active timer)
if(this.autosaveTimer != null){
this.autosave();
}
},
autosave: function () {
clearTimeout(this.autosaveTimer);
this.autosaveTimer = null;
this.createSubmission($('#autosave'), null);
}