Browse Source

feat(app): benchmark data fetching

pull/4604/head
KenTandrian 4 months ago
parent
commit
1d3272d4a6
  1. 46
      apps/client/src/app/components/home-watchlist/home-watchlist.component.ts

46
apps/client/src/app/components/home-watchlist/home-watchlist.component.ts

@ -12,8 +12,8 @@ import {
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs'; import { forkJoin, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators'; import { map, takeUntil } from 'rxjs/operators';
import { CreateWatchlistItemDialog } from './create-watchlist-item-dialog/create-watchlist-item-dialog.component'; import { CreateWatchlistItemDialog } from './create-watchlist-item-dialog/create-watchlist-item-dialog.component';
import { CreateWatchlistItemDialogParams } from './create-watchlist-item-dialog/interfaces/interfaces'; import { CreateWatchlistItemDialogParams } from './create-watchlist-item-dialog/interfaces/interfaces';
@ -72,26 +72,28 @@ export class HomeWatchlistComponent implements OnDestroy, OnInit {
} }
private loadWatchlistData() { private loadWatchlistData() {
this.dataService forkJoin({
.fetchWatchlist() watchlistItems: this.dataService.fetchWatchlist(),
.pipe(takeUntil(this.unsubscribeSubject)) allBenchmarks: this.dataService
.subscribe((watchlist) => { .fetchBenchmarks()
this.watchlist = watchlist.map((item) => ({ .pipe(map((response) => response.benchmarks))
dataSource: item.dataSource, })
symbol: item.symbol, .pipe(
name: item.symbol, takeUntil(this.unsubscribeSubject),
marketCondition: 'NEUTRAL_MARKET', map(({ watchlistItems, allBenchmarks }) => {
performances: { const watchlistLookup = new Set(
allTimeHigh: { watchlistItems.map((item) => `${item.dataSource}:${item.symbol}`)
date: new Date(), );
performancePercent: 0 return allBenchmarks.filter((benchmark) =>
} watchlistLookup.has(`${benchmark.dataSource}:${benchmark.symbol}`)
}, );
trend200d: 'UNKNOWN', })
trend50d: 'UNKNOWN' )
})); .subscribe({
next: (filteredBenchmarks) => {
this.changeDetectorRef.markForCheck(); this.watchlist = filteredBenchmarks;
this.changeDetectorRef.markForCheck();
}
}); });
} }

Loading…
Cancel
Save