Skip to content

Commit

Permalink
feat: add url param to select participant
Browse files Browse the repository at this point in the history
  • Loading branch information
jxhnx committed Nov 1, 2024
1 parent 3fc5e83 commit 78d2c8c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/app/components/marketplace/marketplace.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, EMPTY, catchError } from 'rxjs';
import { ServiceCard } from '../../types/dtos';
import { MarketplaceService } from '../../services/marketplace.service';
Expand Down Expand Up @@ -29,19 +29,27 @@ export class MarketplaceComponent implements OnInit {
constructor(
private marketplaceService: MarketplaceService,
private router: Router,
private route: ActivatedRoute,
public formatter: DataFormattingService,
private queryService: QueryService,
) {}

ngOnInit(): void {
this.route.queryParams.subscribe((params) => {
this.legalName = params['participant'] || null;
this.fetchData();
});

this.legalNames$ = this.marketplaceService.fetchLegalNames().pipe(
catchError((error: HttpErrorResponse) => {
this.error = error;
return EMPTY;
}),
);
}

this.services$ = this.marketplaceService.fetchServiceData(null).pipe(
fetchData(): void {
this.services$ = this.marketplaceService.fetchServiceData(this.legalName).pipe(
catchError((error: HttpErrorResponse) => {
this.error = error;
return EMPTY;
Expand All @@ -58,11 +66,13 @@ export class MarketplaceComponent implements OnInit {

onLegalNameChange(event: MatSelectChange): void {
this.legalName = event.value;
this.services$ = this.marketplaceService.fetchServiceData(this.legalName).pipe(
catchError((error: HttpErrorResponse) => {
this.error = error;
return EMPTY;
}),
);

this.router.navigate([], {
relativeTo: this.route,
queryParams: { participant: this.legalName || null },
queryParamsHandling: 'merge',
});

this.fetchData();
}
}

0 comments on commit 78d2c8c

Please sign in to comment.