added infinite scroll lock

This commit is contained in:
Nicolas Constant 2020-05-29 03:38:38 -04:00
parent 391c515b30
commit 185bb64a42
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 10 additions and 11 deletions

View File

@ -1,16 +1,14 @@
import { OnInit, Input, OnDestroy, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { Store } from '@ngxs/store';
import { Observable } from 'rxjs';
import { MastodonWrapperService } from '../../services/mastodon-wrapper.service';
import { AccountInfo } from '../../states/accounts.state';
import { StreamingService, StreamingWrapper } from '../../services/streaming.service';
import { StreamingWrapper } from '../../services/streaming.service';
import { NotificationService } from '../../services/notification.service';
import { ToolsService, OpenThreadEvent } from '../../services/tools.service';
import { StatusWrapper } from '../../models/common.model';
import { Status } from '../../services/models/mastodon.interfaces';
import { StreamElement } from '../../states/streams.state';
import { TimeLineModeEnum } from '../../states/settings.state';
export abstract class TimelineBase implements OnInit, OnDestroy {
@ -21,7 +19,6 @@ export abstract class TimelineBase implements OnInit, OnDestroy {
hasContentWarnings = false;
timelineLoadingMode: TimeLineModeEnum = TimeLineModeEnum.OnTop;
protected account: AccountInfo;
protected websocketStreaming: StreamingWrapper;
@ -47,13 +44,9 @@ export abstract class TimelineBase implements OnInit, OnDestroy {
@ViewChild('statusstream') public statustream: ElementRef;
constructor(
// protected readonly store: Store,
protected readonly toolsService: ToolsService,
protected readonly notificationService: NotificationService,
// protected readonly streamingService: StreamingService,
protected readonly mastodonService: MastodonWrapperService) {
// this.streams$ = this.store.select(state => state.streamsstatemodel.streams);
}
abstract ngOnInit();
@ -61,7 +54,6 @@ export abstract class TimelineBase implements OnInit, OnDestroy {
protected abstract scrolledToTop();
protected abstract statusProcessOnGoToTop();
protected abstract getNextStatuses(): Promise<Status[]>;
// protected abstract load(streamElement: StreamElement);
onScroll() {
var element = this.statustream.nativeElement as HTMLElement;

View File

@ -23,6 +23,8 @@ export class DirectMessagesComponent implements OnInit {
isThread = false;
hasContentWarnings = false;
private isProcessingInfiniteScroll: boolean;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@ -78,7 +80,7 @@ export class DirectMessagesComponent implements OnInit {
var element = this.statustream.nativeElement as HTMLElement;
const atBottom = element.scrollHeight <= element.clientHeight + element.scrollTop + 1000;
if (atBottom) {
if (atBottom && !this.isProcessingInfiniteScroll) {
this.scrolledToBottom();
}
}
@ -89,6 +91,7 @@ export class DirectMessagesComponent implements OnInit {
const maxId = this.conversations[this.conversations.length - 1].conversation.last_status.id;
this.isLoading = true;
this.isProcessingInfiniteScroll = true;
this.mastodonService.getConversations(this.account.info, maxId)
.then((conversations: Conversation[]) => {
if (conversations.length === 0) {
@ -107,6 +110,7 @@ export class DirectMessagesComponent implements OnInit {
})
.then(() => {
this.isLoading = false;
this.isProcessingInfiniteScroll = false;
});
}

View File

@ -17,6 +17,7 @@ import { OpenThreadEvent, ToolsService } from '../../../../services/tools.servic
})
export class NotificationsComponent implements OnInit, OnDestroy {
notifications: NotificationWrapper[] = [];
private isProcessingInfiniteScroll: boolean;
isLoading = false;
@Output() browseAccountEvent = new EventEmitter<string>();
@ -89,7 +90,7 @@ export class NotificationsComponent implements OnInit, OnDestroy {
var element = this.statustream.nativeElement as HTMLElement;
const atBottom = element.scrollHeight <= element.clientHeight + element.scrollTop + 1000;
if (atBottom) {
if (atBottom && !this.isProcessingInfiniteScroll) {
this.scrolledToBottom();
}
}
@ -98,6 +99,7 @@ export class NotificationsComponent implements OnInit, OnDestroy {
if (this.isLoading || this.maxReached || this.notifications.length === 0) return;
this.isLoading = true;
this.isProcessingInfiniteScroll = true;
this.mastodonService.getNotifications(this.account.info, ['mention'], this.lastId)
.then((notifications: Notification[]) => {
@ -121,6 +123,7 @@ export class NotificationsComponent implements OnInit, OnDestroy {
})
.then(() => {
this.isLoading = false;
this.isProcessingInfiniteScroll = false;
});
}