@@ -22,6 +22,7 @@ import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
22
22
import { searchDomains } from '../../core/model/search-domains-map' ;
23
23
import { AddTagFilterToSearchDialogComponent } from './add-tag-filter-dialog/add-tag-filter-to-search-dialog.component' ;
24
24
import { DialogMeasurementsHelper } from '../../core/helper/dialog-measurements.helper' ;
25
+ import iziToast , { IziToastSettings } from 'izitoast' ;
25
26
26
27
@Component ( {
27
28
selector : 'app-searchbar' ,
@@ -76,8 +77,6 @@ export class SearchbarComponent implements OnInit {
76
77
private searchNotificationService : SearchNotificationService ,
77
78
private bookmarkStore : PublicBookmarksStore ,
78
79
private publicBookmarksService : PublicBookmarksService ,
79
- private personalBookmarksService : PersonalBookmarksService ,
80
- private personalCodeletsService : PersonalSnippetsService ,
81
80
private paginationNotificationService : PaginationNotificationService ,
82
81
private keycloakService : KeycloakService ,
83
82
private keycloakServiceWrapper : KeycloakServiceWrapper ,
@@ -209,9 +208,7 @@ export class SearchbarComponent implements OnInit {
209
208
searches : [ newSearch ]
210
209
}
211
210
} else {
212
- const existingSavedSearchIndex = this . _userData . searches . findIndex (
213
- element => element . searchDomain === this . searchDomain
214
- && element . text . trim ( ) . toLowerCase ( ) === this . searchBoxText . trim ( ) . toLowerCase ( ) ) ;
211
+ const existingSavedSearchIndex = this . getIndexSavedSearch ( this . searchDomain , this . searchBoxText ) ;
215
212
if ( existingSavedSearchIndex !== - 1 ) {
216
213
const existingSavedSearch : Search = this . _userData . searches . splice ( existingSavedSearchIndex , 1 ) [ 0 ] ;
217
214
existingSavedSearch . lastAccessedAt = now ;
@@ -226,6 +223,12 @@ export class SearchbarComponent implements OnInit {
226
223
}
227
224
}
228
225
226
+ private getIndexSavedSearch ( searchDomain : string , searchText : string ) {
227
+ return this . _userData . searches . findIndex (
228
+ element => element . searchDomain === searchDomain
229
+ && element . text . trim ( ) . toLowerCase ( ) === searchText . trim ( ) . toLowerCase ( ) ) ;
230
+ }
231
+
229
232
onAutocompleteSelectionChanged ( event : MatAutocompleteSelectedEvent ) {
230
233
const selectedValue = event . option . value ;
231
234
this . triggerBookmarkSearch ( selectedValue ) ;
@@ -316,4 +319,22 @@ export class SearchbarComponent implements OnInit {
316
319
) ;
317
320
}
318
321
322
+ removeSearch ( search : Search , e : MouseEvent ) {
323
+ e . preventDefault ( ) ;
324
+ e . stopPropagation ( ) ;
325
+
326
+ const indexSavedSearch = this . getIndexSavedSearch ( search . searchDomain , search . text ) ;
327
+
328
+ const deletedSearch = this . _userData . searches . splice ( indexSavedSearch , 1 ) [ 0 ] ;
329
+ this . userDataStore . updateUserData$ ( this . _userData ) . subscribe ( ( ) => {
330
+ console . log ( 'Removed search ' + search . text + ' from domain ' + search . searchDomain ) ;
331
+ const iziToastSettings : IziToastSettings = {
332
+ title : `"${ deletedSearch . text } " deleted from "${ deletedSearch . searchDomain } " search history ` ,
333
+ timeout : 3000 ,
334
+ position : 'bottomRight'
335
+ }
336
+ iziToast . success ( iziToastSettings ) ;
337
+ } ) ;
338
+ }
339
+
319
340
}
0 commit comments