added notification infinite-scroll #55
This commit is contained in:
parent
0b6814af4d
commit
18794ba0c7
@ -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>
|
@ -43,7 +43,7 @@
|
||||
|
||||
&__status {
|
||||
display: block;
|
||||
opacity: 0.55;
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user