fix bug in behavior of infinite scroll

This commit is contained in:
Nicolas Constant 2018-09-17 23:05:49 -04:00
parent b5e22f61c4
commit 394614e93a
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
1 changed files with 10 additions and 1 deletions

View File

@ -19,6 +19,7 @@ export class StreamComponent implements OnInit {
statuses: Status[] = [];
private bufferStream: Status[] = [];
private bufferWasCleared: boolean;
@Input()
set streamElement(streamElement: StreamElement) {
@ -78,6 +79,11 @@ export class StreamComponent implements OnInit {
private scrolledToTop() {
this.streamPositionnedAtTop = true;
if(this.bufferWasCleared) {
this.statuses.length = 0;
this.bufferWasCleared = false;
}
for (const status of this.bufferStream) {
this.statuses.unshift(status); //TODO check order of status
}
@ -126,7 +132,7 @@ export class StreamComponent implements OnInit {
if (this.streamPositionnedAtTop) {
this.statuses.unshift(update.status);
} else {
this.bufferStream.unshift(update.status);
this.bufferStream.push(update.status);
}
}
}
@ -136,13 +142,16 @@ export class StreamComponent implements OnInit {
});
}
private checkAndCleanUpStream(): void {
if (this.streamPositionnedAtTop && this.statuses.length > 60) {
this.statuses.length = 40;
}
if (this.bufferStream.length > 60) {
this.bufferWasCleared = true;
this.bufferStream.length = 40;
}
}
}