Commit 91f49069 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement ESC to cancel note form.

parent 15f3362d
......@@ -61,7 +61,15 @@ export default {
showReplyForm() {
this.isReplying = true;
},
cancelReplyForm() {
cancelReplyForm(shouldConfirm) {
if (shouldConfirm && this.$refs.noteForm.isDirty) {
const msg = 'Are you sure you want to cancel creating this comment?';
const isConfirmed = confirm(msg); // eslint-disable-line
if (!isConfirmed) {
return;
}
}
this.isReplying = false;
},
saveReply({ note }) {
......@@ -139,7 +147,8 @@ export default {
v-if="isReplying"
saveButtonTitle="Comment"
:updateHandler="saveReply"
:cancelHandler="cancelReplyForm" />
:cancelHandler="cancelReplyForm"
ref="noteForm" />
<div
v-if="!canReply"
class="disabled-comment text-center">
......
......@@ -76,7 +76,15 @@ export default {
new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line
});
},
formCancelHandler() {
formCancelHandler(shouldConfirm) {
if (shouldConfirm && this.$refs.noteBody.$refs.noteForm.isDirty) {
const msg = 'Are you sure you want to cancel editing this comment?';
const isConfirmed = confirm(msg); // eslint-disable-line
if (!isConfirmed) {
return;
}
}
this.isEditing = false;
},
},
......@@ -115,7 +123,8 @@ export default {
:note="note"
:isEditing="isEditing"
:formUpdateHandler="formUpdateHandler"
:formCancelHandler="formCancelHandler" />
:formCancelHandler="formCancelHandler"
ref="noteBody" />
</div>
</div>
</li>
......
......@@ -24,6 +24,7 @@ export default {
},
data() {
return {
initialNote: this.noteBody,
note: this.noteBody,
markdownPreviewUrl: '',
markdownDocsUrl: '',
......@@ -39,6 +40,11 @@ export default {
});
},
},
computed: {
isDirty() {
return this.initialNote !== this.note;
},
},
mounted() {
const issuableDataEl = document.getElementById('js-issuable-app-initial-data');
const issueData = JSON.parse(issuableDataEl.innerHTML.replace(/&quot;/g, '"'));
......@@ -68,7 +74,8 @@ export default {
ref="textarea"
slot="textarea"
placeholder="Write a comment or drag your files here..."
@keydown.meta.enter="handleUpdate">
@keydown.meta.enter="handleUpdate"
@keydown.esc="cancelHandler(true)">
</textarea>
</markdown-field>
<div class="note-form-actions clearfix">
......@@ -79,7 +86,7 @@ export default {
{{saveButtonTitle}}
</button>
<button
@click="cancelHandler"
@click="cancelHandler()"
class="btn btn-nr btn-cancel"
type="button">
Cancel
......
......@@ -40,6 +40,7 @@ export default {
},
mounted() {
const { discussionsPath, notesPath, lastFetchedAt } = this.$el.parentNode.dataset;
this.$store.dispatch('fetchNotes', discussionsPath)
.then(() => {
this.isLoading = false;
......@@ -58,6 +59,9 @@ export default {
this.$store.dispatch('poll', options)
.then((res) => {
options.lastFetchedAt = res.last_fetched_at;
})
.catch(() => {
new Flash('Something went wrong while fetching latest comments.'); // eslint-disable-line
});
}, 6000);
},
......
......@@ -23,7 +23,7 @@ export default {
const options = {
headers: {
'X-Last-Fetched-At': lastFetchedAt,
}
},
};
return Vue.http.get(endpoint, options);
......
......@@ -136,8 +136,7 @@ const actions = {
res.notes.forEach((note) => {
if (notesById[note.id]) {
context.commit('updateNote', note);
} else {
if (note.type === 'DiscussionNote') {
} else if (note.type === 'DiscussionNote') {
const discussion = findNoteObjectById(context.state.notes, note.discussion_id);
if (discussion) {
......@@ -148,7 +147,6 @@ const actions = {
} else {
context.commit('addNewNote', note);
}
}
});
}
......
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