[ci skip] Find last note in discussion through vue instead of through the DOM
This commit is contained in:
parent
2845dad2af
commit
9b87e680ca
2 changed files with 9 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
<script>
|
||||
import { mapGetters } from 'vuex';
|
||||
import markdownField from '../../vue_shared/components/markdown/field.vue';
|
||||
import eventHub from '../event_hub';
|
||||
|
||||
|
@ -19,7 +20,7 @@
|
|||
default: 'Save comment',
|
||||
},
|
||||
discussion: {
|
||||
type: Array,
|
||||
type: Object,
|
||||
required: false,
|
||||
}
|
||||
},
|
||||
|
@ -38,6 +39,9 @@
|
|||
markdownField,
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
'getDiscussionLastNote',
|
||||
]),
|
||||
noteHash() {
|
||||
return `#note_${this.noteId}`;
|
||||
},
|
||||
|
@ -48,17 +52,11 @@
|
|||
},
|
||||
editMyLastNote() {
|
||||
if (this.note === '') {
|
||||
// TODO: HANDLE THIS WITHOUTH JQUERY OR QUERYING THE DOM
|
||||
// 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');
|
||||
const lastNoteInDiscussion = this.getDiscussionLastNote(this.discussion, window.gon.current_user_id);
|
||||
|
||||
debugger;
|
||||
const lastNoteInDiscussion = this.$store.getters.getDiscussionLastNote(this.discussion);
|
||||
|
||||
if (myLastNoteId) {
|
||||
if (lastNoteInDiscussion) {
|
||||
eventHub.$emit('enterEditMode', {
|
||||
noteId: parseInt(myLastNoteId.replace('note_', ''), 10),
|
||||
noteId: lastNoteInDiscussion.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,6 @@ export const getCurrentUserLastNote = state => userId => reverseNotes(state.note
|
|||
return acc;
|
||||
}, []).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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue