Thomas Kaul 4 days ago
committed by GitHub
parent
commit
fe07afdc86
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 28
      apps/client/src/app/pages/api/api-page.component.ts

28
apps/client/src/app/pages/api/api-page.component.ts

@ -14,9 +14,10 @@ import {
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Component, OnInit } from '@angular/core'; import { Component, DestroyRef, OnInit } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { format, startOfYear } from 'date-fns'; import { format, startOfYear } from 'date-fns';
import { map, Observable, Subject, takeUntil } from 'rxjs'; import { map, Observable } from 'rxjs';
@Component({ @Component({
host: { class: 'page' }, host: { class: 'page' },
@ -35,9 +36,11 @@ export class GfApiPageComponent implements OnInit {
public status$: Observable<DataProviderGhostfolioStatusResponse>; public status$: Observable<DataProviderGhostfolioStatusResponse>;
private apiKey: string; private apiKey: string;
private unsubscribeSubject = new Subject<void>();
public constructor(private http: HttpClient) {} public constructor(
private destroyRef: DestroyRef,
private http: HttpClient
) {}
public ngOnInit() { public ngOnInit() {
this.apiKey = prompt($localize`Please enter your Ghostfolio API key:`); this.apiKey = prompt($localize`Please enter your Ghostfolio API key:`);
@ -51,18 +54,13 @@ export class GfApiPageComponent implements OnInit {
this.status$ = this.fetchStatus(); this.status$ = this.fetchStatus();
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private fetchAssetProfile({ symbol }: { symbol: string }) { private fetchAssetProfile({ symbol }: { symbol: string }) {
return this.http return this.http
.get<DataProviderGhostfolioAssetProfileResponse>( .get<DataProviderGhostfolioAssetProfileResponse>(
`/api/v1/data-providers/ghostfolio/asset-profile/${symbol}`, `/api/v1/data-providers/ghostfolio/asset-profile/${symbol}`,
{ headers: this.getHeaders() } { headers: this.getHeaders() }
) )
.pipe(takeUntil(this.unsubscribeSubject)); .pipe(takeUntilDestroyed(this.destroyRef));
} }
private fetchDividends({ symbol }: { symbol: string }) { private fetchDividends({ symbol }: { symbol: string }) {
@ -82,7 +80,7 @@ export class GfApiPageComponent implements OnInit {
map(({ dividends }) => { map(({ dividends }) => {
return dividends; return dividends;
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }
@ -103,7 +101,7 @@ export class GfApiPageComponent implements OnInit {
map(({ historicalData }) => { map(({ historicalData }) => {
return historicalData; return historicalData;
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }
@ -129,7 +127,7 @@ export class GfApiPageComponent implements OnInit {
map(({ items }) => { map(({ items }) => {
return items; return items;
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }
@ -145,7 +143,7 @@ export class GfApiPageComponent implements OnInit {
map(({ quotes }) => { map(({ quotes }) => {
return quotes; return quotes;
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }
@ -155,7 +153,7 @@ export class GfApiPageComponent implements OnInit {
'/api/v2/data-providers/ghostfolio/status', '/api/v2/data-providers/ghostfolio/status',
{ headers: this.getHeaders() } { headers: this.getHeaders() }
) )
.pipe(takeUntil(this.unsubscribeSubject)); .pipe(takeUntilDestroyed(this.destroyRef));
} }
private getHeaders() { private getHeaders() {

Loading…
Cancel
Save