From 270204235b8f6c6a5615b53bc774dc943ed6d820 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 17 Sep 2018 21:57:44 -0400 Subject: [PATCH] clean up stream when on top functionnal --- .../components/stream/stream.component.html | 3 +- src/app/components/stream/stream.component.ts | 36 +++++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/app/components/stream/stream.component.html b/src/app/components/stream/stream.component.html index 75e57d8a..884b57dd 100644 --- a/src/app/components/stream/stream.component.html +++ b/src/app/components/stream/stream.component.html @@ -2,9 +2,10 @@

{{ streamElement.name.toUpperCase() }}

-
+
+ \ No newline at end of file diff --git a/src/app/components/stream/stream.component.ts b/src/app/components/stream/stream.component.ts index df6294ba..3df37602 100644 --- a/src/app/components/stream/stream.component.ts +++ b/src/app/components/stream/stream.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Input, ElementRef, ViewChild } from "@angular/core"; +import { Component, OnInit, Input, ElementRef, ViewChild, HostListener } from "@angular/core"; import { AccountWrapper } from "../../models/account.models"; import { StreamElement, StreamTypeEnum } from "../../states/streams.state"; import { StreamingService, StreamingWrapper, EventEnum, StatusUpdate } from "../../services/streaming.service"; @@ -47,14 +47,34 @@ export class StreamComponent implements OnInit { @ViewChild('statusstream') public statustream: ElementRef; goToTop(): boolean { - const stream = this.statustream.nativeElement as HTMLElement; + const stream = this.statustream.nativeElement as HTMLElement; stream.scrollTo({ top: 0, behavior: 'smooth' - }); + }); return false; } + private streamPositionnedAtTop: boolean = true; + private streamPositionnedAtBottom: boolean; + + onScroll() { + var element = this.statustream.nativeElement as HTMLElement; + const atBottom = element.scrollHeight - element.scrollTop === element.clientHeight; + const atTop = element.scrollTop === 0; + + this.streamPositionnedAtTop = false; + this.streamPositionnedAtBottom = false; + + if (atBottom) { + console.log('Bottom reached!!'); + this.streamPositionnedAtBottom = true; + } else if (atTop) { + console.log('Top reached!!'); + this.streamPositionnedAtTop = true; + } + } + private getRegisteredAccounts(): AccountInfo[] { var regAccounts = this.store.snapshot().registeredaccounts.accounts; return regAccounts; @@ -79,6 +99,16 @@ export class StreamComponent implements OnInit { } } } + + this.checkAndCleanUpStream(); }); } + + private checkAndCleanUpStream(): void { + if (this.streamPositionnedAtTop && this.statuses.length > 60) { + console.log(`clean up start! ${this.statuses.length}`); + this.statuses.length = 40; + console.log(`clean up ends! ${this.statuses.length}`); + } + } } \ No newline at end of file