diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 940a3f5..7887ab6 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -24,6 +24,7 @@ import { DirectivesModule } from './directives/directives.module';
import { CommentCardComponent } from './comment-card/comment-card.component';
import { CommentsListComponent } from './comments-list/comments-list.component';
import { CommentCardEditComponent } from './comment-card-edit/comment-card-edit.component';
+import { CommentFilterComponent } from './comment-filter/comment-filter.component';
const materialModules = [
MatAutocompleteModule,
@@ -41,7 +42,8 @@ const materialModules = [
AppComponent,
CommentCardComponent,
CommentsListComponent,
- CommentCardEditComponent
+ CommentCardEditComponent,
+ CommentFilterComponent
],
imports: [
BrowserModule,
diff --git a/src/app/comment-card-edit/comment-card-edit.component.ts b/src/app/comment-card-edit/comment-card-edit.component.ts
index 98ebfe9..49008db 100644
--- a/src/app/comment-card-edit/comment-card-edit.component.ts
+++ b/src/app/comment-card-edit/comment-card-edit.component.ts
@@ -79,7 +79,6 @@ export class CommentCardEditComponent implements OnInit {
this.tagCtrl.setValue(null);
}
-
addTag(event: MatChipInputEvent): void {
const input = event.input;
const value = event.value;
diff --git a/src/app/comment-filter/comment-filter.component.html b/src/app/comment-filter/comment-filter.component.html
new file mode 100644
index 0000000..33fafed
--- /dev/null
+++ b/src/app/comment-filter/comment-filter.component.html
@@ -0,0 +1,15 @@
+
+
+
+ {{ tag }}
+ cancel
+
+
+
+
+
+ {{ tag }}
+
+
+
\ No newline at end of file
diff --git a/src/app/comment-filter/comment-filter.component.scss b/src/app/comment-filter/comment-filter.component.scss
new file mode 100644
index 0000000..924a7a1
--- /dev/null
+++ b/src/app/comment-filter/comment-filter.component.scss
@@ -0,0 +1,3 @@
+.full-width-field {
+ width: 100%;
+}
\ No newline at end of file
diff --git a/src/app/comment-filter/comment-filter.component.spec.ts b/src/app/comment-filter/comment-filter.component.spec.ts
new file mode 100644
index 0000000..7575764
--- /dev/null
+++ b/src/app/comment-filter/comment-filter.component.spec.ts
@@ -0,0 +1,25 @@
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+
+import { CommentFilterComponent } from './comment-filter.component';
+
+describe('CommentFilterComponent', () => {
+ let component: CommentFilterComponent;
+ let fixture: ComponentFixture;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ declarations: [ CommentFilterComponent ]
+ })
+ .compileComponents();
+ }));
+
+ beforeEach(() => {
+ fixture = TestBed.createComponent(CommentFilterComponent);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ });
+
+ it('should create', () => {
+ expect(component).toBeTruthy();
+ });
+});
diff --git a/src/app/comment-filter/comment-filter.component.ts b/src/app/comment-filter/comment-filter.component.ts
new file mode 100644
index 0000000..6abcdf5
--- /dev/null
+++ b/src/app/comment-filter/comment-filter.component.ts
@@ -0,0 +1,69 @@
+import { COMMA, ENTER } from '@angular/cdk/keycodes';
+import { Component, ElementRef, ViewChild, OnInit, OnDestroy } from '@angular/core';
+import { FormBuilder } from '@angular/forms';
+import { MatAutocompleteSelectedEvent, MatAutocomplete } from '@angular/material/autocomplete';
+
+import { Observable } from 'rxjs';
+import { startWith, withLatestFrom, map } from 'rxjs/operators';
+import { untilDestroy } from '../operators';
+
+import { CommentFacade } from '../store/comment';
+
+@Component({
+ selector: 'app-comment-filter',
+ templateUrl: './comment-filter.component.html',
+ styleUrls: ['./comment-filter.component.scss']
+})
+export class CommentFilterComponent implements OnInit, OnDestroy {
+ @ViewChild('tagInput') tagInput: ElementRef;
+ @ViewChild('auto') matAutocomplete: MatAutocomplete;
+ form = this.fb.group({
+ tags: [[]]
+ });
+ tagCtrl = this.fb.control([]);
+ filteredTags: Observable;
+ separatorKeysCodes: number[] = [ENTER, COMMA];
+
+ constructor(
+ private readonly fb: FormBuilder,
+ private readonly commentFacade: CommentFacade
+ ) { }
+
+ ngOnInit(): void {
+ this.filteredTags = this.tagCtrl.valueChanges.pipe(
+ startWith(null),
+ withLatestFrom(this.commentFacade.tags$),
+ map(([tag, allTags]) => {
+ if (tag === null) {
+ return [...allTags];
+ }
+ const value = tag.toLowerCase()
+ return allTags.filter(t => t.toLowerCase().includes(value));
+ })
+ );
+
+ this.form.valueChanges.pipe(
+ untilDestroy(this)
+ ).subscribe(formValue => {
+ this.commentFacade.filter(formValue)
+ });
+ }
+
+ ngOnDestroy(): void {
+ // stub for untilDestroy
+ }
+
+ selected(event: MatAutocompleteSelectedEvent): void {
+ const tags = [...this.form.value.tags];
+ this.form.get('tags').setValue([...tags, event.option.viewValue]);
+ this.tagInput.nativeElement.value = '';
+ this.tagCtrl.setValue(null);
+ }
+
+ removeTag(tag: string): void {
+ const tags = [...this.form.value.tags];
+
+ this.form.get('tags').setValue([...tags.filter(t => t !== tag)]);
+ }
+
+}
diff --git a/src/app/comments-list/comments-list.component.html b/src/app/comments-list/comments-list.component.html
index 245879d..21825ae 100644
--- a/src/app/comments-list/comments-list.component.html
+++ b/src/app/comments-list/comments-list.component.html
@@ -1,4 +1,5 @@