mirror of
https://github.com/avatao-content/frontend-tutorial-framework
synced 2025-01-16 03:01:56 +00:00
Create initial implementation of messaging
This commit is contained in:
parent
6b9c2c19e3
commit
1c1bddd955
@ -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>
|
</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 { Component, OnInit } from '@angular/core';
|
||||||
import { MarkdownService } from '../markdown.service';
|
import { MarkdownService } from '../markdown.service';
|
||||||
|
import { WebSocketService } from '../websocket.service';
|
||||||
|
|
||||||
class Message {
|
class Message {
|
||||||
originator: string;
|
originator: string;
|
||||||
@ -13,10 +14,23 @@ class Message {
|
|||||||
styleUrls: ['./logs.component.scss']
|
styleUrls: ['./logs.component.scss']
|
||||||
})
|
})
|
||||||
export class LogsComponent implements OnInit {
|
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() {
|
ngOnInit() {
|
||||||
|
this.websocketService.observeAnchor<Message>('message').subscribe(
|
||||||
|
(event) => {
|
||||||
|
this.messages.push(event.data);
|
||||||
|
event.data.message = this.convert(event.data.message);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user