feat: Added a chatroom component, that is navigatable by the chatroom's ID
[demos/kafka/chat] / src / app / chatroom / chatroom.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { ActivatedRoute } from '@angular/router';
3 import { ChatroomService } from "../chatroom.service";
4 import { UserService } from "../user.service";
5 import { Chatroom } from "../chatroom";
6
7 @Component({
8   selector: 'app-chatroom',
9   templateUrl: './chatroom.component.html',
10   styleUrls: ['./chatroom.component.less']
11 })
12 export class ChatroomComponent implements OnInit {
13
14   chatroom: Chatroom = { id: 'FOO', name: 'BAR'};
15
16   constructor(
17     private chatroomsService: ChatroomService,
18     private userService: UserService,
19     private route: ActivatedRoute) {}
20
21   ngOnInit(): void
22   {
23     this.userService.assertUserisKnown(() => this.getChatroom());
24   }
25
26   getChatroom(): void {
27     const id: string | null = this.route.snapshot.paramMap.get('id');
28     if (id === null) {
29       console.log("ID for chatroom is missing in URI");
30     }
31     else {
32       this.chatroomsService
33         .getChatroom(id)
34         .subscribe(chatroom => this.chatroom = chatroom);
35     }
36   }
37 }