summaryrefslogtreecommitdiff
path: root/app/assets/javascripts
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-07-28 18:43:19 +0100
committerFilipa Lacerda <filipa@gitlab.com>2017-07-28 18:43:19 +0100
commit2845dad2afcfd1f6e4d48d96d957ac7b33051524 (patch)
treeee4b7d6ca1605e72d207ebfd7376ee7dac7e547d /app/assets/javascripts
parent7a251207e1b6f2b4c709d319d870694ace620e0c (diff)
downloadgitlab-ce-2845dad2afcfd1f6e4d48d96d957ac7b33051524.tar.gz
Find last note created by current user through vue instead of querying the DOM
Diffstat (limited to 'app/assets/javascripts')
-rw-r--r--app/assets/javascripts/notes/components/issue_comment_form.vue17
-rw-r--r--app/assets/javascripts/notes/components/issue_discussion.vue5
-rw-r--r--app/assets/javascripts/notes/components/issue_note.vue3
-rw-r--r--app/assets/javascripts/notes/components/issue_note_body.vue10
-rw-r--r--app/assets/javascripts/notes/components/issue_note_form.vue11
-rw-r--r--app/assets/javascripts/notes/components/issue_notes_app.vue11
-rw-r--r--app/assets/javascripts/notes/stores/getters.js13
7 files changed, 48 insertions, 22 deletions
diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue
index 5b8b7a67fa8..ff15b354917 100644
--- a/app/assets/javascripts/notes/components/issue_comment_form.vue
+++ b/app/assets/javascripts/notes/components/issue_comment_form.vue
@@ -1,7 +1,7 @@
<script>
/* global Flash */
- import { mapActions } from 'vuex';
+ import { mapActions, mapGetters } from 'vuex';
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import markdownField from '../../vue_shared/components/markdown/field.vue';
import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue';
@@ -30,6 +30,9 @@
issueNoteSignedOutWidget,
},
computed: {
+ ...mapGetters([
+ 'getCurrentUserLastNote',
+ ]),
isLoggedIn() {
return window.gon.current_user_id;
},
@@ -126,13 +129,13 @@
setNoteType(type) {
this.noteType = type;
},
- editMyLastNote() {
+ editCurrentUserLastNote() {
if (this.note === '') {
- const myLastNoteId = $('.js-my-note').last().attr('id');
- debugger;
- if (myLastNoteId) {
+ const lastNote = this.getCurrentUserLastNote(window.gon.current_user_id);
+ console.log(lastNote)
+ if (lastNote) {
eventHub.$emit('enterEditMode', {
- noteId: parseInt(myLastNoteId.replace('note_', ''), 10),
+ noteId: lastNote.id,
});
}
}
@@ -185,7 +188,7 @@
ref="textarea"
slot="textarea"
placeholder="Write a comment or drag your files here..."
- @keydown.up="editMyLastNote"
+ @keydown.up="editCurrentUserLastNote()"
@keydown.meta.enter="handleSave()">
</textarea>
</markdown-field>
diff --git a/app/assets/javascripts/notes/components/issue_discussion.vue b/app/assets/javascripts/notes/components/issue_discussion.vue
index 9d0625d30de..087d80e3f5f 100644
--- a/app/assets/javascripts/notes/components/issue_discussion.vue
+++ b/app/assets/javascripts/notes/components/issue_discussion.vue
@@ -164,8 +164,9 @@
<issue-note-form
v-if="isReplying"
saveButtonTitle="Comment"
- :update-handler="saveReply"
- :cancel-handler="cancelReplyForm"
+ :discussion="note"
+ @handleFormUpdate="saveReply"
+ @cancelFormEdition="cancelReplyForm"
ref="noteForm"
/>
<issue-note-signed-out-widget v-if="!canReply" />
diff --git a/app/assets/javascripts/notes/components/issue_note.vue b/app/assets/javascripts/notes/components/issue_note.vue
index 49edac407dd..efe2bf73c40 100644
--- a/app/assets/javascripts/notes/components/issue_note.vue
+++ b/app/assets/javascripts/notes/components/issue_note.vue
@@ -118,7 +118,8 @@
<li
class="note timeline-entry"
:id="noteAnchorId"
- :class="classNameBindings">
+ :class="classNameBindings"
+ :note-id="note.id">
<div class="timeline-entry-inner">
<div class="timeline-icon">
<user-avatar-link
diff --git a/app/assets/javascripts/notes/components/issue_note_body.vue b/app/assets/javascripts/notes/components/issue_note_body.vue
index c7dc146985b..fb663b59a8d 100644
--- a/app/assets/javascripts/notes/components/issue_note_body.vue
+++ b/app/assets/javascripts/notes/components/issue_note_body.vue
@@ -19,14 +19,6 @@
required: false,
default: false,
},
- formUpdateHandler: {
- type: Function,
- required: true,
- },
- formCancelHandler: {
- type: Function,
- required: true,
- },
},
components: {
issueNoteEditedText,
@@ -93,7 +85,7 @@
v-if="note.last_edited_by"
:edited-at="note.last_edited_at"
:edited-by="note.last_edited_by"
- actionText="Edited"
+ action-text="Edited"
/>
<issue-note-awards-list
v-if="note.award_emoji.length"
diff --git a/app/assets/javascripts/notes/components/issue_note_form.vue b/app/assets/javascripts/notes/components/issue_note_form.vue
index 75aca2d5cc9..739a7df64a8 100644
--- a/app/assets/javascripts/notes/components/issue_note_form.vue
+++ b/app/assets/javascripts/notes/components/issue_note_form.vue
@@ -18,6 +18,10 @@
required: false,
default: 'Save comment',
},
+ discussion: {
+ type: Array,
+ required: false,
+ }
},
data() {
const { getIssueData, getNotesData } = this.$store.getters;
@@ -44,9 +48,14 @@
},
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');
+ debugger;
+ const lastNoteInDiscussion = this.$store.getters.getDiscussionLastNote(this.discussion);
+
if (myLastNoteId) {
eventHub.$emit('enterEditMode', {
noteId: parseInt(myLastNoteId.replace('note_', ''), 10),
@@ -116,7 +125,7 @@
{{saveButtonTitle}}
</button>
<button
- @click="cancelHandler"
+ @click="cancelHandler()"
class="btn btn-nr btn-cancel note-edit-cancel"
type="button">
Cancel
diff --git a/app/assets/javascripts/notes/components/issue_notes_app.vue b/app/assets/javascripts/notes/components/issue_notes_app.vue
index 21f9e7089bb..964ad5312b9 100644
--- a/app/assets/javascripts/notes/components/issue_notes_app.vue
+++ b/app/assets/javascripts/notes/components/issue_notes_app.vue
@@ -60,6 +60,7 @@
setNotesData: 'setNotesData',
setIssueData: 'setIssueData',
setUserData: 'setUserData',
+ setLastFetchedAt: 'setLastFetchedAt'
}),
getComponentName(note) {
if (note.isPlaceholderNote) {
@@ -86,7 +87,10 @@
this.checkLocationHash();
});
})
- .catch(() => Flash('Something went wrong while fetching issue comments. Please try again.'));
+ .catch((error) => {
+ console.log(error)
+ Flash('Something went wrong while fetching issue comments. Please try again.')
+ });
},
initPolling() {
this.setLastFetchedAt(this.getNotesDataByProp('lastFetchedAt'));
@@ -98,7 +102,10 @@
.then((res) => {
this.setLastFetchedAt(res.lastFetchedAt);
})
- .catch(() => Flash('Something went wrong while fetching latest comments.'));
+ .catch((error) =>{
+ console.log(error)
+ Flash('Something went wrong while fetching latest comments.')
+ } );
}, 15000);
},
bindEventHubListeners() {
diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js
index 83f18886b24..c454b834649 100644
--- a/app/assets/javascripts/notes/stores/getters.js
+++ b/app/assets/javascripts/notes/stores/getters.js
@@ -21,3 +21,16 @@ export const notesById = (state) => {
return notesByIdObject;
};
+
+const reverseNotes = array => array.slice(0).reverse();
+const isLastNote = (note, userId) => !note.system && note.author.id === userId;
+
+export const getCurrentUserLastNote = state => userId => reverseNotes(state.notes)
+ .reduce((acc, note) => {
+ acc.push(reverseNotes(note.notes).find(el => isLastNote(el, userId)));
+ return acc;
+ }, []).filter(el => el !== undefined)[0];
+
+export const getDiscussionLastNote = state => (discussion, userId) => reverseNotes(discussion[0].notes)
+ .find(el => isLastNote(el, userId));
+