Commit 998299e2 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement note edit.

parent 092d4ca6
...@@ -57,8 +57,23 @@ export default { ...@@ -57,8 +57,23 @@ export default {
}); });
} }
}, },
formUpdateHandler() { formUpdateHandler(note) {
// console.log('update requested', data); const data = {
endpoint: `${this.note.path}?full_data=1`,
note: {
target_type: 'issue',
target_id: this.note.noteable_id,
note,
},
};
this.$store.dispatch('updateNote', data)
.then(() => {
this.isEditing = false;
})
.catch(() => {
new Flash('Something went wrong while editing your comment. Please try again.'); // eslint-disable-line
});
}, },
formCancelHandler() { formCancelHandler() {
this.isEditing = false; this.isEditing = false;
......
...@@ -32,6 +32,11 @@ export default { ...@@ -32,6 +32,11 @@ export default {
renderGFM() { renderGFM() {
$(this.$refs['note-body']).renderGFM(); $(this.$refs['note-body']).renderGFM();
}, },
handleFormUpdate() {
this.formUpdateHandler({
note: this.$refs.noteForm.note,
});
},
}, },
mounted() { mounted() {
this.renderGFM(); this.renderGFM();
...@@ -48,7 +53,8 @@ export default { ...@@ -48,7 +53,8 @@ export default {
class="note-text md"></div> class="note-text md"></div>
<issue-note-form <issue-note-form
v-if="isEditing" v-if="isEditing"
:updateHandler="formUpdateHandler" ref="noteForm"
:updateHandler="handleFormUpdate"
:cancelHandler="formCancelHandler" :cancelHandler="formCancelHandler"
:noteBody="note.note" /> :noteBody="note.note" />
<issue-note-edited-text <issue-note-edited-text
......
...@@ -13,4 +13,7 @@ export default { ...@@ -13,4 +13,7 @@ export default {
replyToDiscussion(endpoint, data) { replyToDiscussion(endpoint, data) {
return Vue.http.post(endpoint, data, { emulateJSON: true }); return Vue.http.post(endpoint, data, { emulateJSON: true });
}, },
updateNote(endpoint, data) {
return Vue.http.put(endpoint, data, { emulateJSON: true });
},
}; };
...@@ -42,6 +42,16 @@ const mutations = { ...@@ -42,6 +42,16 @@ const mutations = {
noteObj.notes.push(note); noteObj.notes.push(note);
}, },
updateNote(storeState, note) {
const noteObj = findNoteObjectById(storeState.notes, note.discussion_id);
if (noteObj.individual_note) {
noteObj.notes.splice(0, 1, note);
} else {
const comment = findNoteObjectById(noteObj.notes, note.id);
noteObj.notes.splice(noteObj.notes.indexOf(comment), 1, note);
}
},
}; };
const actions = { const actions = {
...@@ -70,6 +80,16 @@ const actions = { ...@@ -70,6 +80,16 @@ const actions = {
context.commit('addNewReplyToDiscussion', res); context.commit('addNewReplyToDiscussion', res);
}); });
}, },
updateNote(context, data) {
const { endpoint, note } = data;
return service
.updateNote(endpoint, note)
.then(res => res.json())
.then((res) => {
context.commit('updateNote', res);
});
},
}; };
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