Automatically refetch timeline every 30sec

Signed-off-by: Louis Chemineau <louis@chmn.me>
pull/1687/head
Louis Chemineau 2023-03-21 11:22:42 +01:00
rodzic 5a419ebea5
commit 057ae4b6cd
1 zmienionych plików z 21 dodań i 2 usunięć

Wyświetl plik

@ -70,6 +70,7 @@ export default {
return {
infoHidden: false,
state: [],
intervalId: -1,
emptyContent: {
default: {
image: 'img/undraw/posts.svg',
@ -141,8 +142,11 @@ export default {
return this.$store.getters.getTimeline
},
},
beforeMount() {
mounted() {
this.intervalId = setInterval(() => this.fetchNewStatuses(), 30 * 1000)
},
destroyed() {
clearInterval(this.intervalId)
},
methods: {
async infiniteHandler($state) {
@ -159,6 +163,21 @@ export default {
$state.complete()
}
},
async fetchNewStatuses() {
try {
const response = await this.$store.dispatch('fetchTimeline', {
account: this.currentUser.uid,
min_id: this.timeline[0]?.id ?? undefined,
})
if (response.length > 0) {
this.fetchNewStatuses()
}
} catch (error) {
showError('Failed to load newer timeline entries')
logger.error('Failed to load newer timeline entries', { error })
}
},
},
}
</script>