Skip to content
Snippets Groups Projects
Commit 989e6c9e authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

attach event handler only if posts are present and fix layout bug, fixes #5063

Closes #5063

Merge request studip/studip!3786
parent 102efecd
No related branches found
No related tags found
No related merge requests found
...@@ -213,33 +213,46 @@ export default { ...@@ -213,33 +213,46 @@ export default {
}, },
mounted() { mounted() {
this.handleDebouncedScroll = _.debounce(this.handleScroll, 100); this.handleDebouncedScroll = _.debounce(this.handleScroll, 100);
this.$refs.scrollable.addEventListener('scroll', this.handleDebouncedScroll);
// when everything is initialized
this.$nextTick(() => {
if (this.comments.length > 0) {
this.scrollDown();
}
const memory = getBlubberMemory(this.thread);
if (memory) {
this.composerText = memory;
}
});
}, },
beforeUnmount() { beforeUnmount() {
this.$refs.scrollable.removeEventListener('scroll', this.handleDebouncedScroll); this.$refs.scrollable.removeEventListener('scroll', this.handleDebouncedScroll);
}, },
beforeUpdate() { beforeUpdate() {
if (!this.emptyBlubber) {
const { scrollHeight, scrollTop } = this.$refs.scrollable; const { scrollHeight, scrollTop } = this.$refs.scrollable;
this.scrollPosition = { scrollHeight, scrollTop }; this.scrollPosition = { scrollHeight, scrollTop };
}
}, },
updated() { updated() {
if (!this.emptyBlubber) {
// maintain scroll position when loading older comments // maintain scroll position when loading older comments
const newScrollTop = const newScrollTop =
this.$refs.scrollable.scrollHeight - this.scrollPosition.scrollHeight + this.scrollPosition.scrollTop; this.$refs.scrollable.scrollHeight - this.scrollPosition.scrollHeight + this.scrollPosition.scrollTop;
this.$refs.scrollable.scrollTo(0, newScrollTop); this.$refs.scrollable.scrollTo(0, newScrollTop);
}
}, },
watch: {
emptyBlubber: {
handler(isEmpty) {
if (!isEmpty) {
this.$refs.scrollable.addEventListener('scroll', this.handleDebouncedScroll);
// when everything is initialized
this.$nextTick(() => {
if (this.comments.length > 0) {
this.scrollDown();
}
const memory = getBlubberMemory(this.thread);
if (memory) {
this.composerText = memory;
}
});
}
},
immediate: true,
}
}
}; };
function clearBlubberMemory(thread) { function clearBlubberMemory(thread) {
...@@ -258,3 +271,8 @@ function setBlubberMemory(thread, memory) { ...@@ -258,3 +271,8 @@ function setBlubberMemory(thread, memory) {
} }
} }
</script> </script>
<style lang="scss" scoped>
.empty_blubber_background {
flex: 1;
}
</style>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment