Commit a32f291a authored by Fatih Acet's avatar Fatih Acet

IssueNotesRefactor: Separate mounted blocks to methods.

parent 7edc1bc3
......@@ -253,7 +253,7 @@ class AwardsHandler {
});
$('.emoji-menu').removeClass('is-visible');
$('.js-add-award.is-active').removeClass('is-active');
return $('.js-add-award.is-active').removeClass('is-active');
}
addAwardToEmojiBar(votesBlock, emoji, checkForMutuality) {
......
......@@ -44,22 +44,8 @@ export default {
componentData(note) {
return note.individual_note ? note.notes[0] : note;
},
checkLocationHash() {
const hash = gl.utils.getLocationHash();
const $el = $(`#${hash}`);
if (hash && $el) {
const isInViewport = gl.utils.isInViewport($el[0]);
this.$store.commit('setTargetNoteHash', hash);
if (!isInViewport) {
gl.utils.scrollToElement($el);
}
}
},
},
mounted() {
const { discussionsPath, notesPath, lastFetchedAt } = this.$el.parentNode.dataset;
fetchNotes() {
const { discussionsPath } = this.$el.parentNode.dataset;
this.$store.dispatch('fetchNotes', discussionsPath)
.then(() => {
......@@ -73,7 +59,9 @@ export default {
.catch(() => {
new Flash('Something went wrong while fetching issue comments. Please try again.'); // eslint-disable-line
});
},
initPolling() {
const { notesPath, lastFetchedAt } = this.$el.parentNode.dataset;
const options = {
endpoint: `${notesPath}?full_data=1`,
lastFetchedAt,
......@@ -88,8 +76,9 @@ export default {
.catch(() => {
new Flash('Something went wrong while fetching latest comments.'); // eslint-disable-line
});
}, 6000);
}, 15000);
},
bindEventHubListeners() {
eventHub.$on('toggleAward', (data) => {
const { awardName, noteId } = data;
const endpoint = this.notesById[noteId].toggle_award_path;
......@@ -97,6 +86,25 @@ export default {
this.$store.dispatch('toggleAward', { endpoint, awardName, noteId });
});
},
checkLocationHash() {
const hash = gl.utils.getLocationHash();
const $el = $(`#${hash}`);
if (hash && $el) {
const isInViewport = gl.utils.isInViewport($el[0]);
this.$store.commit('setTargetNoteHash', hash);
if (!isInViewport) {
gl.utils.scrollToElement($el);
}
}
},
},
mounted() {
this.fetchNotes();
this.initPolling();
this.bindEventHubListeners();
},
};
</script>
......
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