Commit 03436e61 authored by Filipa Lacerda's avatar Filipa Lacerda

Handle autosave reset when form is submitted

parent 507b15e7
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
import issueNoteForm from './issue_note_form.vue'; import issueNoteForm from './issue_note_form.vue';
import placeholderNote from './issue_placeholder_note.vue'; import placeholderNote from './issue_placeholder_note.vue';
import placeholderSystemNote from './issue_placeholder_system_note.vue'; import placeholderSystemNote from './issue_placeholder_system_note.vue';
import '../../autosave'; import autosave from '../mixins/autosave';;
export default { export default {
props: { props: {
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
placeholderNote, placeholderNote,
placeholderSystemNote, placeholderSystemNote,
}, },
mixins: [
autosave,
],
computed: { computed: {
...mapGetters([ ...mapGetters([
'getIssueData', 'getIssueData',
...@@ -85,6 +88,7 @@ ...@@ -85,6 +88,7 @@
} }
} }
this.resetAutoSave();
this.isReplying = false; this.isReplying = false;
}, },
saveReply(noteText) { saveReply(noteText) {
...@@ -103,12 +107,10 @@ ...@@ -103,12 +107,10 @@
this.saveNote(replyData) this.saveNote(replyData)
.then(() => { .then(() => {
this.isReplying = false; this.isReplying = false;
this.resetAutoSave();
}) })
.catch(() => Flash('Something went wrong while adding your reply. Please try again.')); .catch(() => Flash('Something went wrong while adding your reply. Please try again.'));
}, },
initAutoSave() {
return new Autosave($(this.$refs.noteForm.$refs.textarea), ['Note', 'Issue', this.note.id]);
},
}, },
mounted() { mounted() {
if (this.isReplying) { if (this.isReplying) {
...@@ -117,7 +119,11 @@ ...@@ -117,7 +119,11 @@
}, },
updated() { updated() {
if (this.isReplying) { if (this.isReplying) {
this.initAutoSave(); if (!this.autosave) {
this.initAutoSave();
} else {
this.setAutoSave();
}
} }
}, },
}; };
......
...@@ -90,6 +90,7 @@ ...@@ -90,6 +90,7 @@
this.isEditing = false; this.isEditing = false;
// TODO: this could be moved down, by setting a prop // TODO: this could be moved down, by setting a prop
$(this.$refs.noteBody.$el).renderGFM(); $(this.$refs.noteBody.$el).renderGFM();
this.$refs.noteBody.resetAutoSave();
}) })
.catch(() => Flash( .catch(() => Flash(
'Something went wrong while editing your comment. Please try again.', 'Something went wrong while editing your comment. Please try again.',
...@@ -102,7 +103,7 @@ ...@@ -102,7 +103,7 @@
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
if (!confirm('Are you sure you want to cancel editing this comment?')) return; if (!confirm('Are you sure you want to cancel editing this comment?')) return;
} }
this.$refs.noteBody.resetAutoSave();
this.isEditing = false; this.isEditing = false;
}, },
}, },
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import issueNoteAwardsList from './issue_note_awards_list.vue'; import issueNoteAwardsList from './issue_note_awards_list.vue';
import issueNoteForm from './issue_note_form.vue'; import issueNoteForm from './issue_note_form.vue';
import TaskList from '../../task_list'; import TaskList from '../../task_list';
import '../../autosave'; import autosave from '../mixins/autosave';
export default { export default {
props: { props: {
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
default: false, default: false,
}, },
}, },
mixins: [
autosave,
],
components: { components: {
issueNoteEditedText, issueNoteEditedText,
issueNoteAwardsList, issueNoteAwardsList,
...@@ -51,9 +54,6 @@ ...@@ -51,9 +54,6 @@
formCancelHandler(shouldConfirm, isDirty) { formCancelHandler(shouldConfirm, isDirty) {
this.$emit('cancelFormEdition', shouldConfirm, isDirty); this.$emit('cancelFormEdition', shouldConfirm, isDirty);
}, },
initAutoSave() {
return new Autosave($(this.$refs.noteForm.$refs.textarea), ['Note', 'Issue', this.note.id]);
},
}, },
mounted() { mounted() {
this.renderGFM(); this.renderGFM();
...@@ -65,7 +65,11 @@ ...@@ -65,7 +65,11 @@
updated() { updated() {
this.initTaskList(); this.initTaskList();
if (this.isEditing) { if (this.isEditing) {
this.initAutoSave(); if (!this.autosave) {
this.initAutoSave();
} else {
this.setAutoSave();
}
} }
}, },
}; };
......
/* globals Autosave */
import '../../autosave';
export default {
methods: {
initAutoSave() {
this.autosave = new Autosave($(this.$refs.noteForm.$refs.textarea), ['Note', 'Issue', this.note.id]);
},
resetAutoSave() {
this.autosave.reset();
},
setAutoSave() {
this.autosave.save();
},
},
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment