Skip to content

Commit

Permalink
closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed May 8, 2024
1 parent a22d61a commit 0cba677
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/app/_shared/components/omnisearch/omnisearch.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
output,
ViewChild,
} from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { IonSearchbar } from '@ionic/angular';
import { TranslateService } from '@ngx-translate/core';
import { getProductFromQuery } from '../../../../../search/search';
Expand All @@ -17,6 +18,7 @@ import { MetaService } from '../../../meta.service';
styleUrls: ['./omnisearch.component.scss'],
})
export class OmnisearchComponent {
private route = inject(ActivatedRoute);
private translateService = inject(TranslateService);
public metaService = inject(MetaService);

Expand All @@ -31,6 +33,10 @@ export class OmnisearchComponent {

public chosenProduct = 'default';

public get queryString() {
return this.route.snapshot.queryParamMap.get('q');
}

public get searchFieldValue(): string {
let baseValue = this.searchField.value ?? '';
if (this.chosenProduct !== 'default') {
Expand Down Expand Up @@ -60,6 +66,12 @@ export class OmnisearchComponent {
constructor() {
effect(() => {
this.query = this.initialQuery();
if (!this.query) {
this.query = this.queryString ?? '';
}

console.log(this.initialQuery(), this.query, this.queryString);

this.chosenProduct = getProductFromQuery(this.query) ?? 'default';

this.query = this.removeProductFromQuery(this.query).trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2>{{ 'Pages.SearchResults.NoResults.Header' | translate }}</h2>
@for(card of searchService.visibleCards(); track card.id) {
<ion-col [sizeMd]="3" [sizeSm]="6" [sizeXs]="12">
<div class="card-container">
<a [routerLink]="['/card', card.id]">
<a [routerLink]="['/card', card.id]" [queryParams]="{ q: queryString }">
<app-card-display class="card" [cardCode]="card.id"
[display]="searchService.queryDisplayValue"></app-card-display>
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Component, inject, output } from '@angular/core';

import { ActivatedRoute } from '@angular/router';
import { SearchService } from '../../../search.service';

@Component({
Expand All @@ -9,9 +10,14 @@ import { SearchService } from '../../../search.service';
styleUrls: ['./search-cards.component.scss'],
})
export class SearchCardsComponent {
public route = inject(ActivatedRoute);
public searchService = inject(SearchService);
public pageChanged = output<number>();

public get queryString() {
return new URLSearchParams(window.location.search).get('q');
}

changePage(newPage: number) {
this.searchService.changePage(newPage);
this.pageChanged.emit(newPage);
Expand Down
2 changes: 1 addition & 1 deletion src/app/search/search.page.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ion-header>
<app-topbar [query]="query" [searchOnType]="true" [searchOnEnter]="true"></app-topbar>
<app-topbar [searchOnType]="true" [searchOnEnter]="true"></app-topbar>
</ion-header>

<ion-content #content>
Expand Down

0 comments on commit 0cba677

Please sign in to comment.