From 2c0d240c8a46904092e35e6267b8627103eb328c Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 26 Feb 2019 00:16:28 -0700 Subject: [PATCH] Update Timeline component, add infinite scroll notifications --- resources/assets/js/components/Timeline.vue | 41 +++++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/resources/assets/js/components/Timeline.vue b/resources/assets/js/components/Timeline.vue index 76e6abc76..a518ce327 100644 --- a/resources/assets/js/components/Timeline.vue +++ b/resources/assets/js/components/Timeline.vue @@ -227,12 +227,12 @@ See All

-
+
Loading...
-
+
@@ -262,7 +262,12 @@

- +
+
+ +
+
+

@@ -318,6 +323,7 @@ min_id: 0, max_id: 0, notifications: {}, + notificationCursor: 2, stories: {}, suggestions: {}, loading: true, @@ -438,17 +444,44 @@ fetchNotifications() { axios.get('/api/v1/notifications') .then(res => { - this.notifications = res.data.filter(n => { + let data = res.data.filter(n => { if(n.type == 'share' && !status) { return false; } return true; }); + this.notifications = data; $('.notification-card .loader').addClass('d-none'); $('.notification-card .contents').removeClass('d-none'); }); }, + infiniteNotifications($state) { + if(this.notificationCursor > 10) { + $state.complete(); + return; + } + axios.get('/api/v1/notifications', { + params: { + page: this.notificationCursor + } + }).then(res => { + if(res.data.length) { + let data = res.data.filter(n => { + if(n.type == 'share' && !status) { + return false; + } + return true; + }); + this.notifications.push(...data); + this.notificationCursor++; + $state.loaded(); + } else { + $state.complete(); + } + }); + }, + reportUrl(status) { let type = status.in_reply_to ? 'comment' : 'post'; let id = status.id;