@@ -8,11 +8,11 @@ import {
88 forwardRef ,
99 inject
1010} from '@angular/core' ;
11+ import { AsyncPipe } from '@angular/common' ;
1112import fileSaver from 'file-saver' ;
1213import Fuse from 'fuse.js' ;
13- import { Subject } from 'rxjs' ;
14- import { debounceTime , distinctUntilChanged } from 'rxjs/operators' ;
15- import { toSignal } from '@angular/core/rxjs-interop' ;
14+ import { Subject , combineLatest , BehaviorSubject , Observable } from 'rxjs' ;
15+ import { debounceTime , distinctUntilChanged , map , startWith } from 'rxjs/operators' ;
1616
1717import { IgxIconComponent , IgxIconService } from 'igniteui-angular/icon' ;
1818import { ISelectionEventArgs } from 'igniteui-angular/drop-down' ;
@@ -42,6 +42,7 @@ interface ICategoryOption {
4242 templateUrl : './material-icons-extended.component.html' ,
4343 styleUrls : [ './material-icons-extended.component.scss' ] ,
4444 imports : [
45+ AsyncPipe ,
4546 IgxSelectComponent ,
4647 IgxLabelDirective ,
4748 IgxSelectItemComponent ,
@@ -58,14 +59,28 @@ export class MaterialIconsExtendedComponent implements OnInit {
5859 private iconService = inject ( IgxIconService ) ;
5960 private renderer = inject ( Renderer2 ) ;
6061
61- // Search with debounce using signals
62+ // Search with debounce
6263 private searchInput$ = new Subject < string > ( ) ;
63- public searchTerm = toSignal (
64- this . searchInput$ . pipe (
65- debounceTime ( 300 ) ,
66- distinctUntilChanged ( )
67- ) ,
68- { initialValue : '' }
64+ private categorySubject$ = new BehaviorSubject < IconCategory | 'all' > ( 'all' ) ;
65+
66+ private searchTerm$ = this . searchInput$ . pipe (
67+ debounceTime ( 300 ) ,
68+ distinctUntilChanged ( ) ,
69+ startWith ( '' )
70+ ) ;
71+
72+ // Combine search and category filters
73+ public filteredResults$ : Observable < IIconsGroup [ ] > = combineLatest ( [
74+ this . searchTerm$ ,
75+ this . categorySubject$
76+ ] ) . pipe (
77+ map ( ( [ searchTerm , category ] ) => {
78+ const filterByNamePipe = new FilterByName ( ) ;
79+ const categoriesPipe = new CategoriesFilterPipe ( ) ;
80+
81+ const filtered = filterByNamePipe . transform ( this . allIcons , searchTerm ) ;
82+ return categoriesPipe . transform ( filtered , category ) ;
83+ } )
6984 ) ;
7085
7186 public categories : ICategoryOption [ ] = [
@@ -99,15 +114,16 @@ export class MaterialIconsExtendedComponent implements OnInit {
99114 }
100115
101116 public allIcons = imxIcons ;
102-
103117 public selectedCategory : IconCategory | 'all' = 'all' ;
104118
105119 handleSelection ( event : ISelectionEventArgs ) {
106120 this . selectedCategory = event . newSelection . value ;
121+ this . categorySubject$ . next ( event . newSelection . value ) ;
107122 }
108123
109124 resetFilter ( ) {
110125 this . selectedCategory = 'all' ;
126+ this . categorySubject$ . next ( 'all' ) ;
111127 }
112128
113129 trackByIcon ( _index : number , icon : IMXIcon ) : string {
@@ -172,7 +188,8 @@ interface IIconsGroup {
172188}
173189
174190@Pipe ( {
175- name : 'categoriesFilter'
191+ name : 'categoriesFilter' ,
192+ pure : true
176193} )
177194export class CategoriesFilterPipe implements PipeTransform {
178195 sortIcons ( acc : IIconsGroup [ ] , icon : IMXIcon ) : IIconsGroup [ ] {
@@ -215,7 +232,8 @@ export class CategoriesFilterPipe implements PipeTransform {
215232}
216233
217234@Pipe ( {
218- name : 'filterByName'
235+ name : 'filterByName' ,
236+ pure : true
219237} )
220238export class FilterByName implements PipeTransform {
221239 private fuse : Fuse < IMXIcon > | null = null ;
0 commit comments