Fix marking as read when scrolling

This commit is contained in:
Peter Stuifzand 2018-09-08 14:51:11 +02:00
parent ae47582c08
commit ec7e79c61a
2 changed files with 20 additions and 15 deletions

View File

@ -36,7 +36,7 @@
computed: { computed: {
items() { items() {
return this.timeline.items.filter((item) => { return this.timeline.items.filter((item) => {
return item.type === 'entry'; return item.type === 'entry' || item.type === 'cite';
}) })
} }
}, },
@ -62,20 +62,12 @@
}, },
handleScroll() { handleScroll() {
// let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === document.documentElement.offsetHeight; // let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === document.documentElement.offsetHeight;
let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === this.$el.offsetHeight + document.documentElement.offsetHeight + 20; let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === this.$el.offsetHeight + document.documentElement.offsetHeight + 12
// eslint-disable-next-line
console.log(document.documentElement.scrollTop + window.innerHeight, this.$el.offsetHeight + document.documentElement.offsetHeight + 12)
if (bottomOfWindow) { if (bottomOfWindow) {
let count = 0 this.$store.dispatch('bottomReached')
this.$children.forEach((child) => { return
if (child.$props.item && !child.$props.item._is_read) {
child.$props.item._is_read = true
let item = child.$props.item
this.markRead(this.channel.uid, item)
count++
}
})
if (count > 0) {
this.$store.dispatch('fetchChannels')
}
} }
this.$children.forEach((child) => { this.$children.forEach((child) => {
@ -97,7 +89,7 @@
window.addEventListener('scroll', this.handleScroll); window.addEventListener('scroll', this.handleScroll);
}, },
destroyed() { beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll); window.removeEventListener('scroll', this.handleScroll);
} }
} }

View File

@ -140,6 +140,19 @@ export default new Vuex.Store({
}).then(() => { }).then(() => {
this.dispatch('fetchChannels') this.dispatch('fetchChannels')
}) })
},
bottomReached() {
let count = 0
this.state.timeline.items.forEach((item) => {
if (item && !item._is_read) {
item._is_read = true
this.dispatch('markRead', {channel: this.state.channel.uid, entry: item._id})
count++;
}
})
if (count > 0) {
this.dispatch('fetchChannels')
}
} }
} }
}) })