Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote 3.1.0 to staging #1128

Merged
merged 9 commits into from
Dec 7, 2022
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "pwa-chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
"url": "http://localhost:8080/"
},
{
"name": "ng test",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
distinctUntilChanged,
switchMap,
catchError,
takeUntil,
} from 'rxjs/operators';
import { fromEvent, Observable, empty, throwError } from 'rxjs';

Expand All @@ -23,6 +24,7 @@ import { fromEvent, Observable, empty, throwError } from 'rxjs';
// -------------------------------------------------------------------------- //
import { Gene, GenesResponse } from '../../../../models';
import { ApiService } from '../../../../core/services';
import { Unsub } from '../../../../models/unsub';

// -------------------------------------------------------------------------- //
// Component
Expand All @@ -32,7 +34,7 @@ import { ApiService } from '../../../../core/services';
templateUrl: './gene-search.component.html',
styleUrls: ['./gene-search.component.scss'],
})
export class GeneSearchComponent implements AfterViewInit {
export class GeneSearchComponent extends Unsub implements AfterViewInit {
@Input() location: 'header' | 'home' = 'header';
@Output() searchNavigated = new EventEmitter();

Expand Down Expand Up @@ -64,11 +66,14 @@ export class GeneSearchComponent implements AfterViewInit {
this.checkClickIsInsideComponent(event);
}

constructor(private router: Router, private apiService: ApiService) {}
constructor(private router: Router, private apiService: ApiService) {
super();
}

ngAfterViewInit() {
fromEvent(this.input.nativeElement, 'keyup')
.pipe(
takeUntil(this.unsubscribe$),
debounceTime(500),
distinctUntilChanged(),
switchMap((event: any) => {
Expand Down Expand Up @@ -98,6 +103,7 @@ export class GeneSearchComponent implements AfterViewInit {
} else if (this.isEnsemblId) {
const digits = query.toLowerCase().substring(4, query.length);
if (digits.length !== 11 || !/^\d+$/.test(digits)) {
this.showGeneResults = true;
this.error = this.errorMessages.notValidEnsemblId;
}
}
Expand All @@ -124,6 +130,8 @@ export class GeneSearchComponent implements AfterViewInit {
this.error = this.errorMessages.ensemblIdNotFound;
} else {
this.goToGene(results[0].ensembl_gene_id);
this.isLoading = false;
return;
}
} else {
this.hgncSymbolCounts = {};
Expand All @@ -147,6 +155,7 @@ export class GeneSearchComponent implements AfterViewInit {
this.input.nativeElement.blur();
this.query = '';
this.results = [];
this.showGeneResults = false;
this.searchNavigated.emit();
this.router.navigate(['/genes/' + id]);
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/models/unsub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Injectable, OnDestroy } from '@angular/core';
import { Subject } from 'rxjs';

@Injectable()
export abstract class Unsub implements OnDestroy {
protected unsubscribe$ = new Subject<void>();

ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
}