From 2d1b21b804b89f01b66c014da86d1e9325c41638 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Mon, 27 Aug 2018 23:19:32 +0200 Subject: [PATCH] Cleanup mark_read --- src/components/Timeline.vue | 14 ++++++++++++-- src/store.js | 2 -- 2 files changed, 12 insertions(+), 4 deletions(-) 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',