Commit a2da945a authored by Tom Quirk's avatar Tom Quirk

Abstract discussion scroll logic into method

parent 1f0b9525
...@@ -62,22 +62,14 @@ export default { ...@@ -62,22 +62,14 @@ export default {
activeDiscussion: { activeDiscussion: {
query: activeDiscussionQuery, query: activeDiscussionQuery,
result({ data }) { result({ data }) {
const activeDiscussionId = data.activeDiscussion.id;
if (this.discussion.resolved && !this.resolvedDiscussionsExpanded) { if (this.discussion.resolved && !this.resolvedDiscussionsExpanded) {
return; return;
} }
this.$nextTick(() => { this.$nextTick(() => {
// We watch any changes to the active discussion from the design pins and scroll to this discussion if it exists // We watch any changes to the active discussion from the design pins and scroll to this discussion if it exists.
// We don't want scrollIntoView to be triggered from the discussion click itself // We don't want scrollIntoView to be triggered from the discussion click itself.
if ( if (this.$el && this.shouldScrollToDiscussion(data.activeDiscussion)) {
this.$el &&
activeDiscussionId &&
[ACTIVE_DISCUSSION_SOURCE_TYPES.pin, ACTIVE_DISCUSSION_SOURCE_TYPES.url].includes(
data.activeDiscussion.source,
) &&
activeDiscussionId === this.discussion.notes[0].id
) {
this.$el.scrollIntoView({ this.$el.scrollIntoView({
behavior: 'smooth', behavior: 'smooth',
inline: 'start', inline: 'start',
...@@ -142,6 +134,18 @@ export default { ...@@ -142,6 +134,18 @@ export default {
isFormVisible() { isFormVisible() {
return this.isFormRendered && this.discussionWithOpenForm === this.discussion.id; return this.isFormRendered && this.discussionWithOpenForm === this.discussion.id;
}, },
shouldScrollToDiscussion(activeDiscussion) {
const ALLOWED_ACTIVE_DISCUSSION_SOURCES = [
ACTIVE_DISCUSSION_SOURCE_TYPES.pin,
ACTIVE_DISCUSSION_SOURCE_TYPES.url,
];
const { id: activeDiscussionId, source: activeDiscussionSource } = activeDiscussion;
return (
ALLOWED_ACTIVE_DISCUSSION_SOURCES.includes(activeDiscussionSource) &&
activeDiscussionId === this.discussion.notes[0].id
);
},
}, },
methods: { methods: {
addDiscussionComment( addDiscussionComment(
......
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