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 {
},
mounted() {
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() {
this.$refs.scrollable.removeEventListener('scroll', this.handleDebouncedScroll);
},
beforeUpdate() {
const { scrollHeight, scrollTop } = this.$refs.scrollable;
this.scrollPosition = { scrollHeight, scrollTop };
if (!this.emptyBlubber) {
const { scrollHeight, scrollTop } = this.$refs.scrollable;
this.scrollPosition = { scrollHeight, scrollTop };
}
},
updated() {
// maintain scroll position when loading older comments
const newScrollTop =
this.$refs.scrollable.scrollHeight - this.scrollPosition.scrollHeight + this.scrollPosition.scrollTop;
this.$refs.scrollable.scrollTo(0, newScrollTop);
if (!this.emptyBlubber) {
// maintain scroll position when loading older comments
const newScrollTop =
this.$refs.scrollable.scrollHeight - this.scrollPosition.scrollHeight + this.scrollPosition.scrollTop;
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) {
......@@ -258,3 +271,8 @@ function setBlubberMemory(thread, memory) {
}
}
</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.
Finish editing this message first!
Please register or to comment