Commit 9b87e680 authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Find last note in discussion through vue instead of through the DOM

parent 2845dad2
<script> <script>
import { mapGetters } from 'vuex';
import markdownField from '../../vue_shared/components/markdown/field.vue'; import markdownField from '../../vue_shared/components/markdown/field.vue';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
...@@ -19,7 +20,7 @@ ...@@ -19,7 +20,7 @@
default: 'Save comment', default: 'Save comment',
}, },
discussion: { discussion: {
type: Array, type: Object,
required: false, required: false,
} }
}, },
...@@ -38,6 +39,9 @@ ...@@ -38,6 +39,9 @@
markdownField, markdownField,
}, },
computed: { computed: {
...mapGetters([
'getDiscussionLastNote',
]),
noteHash() { noteHash() {
return `#note_${this.noteId}`; return `#note_${this.noteId}`;
}, },
...@@ -48,17 +52,11 @@ ...@@ -48,17 +52,11 @@
}, },
editMyLastNote() { editMyLastNote() {
if (this.note === '') { if (this.note === '') {
// TODO: HANDLE THIS WITHOUTH JQUERY OR QUERYING THE DOM const lastNoteInDiscussion = this.getDiscussionLastNote(this.discussion, window.gon.current_user_id);
// FIND the discussion we are in and the last comment on that discussion
const discussion = $(this.$el).closest('.discussion-notes');
const myLastNoteId = discussion.find('.js-my-note').last().attr('id');
debugger; if (lastNoteInDiscussion) {
const lastNoteInDiscussion = this.$store.getters.getDiscussionLastNote(this.discussion);
if (myLastNoteId) {
eventHub.$emit('enterEditMode', { eventHub.$emit('enterEditMode', {
noteId: parseInt(myLastNoteId.replace('note_', ''), 10), noteId: lastNoteInDiscussion.id,
}); });
} }
} }
......
...@@ -31,6 +31,6 @@ export const getCurrentUserLastNote = state => userId => reverseNotes(state.note ...@@ -31,6 +31,6 @@ export const getCurrentUserLastNote = state => userId => reverseNotes(state.note
return acc; return acc;
}, []).filter(el => el !== undefined)[0]; }, []).filter(el => el !== undefined)[0];
export const getDiscussionLastNote = state => (discussion, userId) => reverseNotes(discussion[0].notes) export const getDiscussionLastNote = state => (discussion, userId) => reverseNotes(discussion.notes)
.find(el => isLastNote(el, userId)); .find(el => isLastNote(el, userId));
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