diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 6ad9fa9..7c455de 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -51,6 +51,9 @@ }, prevPage() { this.$emit('getPage', {uid: this.channel.uid, before: this.timeline.paging.before}) + }, + markRead(channel, id) { + return this.$store.dispatch('markRead', {channel:channel, entry: id }) } }, @@ -59,12 +62,18 @@ // let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === document.documentElement.offsetHeight; let bottomOfWindow = document.documentElement.scrollTop + window.innerHeight === this.$el.offsetHeight + document.documentElement.offsetHeight + 20; if (bottomOfWindow) { + let count = 0 this.$children.forEach((child) => { if (child.$props.item && !child.$props.item._is_read) { child.$props.item._is_read = true - this.$store.dispatch('markRead', child.$props.item.uid) + let item = child.$props.item + this.markRead(this.channel.uid, item._id) + count++ } }) + if (count > 0) { + this.$store.dispatch('fetchChannels') + } } this.$children.forEach((child) => { @@ -72,7 +81,8 @@ if (rect.top + rect.height < 100) { if (child.$props.item && !child.$props.item._is_read) { child.$props.item._is_read = true - this.$store.dispatch('markRead', {channel:this.channel.uid, entry: child.$props.item._id }).then(() => { + let item = child.$props.item + this.markRead(this.channel.uid, item._id).then(() => { this.$store.dispatch('fetchChannels') }) } diff --git a/src/store.js b/src/store.js index 90767a4..9866e2e 100644 --- a/src/store.js +++ b/src/store.js @@ -83,8 +83,6 @@ export default new Vuex.Store({ commit('newAccessToken', response) }, markRead(x, {channel, entry}) { - // eslint-disable-next-line - console.log(channel, entry) let url = 'https://microsub.stuifzandapp.com/microsub?action=timeline&method=mark_read&channel=' + encodeURIComponent(channel) + '&entry=' + encodeURIComponent(entry); return fetch(url, { method: 'POST',