diff --git a/frontend/src/app/core/mud/components/mud-output/mud-output.component.ts b/frontend/src/app/core/mud/components/mud-output/mud-output.component.ts index 6bc1d1cd..3f66306a 100644 --- a/frontend/src/app/core/mud/components/mud-output/mud-output.component.ts +++ b/frontend/src/app/core/mud/components/mud-output/mud-output.component.ts @@ -3,7 +3,10 @@ import { AfterViewInit, Component, ElementRef, + EventEmitter, Input, + OnDestroy, + Output, ViewChild, } from '@angular/core'; import { BehaviorSubject, Observable } from 'rxjs'; @@ -15,13 +18,18 @@ import { IMudMessage } from '../../types/mud-message'; templateUrl: './mud-output.component.html', styleUrls: ['./mud-output.component.scss'], }) -export class MudOutputComponent implements AfterViewChecked, AfterViewInit { +export class MudOutputComponent + implements AfterViewChecked, AfterViewInit, OnDestroy +{ + ngOnDestroy(): void { + console.log('DESTROY!'); + } private readonly linesSubject = new BehaviorSubject([]); - private canScrollToBottom = true; + private isScrollAtBottom = true; - @ViewChild('container', { static: true }) - private readonly outputContainer!: ElementRef; + @ViewChild('container', { static: false }) + private readonly outputContainer?: ElementRef; protected readonly lines$: Observable = this.linesSubject.asObservable(); @@ -47,16 +55,21 @@ export class MudOutputComponent implements AfterViewChecked, AfterViewInit { @Input({ required: false }) public autoScroll: boolean = false; + @Output() + public readonly onScrolled = new EventEmitter(); + public ngAfterViewChecked() { - if (this.canScrollToBottom && this.autoScroll) { + if (this.isScrollAtBottom && this.autoScroll) { this.scrollToBottom(); } } public ngAfterViewInit(): void { - this.outputContainer.nativeElement.onscroll = (event: Event) => { - this.onScroll(event); - }; + if (this.outputContainer?.nativeElement !== undefined) { + this.outputContainer.nativeElement.onscroll = (event: Event) => { + this.onScroll(event); + }; + } } private onScroll(event: Event): void { @@ -67,11 +80,15 @@ export class MudOutputComponent implements AfterViewChecked, AfterViewInit { element.scrollHeight - element.scrollTop - element.clientHeight, ) <= tolerance; - this.canScrollToBottom = atBottom; + this.onScrolled.emit(atBottom); + + this.isScrollAtBottom = atBottom; } - private scrollToBottom(): void { - this.outputContainer.nativeElement.scrollTop = - this.outputContainer.nativeElement.scrollHeight; + public scrollToBottom(): void { + if (this.outputContainer?.nativeElement !== undefined) { + this.outputContainer.nativeElement.scrollTop = + this.outputContainer.nativeElement.scrollHeight; + } } } diff --git a/frontend/src/app/core/mud/mud-client/mud-client.component.html b/frontend/src/app/core/mud/mud-client/mud-client.component.html index f14e32e6..bc85f7d1 100644 --- a/frontend/src/app/core/mud/mud-client/mud-client.component.html +++ b/frontend/src/app/core/mud/mud-client/mud-client.component.html @@ -1,42 +1,63 @@ - - - - - + + + + + + + + + + + - - - - + +
+ + +
+
- -
-

Disconnected!

- -
-
- - + +
+

Disconnected!

+ +
+
+ diff --git a/frontend/src/app/core/mud/mud-client/mud-client.component.scss b/frontend/src/app/core/mud/mud-client/mud-client.component.scss index 958eb7d3..87e19e2f 100644 --- a/frontend/src/app/core/mud/mud-client/mud-client.component.scss +++ b/frontend/src/app/core/mud/mud-client/mud-client.component.scss @@ -35,6 +35,11 @@ app-mud-output { flex: 1 1 100%; + overflow: hidden; + + &#test { + flex: 1 1 0%; + } } app-mud-input { diff --git a/frontend/src/app/core/mud/mud-client/mud-client.component.ts b/frontend/src/app/core/mud/mud-client/mud-client.component.ts index 96c4a3f0..4932709f 100644 --- a/frontend/src/app/core/mud/mud-client/mud-client.component.ts +++ b/frontend/src/app/core/mud/mud-client/mud-client.component.ts @@ -1,25 +1,38 @@ -import { Component, HostListener, ViewChild } from '@angular/core'; -import { Observable } from 'rxjs'; +import { + AfterViewChecked, + Component, + HostListener, + ViewChild, +} from '@angular/core'; +import { BehaviorSubject, Observable } from 'rxjs'; import { MudInputComponent } from '../components/mud-input/mud-input.component'; import { MudService } from '../mud.service'; import { IMudMessage } from '../types/mud-message'; import { isSecureString, SecureString } from '@mudlet3/frontend/shared'; +import { MudOutputComponent } from 'src/app/core/mud/components/mud-output/mud-output.component'; @Component({ selector: 'app-mud-client', templateUrl: './mud-client.component.html', styleUrls: ['./mud-client.component.scss'], }) -export class MudclientComponent { +export class MudclientComponent implements AfterViewChecked { + private readonly mode = new BehaviorSubject<'normal' | 'split'>('normal'); + protected readonly output$: Observable; protected readonly isConnected$: Observable; protected readonly showEcho$: Observable; + protected readonly mode$ = this.mode.asObservable(); + @ViewChild(MudInputComponent, { static: false }) private mudInputComponent?: MudInputComponent; + @ViewChild('mainOutputSplit', { static: false }) + private mudOutputComponent?: MudOutputComponent; + public v = { // scrollLock: true, // sizeCalculated: false, @@ -52,6 +65,12 @@ export class MudclientComponent { this.mudService.connect(); + // this.mode$.subscribe((mode) => { + // if (mode === 'split') { + // this.mudOutputComponent?.scrollToBottom(); + // } + // }); + // this.invlist = new InventoryList(); // Todo[myst]: Herausfinden, was der cookieService alles unter 'mudcolors' gespeichert hat @@ -67,11 +86,20 @@ export class MudclientComponent { // this.v.stdbg = 'black'; // } } + ngAfterViewChecked(): void { + if (this.mode.value === 'split') { + this.mudOutputComponent?.scrollToBottom(); + } + } // protected onDisconnectClicked() { // this.mudService.disconnect(); // } + protected onSplitToggle() { + this.mode.next(this.mode.value === 'normal' ? 'split' : 'normal'); + } + protected onConnectClicked() { this.mudService.connect(); }