Skip to content

Commit

Permalink
closes #94
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Jun 23, 2024
1 parent 1bfea60 commit fbf8a5b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/app/_shared/components/omnisearch/omnisearch.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
input,
output,
ViewChild,
type OnDestroy,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonSearchbar } from '@ionic/angular';
Expand All @@ -25,13 +26,15 @@ import { SearchService } from '../../../search.service';
templateUrl: './omnisearch.component.html',
styleUrls: ['./omnisearch.component.scss'],
})
export class OmnisearchComponent {
export class OmnisearchComponent implements OnDestroy {
private route = inject(ActivatedRoute);
private translateService = inject(TranslateService);
private searchService = inject(SearchService);
private storageService = inject(LocalStorageService);
public metaService = inject(MetaService);

private isDestroyed = false;

@ViewChild(IonSearchbar) searchField!: IonSearchbar;

public query = '';
Expand Down Expand Up @@ -69,6 +72,8 @@ export class OmnisearchComponent {
}

private debouncedTypeEmit = debounce(() => {
if (this.isDestroyed) return;

// yes, we need to do this _again_ here, in case the user leaves a game: prompt in their query with a game selected
this.tryChangeProductBasedOnQuery(this.query);
this.type.emit(this.emittedText());
Expand All @@ -77,11 +82,11 @@ export class OmnisearchComponent {
constructor() {
effect(() => {
this.query =
this.initialQuery() ||
this.searchService.queryString() ||
this.initialQuery() ??
this.searchService.queryString() ??
reformatQueryToJustHaveProduct(
this.storageService.retrieve('search-query')
) ||
) ??
'';

if (!this.query) {
Expand All @@ -92,6 +97,10 @@ export class OmnisearchComponent {
});
}

ngOnDestroy(): void {
this.isDestroyed = true;
}

doEnter(newText: string) {
this.tryChangeProductBasedOnQuery(newText);
this.enter.emit(this.emittedText());
Expand Down

0 comments on commit fbf8a5b

Please sign in to comment.