Commit 717c3022 authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Implement up arrow to edit last note.

parent d45a8e00
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import UserAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import UserAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import MarkdownField from '../../vue_shared/components/markdown/field.vue'; import MarkdownField from '../../vue_shared/components/markdown/field.vue';
import IssueNoteSignedOutWidget from './issue_note_signed_out_widget.vue'; import IssueNoteSignedOutWidget from './issue_note_signed_out_widget.vue';
import eventHub from '../event_hub';
export default { export default {
props: {}, props: {},
...@@ -101,6 +102,17 @@ export default { ...@@ -101,6 +102,17 @@ export default {
handleError() { handleError() {
new Flash('Something went wrong while adding your comment. Please try again.'); // eslint-disable-line new Flash('Something went wrong while adding your comment. Please try again.'); // eslint-disable-line
}, },
editMyLastNote() {
if (this.note === '') {
const myLastNoteId = $('.js-my-note').last().attr('id');
if (myLastNoteId) {
eventHub.$emit('EnterEditMode', {
noteId: parseInt(myLastNoteId.replace('note_', ''), 10),
});
}
}
},
}, },
mounted() { mounted() {
const issuableDataEl = document.getElementById('js-issuable-app-initial-data'); const issuableDataEl = document.getElementById('js-issuable-app-initial-data');
...@@ -143,6 +155,7 @@ export default { ...@@ -143,6 +155,7 @@ export default {
ref="textarea" ref="textarea"
slot="textarea" slot="textarea"
placeholder="Write a comment or drag your files here..." placeholder="Write a comment or drag your files here..."
@keydown.up="editMyLastNote"
@keydown.meta.enter="handleSave()"> @keydown.meta.enter="handleSave()">
</textarea> </textarea>
</markdown-field> </markdown-field>
......
...@@ -6,6 +6,7 @@ import UserAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_ ...@@ -6,6 +6,7 @@ import UserAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_
import IssueNoteHeader from './issue_note_header.vue'; import IssueNoteHeader from './issue_note_header.vue';
import IssueNoteActions from './issue_note_actions.vue'; import IssueNoteActions from './issue_note_actions.vue';
import IssueNoteBody from './issue_note_body.vue'; import IssueNoteBody from './issue_note_body.vue';
import eventHub from '../event_hub';
export default { export default {
props: { props: {
...@@ -37,6 +38,7 @@ export default { ...@@ -37,6 +38,7 @@ export default {
return { return {
'is-editing': this.isEditing, 'is-editing': this.isEditing,
'disabled-content': this.isDeleting, 'disabled-content': this.isDeleting,
'js-my-note': this.author.id === window.gon.current_user_id,
target: this.targetNoteHash === this.noteAnchorId, target: this.targetNoteHash === this.noteAnchorId,
}; };
}, },
...@@ -100,6 +102,14 @@ export default { ...@@ -100,6 +102,14 @@ export default {
this.isEditing = false; this.isEditing = false;
}, },
}, },
created() {
eventHub.$on('EnterEditMode', ({ noteId }) => {
if (noteId === this.note.id) {
this.isEditing = true;
this.$store.dispatch('scrollToNoteIfNeeded', $(this.$el));
}
});
},
}; };
</script> </script>
......
<script> <script>
import MarkdownField from '../../vue_shared/components/markdown/field.vue'; import MarkdownField from '../../vue_shared/components/markdown/field.vue';
import eventHub from '../event_hub';
export default { export default {
props: { props: {
...@@ -39,6 +40,18 @@ export default { ...@@ -39,6 +40,18 @@ export default {
note: this.note, note: this.note,
}); });
}, },
editMyLastNote() {
if (this.note === '') {
const discussion = $(this.$el).closest('.discussion-notes');
const myLastNoteId = discussion.find('.js-my-note').last().attr('id');
if (myLastNoteId) {
eventHub.$emit('EnterEditMode', {
noteId: parseInt(myLastNoteId.replace('note_', ''), 10),
});
}
}
},
}, },
computed: { computed: {
isDirty() { isDirty() {
...@@ -75,6 +88,7 @@ export default { ...@@ -75,6 +88,7 @@ export default {
slot="textarea" slot="textarea"
placeholder="Write a comment or drag your files here..." placeholder="Write a comment or drag your files here..."
@keydown.meta.enter="handleUpdate" @keydown.meta.enter="handleUpdate"
@keydown.up="editMyLastNote"
@keydown.esc="cancelHandler(true)"> @keydown.esc="cancelHandler(true)">
</textarea> </textarea>
</markdown-field> </markdown-field>
......
...@@ -197,10 +197,10 @@ const actions = { ...@@ -197,10 +197,10 @@ const actions = {
if (!skipMutalityCheck && (awardName === 'thumbsup' || awardName === 'thumbsdown')) { if (!skipMutalityCheck && (awardName === 'thumbsup' || awardName === 'thumbsdown')) {
const counterAward = awardName === 'thumbsup' ? 'thumbsdown' : 'thumbsup'; const counterAward = awardName === 'thumbsup' ? 'thumbsdown' : 'thumbsup';
const note = context.getters.notesById[noteId]; const targetNote = context.getters.notesById[noteId];
let amIAwarded = false; let amIAwarded = false;
note.award_emoji.forEach((a) => { targetNote.award_emoji.forEach((a) => {
if (a.name === counterAward && a.user.id === window.gon.current_user_id) { if (a.name === counterAward && a.user.id === window.gon.current_user_id) {
amIAwarded = true; amIAwarded = true;
} }
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
- if can_update && is_current_user - if can_update && is_current_user
= link_to "Close #{display_issuable_type}", close_issuable_url(issuable), method: button_method, = link_to "Close #{display_issuable_type}", close_issuable_url(issuable), method: button_method,
class: "hidden-xs hidden-sm btn btn-grouped btn-close #{issuable_button_visibility(issuable, true)}", title: "Close #{display_issuable_type}" class: "hidden-xs hidden-sm btn btn-grouped btn-close js-btn-issue-action #{issuable_button_visibility(issuable, true)}", title: "Close #{display_issuable_type}"
= link_to "Reopen #{display_issuable_type}", reopen_issuable_url(issuable), method: button_method, = link_to "Reopen #{display_issuable_type}", reopen_issuable_url(issuable), method: button_method,
class: "hidden-xs hidden-sm btn btn-grouped btn-reopen #{issuable_button_visibility(issuable, false)}", title: "Reopen #{display_issuable_type}" class: "hidden-xs hidden-sm btn btn-grouped btn-reopen js-btn-issue-action #{issuable_button_visibility(issuable, false)}", title: "Reopen #{display_issuable_type}"
- elsif can_update && !is_current_user - elsif can_update && !is_current_user
= render 'shared/issuable/close_reopen_report_toggle', issuable: issuable = render 'shared/issuable/close_reopen_report_toggle', issuable: issuable
- else - else
......
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