AltitudeWeb/frontend/src/app/pages/altitude/chat/chat.component.ts

52 lines
1.8 KiB
TypeScript
Raw Normal View History

import {Component, inject, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {ChatService} from '@pages/altitude/chat/service/chat.service';
import {HeaderComponent} from '@header/header.component';
import {MiniMessageInteractionService} from '@pages/altitude/chat/mini-message/mini-message-interaction.service';
import {FullSizeComponent} from '@shared-components/full-size/full-size.component';
import {ChatBoxComponent} from '@pages/altitude/chat/components/chat/chat-box.component';
import {ServerListComponent} from '@pages/altitude/chat/components/server-list/server-list.component';
import {ChatInfoComponent} from '@pages/altitude/chat/components/chat-info/chat-info.component';
@Component({
selector: 'app-chat',
imports: [
HeaderComponent,
FullSizeComponent,
ChatBoxComponent,
ServerListComponent,
ChatInfoComponent
],
templateUrl: './chat.component.html',
styleUrl: './chat.component.scss',
providers: [MiniMessageInteractionService]
})
export class ChatComponent implements OnInit, OnDestroy {
private sub?: Subscription;
private readonly chatService: ChatService = inject(ChatService)
protected readonly messages = this.chatService.messages;
protected readonly servers = this.chatService.servers;
protected readonly selectedServer = this.chatService.selectedServer;
constructor(private interaction: MiniMessageInteractionService) {
interaction.clicks$.subscribe(({action, value}) => {
if (action === 'run_command') {
alert(value);
}
});
}
public onSelectedServerChange(server: string) {
this.chatService.selectServer(server);
}
ngOnInit(): void {
this.chatService.connect();
}
ngOnDestroy(): void {
this.sub?.unsubscribe();
this.chatService.disconnect(); // triggers onCompletion server-side, cleans up the emitter
}
}