@@ -2,7 +2,11 @@ import { Component, OnInit, ElementRef, ViewChild } from '@angular/core';
2
2
import { ActivatedRoute } from '@angular/router' ;
3
3
import { ChatService } from '../chat.service' ;
4
4
5
- import { Subscription } from 'rxjs/Subscription' ;
5
+ // import { Subscription } from 'rxjs/Subscription';
6
+ import { Observable } from 'rxjs/Observable' ;
7
+ import { ChatDetail } from '../models/chat' ;
8
+ import { Store } from '@ngrx/store' ;
9
+ import { AppState } from '../chat-reducer/chat.reducer' ;
6
10
7
11
declare var $ : any ;
8
12
@@ -14,32 +18,37 @@ declare var $: any;
14
18
export class ChatDetailComponent implements OnInit {
15
19
16
20
@ViewChild ( 'chatMessages' ) private chatMessagesContainer : ElementRef ;
17
- arrChatMessages : any ;
21
+ arrChatMessages : Observable < Array < ChatDetail > > ;
18
22
19
- subscriptionNewMessage : Subscription ;
23
+ // subscriptionNewMessage: Subscription;
20
24
21
25
constructor (
22
- private route : ActivatedRoute , private chatService : ChatService
26
+ private route : ActivatedRoute , private chatService : ChatService ,
27
+ private store : Store < AppState >
23
28
) {
24
- this . subscriptionNewMessage = this . chatService . getMessageObservable ( )
25
- . subscribe ( message => {
26
- this . arrChatMessages . push ( message ) ;
27
- setTimeout ( ( ) => {
28
- let ele = $ ( '.chat-discussion' ) ; // document.querySelector('.chat-discussion');
29
- // this.chatMessagesContainer.nativeElement.scrollIntoView(false);
30
- // ele.scrollTo(100, ele.scrollHeight);
31
- ele . animate ( { scrollTop : ele . prop ( 'scrollHeight' ) } , 1000 ) ;
32
- } , 1 ) ;
33
-
34
- // this.chatMessagesContainer.nativeElement.scrollTop = this.chatMessagesContainer.nativeElement.scrollHeight;
35
- // window.scrollTo(0, document.querySelector('.chat-discussion').scrollHeight);
36
- } ) ;
29
+
30
+ this . arrChatMessages = this . store . select < any > ( "chatDetailReducer" ) ;
31
+
32
+
33
+ // this.subscriptionNewMessage = this.chatService.getMessageObservable()
34
+ // .subscribe(message => {
35
+ // // this.arrChatMessages.push(message);
36
+ // setTimeout(() => {
37
+ // let ele = $('.chat-discussion'); // document.querySelector('.chat-discussion');
38
+ // // this.chatMessagesContainer.nativeElement.scrollIntoView(false);
39
+ // // ele.scrollTo(100, ele.scrollHeight);
40
+ // ele.animate({ scrollTop: ele.prop('scrollHeight')}, 1000);
41
+ // }, 1);
42
+
43
+ // // this.chatMessagesContainer.nativeElement.scrollTop = this.chatMessagesContainer.nativeElement.scrollHeight;
44
+ // // window.scrollTo(0, document.querySelector('.chat-discussion').scrollHeight);
45
+ // });
37
46
}
38
47
39
48
ngOnInit ( ) {
40
49
this . route . params . subscribe ( params => {
41
50
this . chatService . getdetailedChat ( params . id ) . subscribe ( ( result ) => {
42
- this . arrChatMessages = result ;
51
+ // this.arrChatMessages = result;
43
52
} , ( error : any ) => {
44
53
console . log ( 'ChatDetailComponent login fail: ' + error ) ;
45
54
} ) ;
0 commit comments