2026-07-18 22:22:54 +00:00
|
|
|
import {Component, inject, OnDestroy, OnInit} from '@angular/core';
|
|
|
|
|
import {Subscription} from 'rxjs';
|
|
|
|
|
import {ChatService} from '@pages/altitude/chat/service/chat.service';
|
2026-07-18 22:59:04 +00:00
|
|
|
import {HeaderComponent} from '@header/header.component';
|
|
|
|
|
import {MiniMessageComponent} from '@pages/altitude/chat/mini-message/mini-message.component';
|
|
|
|
|
import {MiniMessageInteractionService} from '@pages/altitude/chat/mini-message/mini-message-interaction.service';
|
|
|
|
|
import {JsonPipe} from '@angular/common';
|
2026-07-18 22:22:54 +00:00
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-chat',
|
2026-07-18 22:59:04 +00:00
|
|
|
imports: [
|
|
|
|
|
HeaderComponent,
|
|
|
|
|
MiniMessageComponent,
|
|
|
|
|
JsonPipe
|
|
|
|
|
],
|
2026-07-18 22:22:54 +00:00
|
|
|
templateUrl: './chat.component.html',
|
2026-07-18 22:59:04 +00:00
|
|
|
styleUrl: './chat.component.scss',
|
|
|
|
|
providers: [MiniMessageInteractionService]
|
2026-07-18 22:22:54 +00:00
|
|
|
})
|
|
|
|
|
export class ChatComponent implements OnInit, OnDestroy {
|
|
|
|
|
private sub?: Subscription;
|
2026-07-18 22:59:04 +00:00
|
|
|
private readonly chatService: ChatService = inject(ChatService)
|
|
|
|
|
protected readonly messages = this.chatService.messages;
|
2026-07-18 22:22:54 +00:00
|
|
|
|
2026-07-18 22:59:04 +00:00
|
|
|
constructor(private interaction: MiniMessageInteractionService) {
|
|
|
|
|
interaction.clicks$.subscribe(({action, value}) => {
|
|
|
|
|
if (action === 'run_command') {
|
|
|
|
|
alert(value);
|
2026-07-18 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:59:04 +00:00
|
|
|
ngOnInit(): void {
|
|
|
|
|
this.chatService.connect();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-18 22:22:54 +00:00
|
|
|
ngOnDestroy(): void {
|
|
|
|
|
this.sub?.unsubscribe();
|
2026-07-18 22:59:04 +00:00
|
|
|
this.chatService.disconnect(); // triggers onCompletion server-side, cleans up the emitter
|
2026-07-18 22:22:54 +00:00
|
|
|
}
|
|
|
|
|
}
|