added notification infinite-scroll #55

This commit is contained in:
Nicolas Constant 2019-03-27 23:34:29 -04:00
parent 0b6814af4d
commit 18794ba0c7
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 45 additions and 1 deletions

View File

@ -31,4 +31,6 @@
[isThreadDisplay]="false" (browseAccountEvent)="browseAccount($event)"
(browseHashtagEvent)="browseHashtag($event)" (browseThreadEvent)="browseThread($event)"></app-status>
</div>
<app-waiting-animation *ngIf="isLoading" class="waiting-icon"></app-waiting-animation>
</div>

View File

@ -43,7 +43,7 @@
&__status {
display: block;
opacity: 0.55;
opacity: 0.65;
}
}

View File

@ -75,6 +75,48 @@ export class NotificationsComponent implements OnInit, OnDestroy {
});
}
onScroll() {
var element = this.statustream.nativeElement as HTMLElement;
const atBottom = element.scrollHeight <= element.clientHeight + element.scrollTop + 1000;
if (atBottom) {
this.scrolledToBottom();
}
}
private scrolledToBottom() {
if (this.isLoading || this.maxReached || this.notifications.length === 0) return;
this.isLoading = true;
console.warn(`this.lastId ${this.lastId}`);
this.mastodonService.getNotifications(this.account.info, ['mention'], this.lastId)
.then((notifications: Notification[]) => {
console.warn(notifications);
// const statuses = result.map(x => x.status);
if (notifications.length === 0) {
this.maxReached = true;
return;
}
for (const s of notifications) {
const wrapper = new NotificationWrapper(s, this.account.info);
this.notifications.push(wrapper);
}
this.lastId = notifications[notifications.length - 1].id;
})
.catch(err => {
this.notificationService.notifyHttpError(err);
})
.then(() => {
this.isLoading = false;
});
}
}
class NotificationWrapper {