33 */
44import Component from '../../decorators' ;
55import './comment-list.scss' ;
6+ import { IComment } from "../../interfaces" ;
67
78@Component ( 'app.components' , 'comments' , {
89 template : `
910 <div class="container-fluid">
1011 <div class="discussion-timeline">
11- <comment ng-repeat="comment in $ctrl.comments" comment="comment"></comment>
12- <!--<comment></comment>-->
12+ <tags-input ng-model="$ctrl.tagFilter">
13+ <auto-complete source="$ctrl.tags"></auto-complete>
14+ </tags-input>
15+ <comment ng-repeat="comment in $ctrl.comments | filterByTags:$ctrl.tagFilter" comment="comment" tags="$ctrl.tags"></comment>
16+ <comment comment="$ctrl.emptyComment" on-add="$ctrl.addComment()" tags="$ctrl.tags"></comment>
1317 </div>
1418 </div>`
1519} )
1620class CommentsController {
17- comments ;
21+ comments : IComment [ ] ;
22+ emptyComment : IComment ;
23+ tags : string [ ] ;
24+ tagFilter : any [ ] ;
1825
1926 static $inject = [ 'Comments' ] ;
2027 constructor ( private Comments ) {
28+ this . emptyComment = { } ;
29+ this . tagFilter = [ ] ;
2130 Comments . getComments ( ) . then ( ( comments ) => {
22- this . comments = comments
31+ this . comments = comments ;
32+ this . tags = this . comments
33+ . map ( ( el ) => el . tags )
34+ . reduce ( ( prev , curr ) => [ ...prev , ...curr ] )
35+ . filter ( ( elem , pos , arr ) => arr . indexOf ( elem ) == pos ) ;
2336 } ) ;
2437 }
38+
39+ private getCommentId ( ) {
40+ let arr = this . comments . map ( ( el ) => el . id ) ;
41+ return Math . max ( ...arr ) + 1 ;
42+ }
43+
44+ addComment ( ) {
45+ this . emptyComment . id = this . getCommentId ( ) ;
46+ this . comments . push ( this . emptyComment ) ;
47+ this . emptyComment = { } ;
48+ }
2549}
0 commit comments