Commit ff6acdf1 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement discussion reply.

parent 905ad9cd
...@@ -17,6 +17,7 @@ export default { ...@@ -17,6 +17,7 @@ export default {
return { return {
registerLink: '#', registerLink: '#',
signInLink: '#', signInLink: '#',
newNotePath: '',
isReplying: false, isReplying: false,
}; };
}, },
...@@ -45,6 +46,9 @@ export default { ...@@ -45,6 +46,9 @@ export default {
this.registerLink = registerLink.getAttribute('href'); this.registerLink = registerLink.getAttribute('href');
this.signInLink = signInLink.getAttribute('href'); this.signInLink = signInLink.getAttribute('href');
} }
const newNotePath = document.querySelector('.js-main-target-form').getAttribute('action');
this.newNotePath = `${newNotePath}?full_data=1`;
}, },
methods: { methods: {
toggleDiscussion() { toggleDiscussion() {
...@@ -58,8 +62,21 @@ export default { ...@@ -58,8 +62,21 @@ export default {
cancelReplyForm() { cancelReplyForm() {
this.isReplying = false; this.isReplying = false;
}, },
saveReply() { saveReply({ note }) {
const data = {
endpoint: this.newNotePath,
reply: {
in_reply_to_discussion_id: this.note.reply_id,
target_type: 'issue',
target_id: this.discussion.noteable_id,
note: { note },
},
};
this.$store.dispatch('replyToDiscussion', data)
.then(() => {
this.isReplying = false; this.isReplying = false;
});
}, },
}, },
}; };
......
...@@ -10,4 +10,7 @@ export default { ...@@ -10,4 +10,7 @@ export default {
deleteNote(endpoint) { deleteNote(endpoint) {
return Vue.http.delete(endpoint); return Vue.http.delete(endpoint);
}, },
replyToDiscussion(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true });
},
}; };
...@@ -38,6 +38,11 @@ const mutations = { ...@@ -38,6 +38,11 @@ const mutations = {
} }
} }
}, },
addNewReplyToDiscussion(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id);
noteObj.notes.push(note);
},
}; };
const actions = { const actions = {
...@@ -62,6 +67,19 @@ const actions = { ...@@ -62,6 +67,19 @@ const actions = {
new Flash('Something went wrong while deleting your note. Please try again.'); // eslint-disable-line new Flash('Something went wrong while deleting your note. Please try again.'); // eslint-disable-line
}); });
}, },
replyToDiscussion(context, data) {
const { endpoint, reply } = data;
return service
.replyToDiscussion(endpoint, reply)
.then((res) => res.json())
.then((res) => {
context.commit('addNewReplyToDiscussion', res);
})
.catch(() => {
new Flash('Something went wrong while adding your reply. Please try again.'); // eslint-disable-line
});
},
}; };
export default { export default {
......
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