Skip to content

Commit dd87837

Browse files
committed
feat(search-history): can delete history from search history for bigger screens
1 parent be041c5 commit dd87837

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

frontend/src/app/shared/search/searchbar.component.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@
105105
>
106106
<mat-autocomplete #auto="matAutocomplete" (optionSelected)="onAutocompleteSelectionChanged($event)">
107107
<mat-option *ngFor="let search of filteredSearches | async" [value]="search.text">
108-
<i class="fas fa-history mr-2 search-history-clock"></i> <span
109-
class="search-history-text"> {{search.text}} </span>
108+
<i class="fas fa-history mr-2 search-history-clock"></i>
109+
<span class="search-history-text">
110+
{{search.text}}
111+
<span class="float-right rm-search-trashbin" (click)="removeSearch(search, $event)" title="Remove search from history"><i
112+
class="far fa-trash-alt fa-sm"></i></span>
113+
</span>
110114
</mat-option>
111115
</mat-autocomplete>
112116
<mat-autocomplete autoActiveFirstOption #auto2="matAutocomplete">ß

frontend/src/app/shared/search/searchbar.component.scss

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ $background-gray: rgb(240, 242, 245);
1616
}
1717

1818
.search-component {
19-
min-width: 300px;
19+
margin: 0.3rem 0rem;
20+
min-width: 320px;
2021

2122
input:focus {
2223
box-shadow: none;
@@ -27,11 +28,16 @@ $background-gray: rgb(240, 242, 245);
2728
color: gainsboro;
2829
}
2930

31+
.rm-search-trashbin {
32+
display: none;
33+
}
34+
3035
// inspired from https://getbootstrap.com/docs/4.0/layout/overview/#responsive-breakpoints
3136
// Large devices (desktops, 992px and up)
3237
@media (min-width: 992px) {
3338
.search-component {
34-
min-width: 510px;
39+
margin: inherit;
40+
min-width: 550px;
3541

3642
input:focus {
3743
box-shadow: none;
@@ -41,16 +47,26 @@ $background-gray: rgb(240, 242, 245);
4147

4248
@media (min-width: 1250px) {
4349
.search-component {
44-
min-width: 700px;
50+
margin: inherit;
51+
min-width: 720px;
4552

4653
input:focus {
4754
box-shadow: none;
4855
}
4956
}
57+
58+
.rm-search-trashbin {
59+
display: inherit;
60+
&:hover {
61+
color: red;
62+
font-weight: bolder;
63+
}
64+
}
5065
}
5166

5267
@media (min-width: 1600px) {
5368
.search-component {
69+
margin: inherit;
5470
min-width: 850px;
5571

5672
input:focus {
@@ -127,3 +143,4 @@ input {
127143
color: #52188c;
128144
font-size: 1.05rem
129145
}
146+

frontend/src/app/shared/search/searchbar.component.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
2222
import { searchDomains } from '../../core/model/search-domains-map';
2323
import { AddTagFilterToSearchDialogComponent } from './add-tag-filter-dialog/add-tag-filter-to-search-dialog.component';
2424
import { 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
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Codever",
3-
"version": "4.4.0",
3+
"version": "4.5.0",
44
"description": "Codever - bookmarks and snippets manager for developers & co",
55
"scripts": {
66
"test": "echo \"Error: no test specified\" && exit 1",

0 commit comments

Comments
 (0)