Commit 66f4af5c authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Refactor toggle to work with delegated handler.

parent c77b2649
...@@ -43,6 +43,13 @@ export default { ...@@ -43,6 +43,13 @@ export default {
this.signInLink = signInLink.getAttribute('href'); this.signInLink = signInLink.getAttribute('href');
} }
}, },
methods: {
toggleDiscussion() {
this.$store.commit('toggleDiscussion', {
discussionId: this.note.id,
});
}
},
}; };
</script> </script>
...@@ -64,7 +71,7 @@ export default { ...@@ -64,7 +71,7 @@ export default {
:createdAt="discussion.created_at" :createdAt="discussion.created_at"
:notePath="discussion.path" :notePath="discussion.path"
:includeToggle="true" :includeToggle="true"
:discussionId="note.id" :toggleHandler="toggleDiscussion"
actionText="started a discussion" /> actionText="started a discussion" />
<issue-note-edited-text <issue-note-edited-text
v-if="note.last_updated_by" v-if="note.last_updated_by"
......
...@@ -30,21 +30,14 @@ export default { ...@@ -30,21 +30,14 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
discussionId: { toggleHandler: {
type: String, type: Function,
required: false, required: false,
}, },
}, },
components: { components: {
TimeAgoTooltip, TimeAgoTooltip,
}, },
methods: {
toggle() {
this.$store.commit('toggleDiscussion', {
discussionId: this.discussionId,
});
},
},
}; };
</script> </script>
...@@ -78,7 +71,7 @@ export default { ...@@ -78,7 +71,7 @@ export default {
v-if="includeToggle" v-if="includeToggle"
class="discussion-actions"> class="discussion-actions">
<button <button
@click="toggle" @click="toggleHandler"
class="note-action-button discussion-toggle-button js-toggle-button" class="note-action-button discussion-toggle-button js-toggle-button"
type="button"> type="button">
<i <i
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
import service from '../services/issue_notes_service'; import service from '../services/issue_notes_service';
const findNoteObjectById = (notes, id) => {
return notes.filter(n => n.id === id)[0];
};
const state = { const state = {
notes: [], notes: [],
}; };
...@@ -18,7 +22,7 @@ const mutations = { ...@@ -18,7 +22,7 @@ const mutations = {
storeState.notes = notes; storeState.notes = notes;
}, },
toggleDiscussion(storeState, { discussionId }) { toggleDiscussion(storeState, { discussionId }) {
const [discussion] = storeState.notes.filter(note => note.id === discussionId); const discussion = findNoteObjectById(storeState.notes, discussionId);
discussion.expanded = !discussion.expanded; discussion.expanded = !discussion.expanded;
}, },
......
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