@@ -22,6 +22,7 @@ import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
2222import { searchDomains } from '../../core/model/search-domains-map' ;
2323import { AddTagFilterToSearchDialogComponent } from './add-tag-filter-dialog/add-tag-filter-to-search-dialog.component' ;
2424import { DialogMeasurementsHelper } from '../../core/helper/dialog-measurements.helper' ;
25+ import iziToast , { IziToastSettings } from 'izitoast' ;
2526
2627@Component ( {
2728 selector : 'app-searchbar' ,
@@ -76,8 +77,6 @@ export class SearchbarComponent implements OnInit {
7677 private searchNotificationService : SearchNotificationService ,
7778 private bookmarkStore : PublicBookmarksStore ,
7879 private publicBookmarksService : PublicBookmarksService ,
79- private personalBookmarksService : PersonalBookmarksService ,
80- private personalCodeletsService : PersonalSnippetsService ,
8180 private paginationNotificationService : PaginationNotificationService ,
8281 private keycloakService : KeycloakService ,
8382 private keycloakServiceWrapper : KeycloakServiceWrapper ,
@@ -209,9 +208,7 @@ export class SearchbarComponent implements OnInit {
209208 searches : [ newSearch ]
210209 }
211210 } 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 ) ;
215212 if ( existingSavedSearchIndex !== - 1 ) {
216213 const existingSavedSearch : Search = this . _userData . searches . splice ( existingSavedSearchIndex , 1 ) [ 0 ] ;
217214 existingSavedSearch . lastAccessedAt = now ;
@@ -226,6 +223,12 @@ export class SearchbarComponent implements OnInit {
226223 }
227224 }
228225
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+
229232 onAutocompleteSelectionChanged ( event : MatAutocompleteSelectedEvent ) {
230233 const selectedValue = event . option . value ;
231234 this . triggerBookmarkSearch ( selectedValue ) ;
@@ -316,4 +319,22 @@ export class SearchbarComponent implements OnInit {
316319 ) ;
317320 }
318321
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+
319340}
0 commit comments