From ec7e79c61ab23d4ae214da2f08b6db2adcf60677 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Sat, 8 Sep 2018 14:51:11 +0200 Subject: [PATCH] Fix marking as read when scrolling --- src/components/Timeline.vue | 22 +++++++--------------- src/store.js | 13 +++++++++++++ 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 27d63d3..ff29cba 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -36,7 +36,7 @@ computed: { items() { return this.timeline.items.filter((item) => { - return item.type === 'entry'; + return item.type === 'entry' || item.type === 'cite'; }) } }, @@ -62,20 +62,12 @@ }, handleScroll() { // 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) { - let count = 0 - this.$children.forEach((child) => { - 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.$store.dispatch('bottomReached') + return } this.$children.forEach((child) => { @@ -97,7 +89,7 @@ window.addEventListener('scroll', this.handleScroll); }, - destroyed() { + beforeDestroy() { window.removeEventListener('scroll', this.handleScroll); } } diff --git a/src/store.js b/src/store.js index 3cda683..4365139 100644 --- a/src/store.js +++ b/src/store.js @@ -140,6 +140,19 @@ export default new Vuex.Store({ }).then(() => { 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') + } } } })