forked from ng-book/angular2-redux-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat-threads.component.ts
46 lines (40 loc) · 1.08 KB
/
chat-threads.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import {
Component,
OnInit,
Inject
} from '@angular/core';
import { AppStore } from '../app.store';
import * as Redux from 'redux';
import {
Thread
} from '../thread/thread.model';
import * as ThreadActions from '../thread/thread.actions';
import {
AppState,
getCurrentThread,
getAllThreads
} from '../app.reducer';
@Component({
selector: 'chat-threads',
templateUrl: './chat-threads.component.html',
styleUrls: ['./chat-threads.component.css']
})
export class ChatThreadsComponent {
threads: Thread[];
currentThreadId: string;
constructor(@Inject(AppStore) private store: Redux.Store<AppState>) {
store.subscribe(() => this.updateState());
this.updateState();
}
updateState() {
const state = this.store.getState();
// Store the threads list
this.threads = getAllThreads(state);
// We want to mark the current thread as selected,
// so we store the currentThreadId as a value
this.currentThreadId = getCurrentThread(state).id;
}
handleThreadClicked(thread: Thread) {
this.store.dispatch(ThreadActions.selectThread(thread));
}
}