mirror of
				https://github.com/avatao-content/frontend-tutorial-framework
				synced 2025-11-04 12:22:54 +00:00 
			
		
		
		
	Create initial implementation of messaging
This commit is contained in:
		@@ -1 +1,11 @@
 | 
			
		||||
<div>
 | 
			
		||||
<ul>
 | 
			
		||||
  <li *ngFor="let message of messages">
 | 
			
		||||
    <p>
 | 
			
		||||
      <strong>{{message.originator}}</strong>
 | 
			
		||||
      <span class="timestamp">{{message.timestamp | date:'yyyy-MM-dd HH:mm:ss'}}</span><br>
 | 
			
		||||
      <span [innerHtml]="message.message"></span>
 | 
			
		||||
    </p>
 | 
			
		||||
  </li>
 | 
			
		||||
</ul>
 | 
			
		||||
</div>
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,14 @@
 | 
			
		||||
div {
 | 
			
		||||
  display: block;
 | 
			
		||||
  overflow: auto;
 | 
			
		||||
  max-height: 100%;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ul {
 | 
			
		||||
  max-height: inherit;
 | 
			
		||||
  list-style-type: none;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.timestamp {
 | 
			
		||||
  opacity: 0.37;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import { Component, OnInit } from '@angular/core';
 | 
			
		||||
import { MarkdownService } from '../markdown.service';
 | 
			
		||||
import { WebSocketService } from '../websocket.service';
 | 
			
		||||
 | 
			
		||||
class Message {
 | 
			
		||||
  originator: string;
 | 
			
		||||
@@ -13,10 +14,23 @@ class Message {
 | 
			
		||||
  styleUrls: ['./logs.component.scss']
 | 
			
		||||
})
 | 
			
		||||
export class LogsComponent implements OnInit {
 | 
			
		||||
  constructor(private markdownService: MarkdownService) {
 | 
			
		||||
  messages: Message[] = [];
 | 
			
		||||
  constructor(
 | 
			
		||||
    private markdownService: MarkdownService,
 | 
			
		||||
    private websocketService: WebSocketService
 | 
			
		||||
  ) {}
 | 
			
		||||
 | 
			
		||||
  convert(text: string) {
 | 
			
		||||
    return this.markdownService.convertToHtml(text);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngOnInit() {
 | 
			
		||||
    this.websocketService.observeAnchor<Message>('message').subscribe(
 | 
			
		||||
      (event) => {
 | 
			
		||||
        this.messages.push(event.data);
 | 
			
		||||
        event.data.message = this.convert(event.data.message);
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user