From 0dfda66578a4e43d25907f0668e4362bade15875 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 30 Aug 2022 11:46:37 +0200 Subject: [PATCH 1/2] Typeahead loading spinner and regex fixes --- .../search-form/search-form.component.html | 8 +++++++- .../search-form/search-form.component.scss | 8 +++++++- .../components/search-form/search-form.component.ts | 13 ++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/src/app/components/search-form/search-form.component.html b/frontend/src/app/components/search-form/search-form.component.html index 378e38940..e96cd0a57 100644 --- a/frontend/src/app/components/search-form/search-form.component.html +++ b/frontend/src/app/components/search-form/search-form.component.html @@ -7,7 +7,13 @@
- +
+ + + + diff --git a/frontend/src/app/components/search-form/search-form.component.scss b/frontend/src/app/components/search-form/search-form.component.scss index 448cb28b3..7c8161196 100644 --- a/frontend/src/app/components/search-form/search-form.component.scss +++ b/frontend/src/app/components/search-form/search-form.component.scss @@ -49,4 +49,10 @@ form { .btn { width: 100px; } -} \ No newline at end of file +} + +.spinner-border { + vertical-align: text-top; + margin-top: 1px; + margin-right: 2px; +} diff --git a/frontend/src/app/components/search-form/search-form.component.ts b/frontend/src/app/components/search-form/search-form.component.ts index 9ed40700a..a9deccc6b 100644 --- a/frontend/src/app/components/search-form/search-form.component.ts +++ b/frontend/src/app/components/search-form/search-form.component.ts @@ -3,8 +3,8 @@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { AssetsService } from 'src/app/services/assets.service'; import { StateService } from 'src/app/services/state.service'; -import { Observable, of, Subject, merge, zip } from 'rxjs'; -import { debounceTime, distinctUntilChanged, switchMap, filter, catchError, map } from 'rxjs/operators'; +import { Observable, of, Subject, zip, BehaviorSubject } from 'rxjs'; +import { debounceTime, distinctUntilChanged, switchMap, catchError, map } from 'rxjs/operators'; import { ElectrsApiService } from 'src/app/services/electrs-api.service'; import { RelativeUrlPipe } from 'src/app/shared/pipes/relative-url/relative-url.pipe'; import { ApiService } from 'src/app/services/api.service'; @@ -20,13 +20,14 @@ export class SearchFormComponent implements OnInit { network = ''; assets: object = {}; isSearching = false; + isTypeaheading$ = new BehaviorSubject(false); typeAhead$: Observable; searchForm: FormGroup; regexAddress = /^([a-km-zA-HJ-NP-Z1-9]{26,35}|[a-km-zA-HJ-NP-Z1-9]{80}|[a-z]{2,5}1[ac-hj-np-z02-9]{8,100}|[A-Z]{2,5}1[AC-HJ-NP-Z02-9]{8,100})$/; regexBlockhash = /^[0]{8}[a-fA-F0-9]{56}$/; - regexTransaction = /^([a-fA-F0-9]{64}):?(\d+)?$/; - regexBlockheight = /^[0-9]+$/; + regexTransaction = /^([a-fA-F0-9]{64})(:\d+)?$/; + regexBlockheight = /^[0-9]{1,9}$/; focus$ = new Subject(); click$ = new Subject(); @@ -68,7 +69,7 @@ export class SearchFormComponent implements OnInit { } return text.trim(); }), - debounceTime(250), + debounceTime(200), distinctUntilChanged(), switchMap((text) => { if (!text.length) { @@ -80,6 +81,7 @@ export class SearchFormComponent implements OnInit { } ]); } + this.isTypeaheading$.next(true); if (!this.stateService.env.LIGHTNING) { return zip( this.electrsApiService.getAddressesByPrefix$(text).pipe(catchError(() => of([]))), @@ -95,6 +97,7 @@ export class SearchFormComponent implements OnInit { ); }), map((result: any[]) => { + this.isTypeaheading$.next(false); if (this.network === 'bisq') { return result[0].map((address: string) => 'B' + address); } From a2e6b265d35aaf92c7e71d0fa7c04ebca0537c19 Mon Sep 17 00:00:00 2001 From: softsimon Date: Tue, 30 Aug 2022 22:36:13 +0200 Subject: [PATCH 2/2] Search bar fixes. --- .../app/components/search-form/search-form.component.html | 2 +- .../app/components/search-form/search-form.component.ts | 1 + .../search-form/search-results/search-results.component.ts | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/search-form/search-form.component.html b/frontend/src/app/components/search-form/search-form.component.html index e96cd0a57..8badcc3cf 100644 --- a/frontend/src/app/components/search-form/search-form.component.html +++ b/frontend/src/app/components/search-form/search-form.component.html @@ -15,5 +15,5 @@ - + diff --git a/frontend/src/app/components/search-form/search-form.component.ts b/frontend/src/app/components/search-form/search-form.component.ts index a9deccc6b..712f7438c 100644 --- a/frontend/src/app/components/search-form/search-form.component.ts +++ b/frontend/src/app/components/search-form/search-form.component.ts @@ -156,6 +156,7 @@ export class SearchFormComponent implements OnInit { this.navigate('/tx/', matches[0]); } } else { + this.searchResults.searchButtonClick(); this.isSearching = false; } } diff --git a/frontend/src/app/components/search-form/search-results/search-results.component.ts b/frontend/src/app/components/search-form/search-results/search-results.component.ts index 84f6a7447..7bda62c02 100644 --- a/frontend/src/app/components/search-form/search-results/search-results.component.ts +++ b/frontend/src/app/components/search-form/search-results/search-results.component.ts @@ -25,6 +25,13 @@ export class SearchResultsComponent implements OnChanges { } } + searchButtonClick() { + if (this.resultsFlattened[this.activeIdx]) { + this.selectedResult.emit(this.resultsFlattened[this.activeIdx]); + this.results = null; + } + } + handleKeyDown(event: KeyboardEvent) { switch (event.key) { case 'ArrowDown':