Skip to content

Commit

Permalink
feat: player search not found
Browse files Browse the repository at this point in the history
  • Loading branch information
WorthyD committed Jul 1, 2021
1 parent 9546955 commit 40294d3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app/player/player.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { PipesModule } from '@destiny/components';
import { MatSidenavModule } from '@angular/material/sidenav';
import { DirectivesModule } from '../shared/directives/directives.module';
import { MatListModule } from '@angular/material/list';
import { DialogModule } from '../shared/components/dialog/dialog.module';

@NgModule({
declarations: [PlayerDetailsContainerComponent],
imports: [
CommonModule,

DialogModule,
MatListModule,
DirectivesModule,
MatSidenavModule,
Expand Down
26 changes: 23 additions & 3 deletions src/app/player/player.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Destiny2Service } from 'bungie-api-angular';
import { ActivityStats, MemberProfile } from 'bungie-models';
import { BehaviorSubject, combineLatest, Observable, of, Subject } from 'rxjs';
import { distinctUntilChanged, filter, map, shareReplay, switchMap } from 'rxjs/operators';
import { catchError, distinctUntilChanged, filter, map, shareReplay, switchMap } from 'rxjs/operators';
import { PlayerService as BasePlayerService } from '../shared/components/player/player.service';
import { latestSeason } from '@destiny/models';
import { Callout } from '@destiny/components';
Expand All @@ -16,14 +16,18 @@ import {
BungieInfoService
} from '@destiny/data';
import { DecimalPipe } from '@angular/common';
import { MatDialog } from '@angular/material/dialog';
import { DialogComponent } from '../shared/components/dialog/dialog.component';

@Injectable()
export class PlayerService extends BasePlayerService {
private profileComponents = [100, 104, 200, 202, 900];
constructor(
private d2Service: Destiny2Service,
private decimalPipe: DecimalPipe,
private bungieInfoService: BungieInfoService
private bungieInfoService: BungieInfoService,
public dialog: MatDialog,
private router: Router
) {
super();
}
Expand Down Expand Up @@ -174,7 +178,23 @@ export class PlayerService extends BasePlayerService {
.pipe(
map((memberProfileResponse) => {
return memberProfileResponse.Response;
}),
catchError((error) => {
this.openError(error);
return of();
})
);
}

openError(error) {
console.log('error', error);
const dialogRef = this.dialog.open(DialogComponent, {
width: '400px',
data: { title: error.error.ErrorStatus, description: error.error.Message }
});

dialogRef.afterClosed().subscribe((result) => {
this.router.navigate(['/', 'player-search']);
});
}
}
25 changes: 25 additions & 0 deletions src/app/shared/components/dialog/dialog.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { DialogComponent } from './dialog.component';

describe('DialogComponent', () => {
let component: DialogComponent;
let fixture: ComponentFixture<DialogComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ DialogComponent ]
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(DialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
27 changes: 27 additions & 0 deletions src/app/shared/components/dialog/dialog.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component, Inject, OnInit } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';

export interface DialogData {
title: string;
description: string;
}

@Component({
selector: 'app-dialog',
template: ` <h1 mat-dialog-title>{{ data.title }}</h1>
<div mat-dialog-content>
<p>{{ data.description }}</p>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">Close</button>
</div>`,
styles: [``]
})
export class DialogComponent implements OnInit {
constructor(public dialogRef: MatDialogRef<DialogComponent>, @Inject(MAT_DIALOG_DATA) public data: DialogData) {}

ngOnInit(): void {}
onNoClick(): void {
this.dialogRef.close();
}
}
11 changes: 11 additions & 0 deletions src/app/shared/components/dialog/dialog.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DialogComponent } from './dialog.component';
import { MatDialogModule } from '@angular/material/dialog';
import { MatButtonModule } from '@angular/material/button';

@NgModule({
declarations: [DialogComponent],
imports: [CommonModule, MatDialogModule, MatButtonModule]
})
export class DialogModule {}

0 comments on commit 40294d3

Please sign in to comment.