Browse Source

feat(lib): change historicalDataItems to computed signal

pull/6337/head
KenTandrian 2 months ago
parent
commit
35ae74d80c
  1. 22
      libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

22
libs/ui/src/lib/historical-market-data-editor/historical-market-data-editor.component.ts

@ -78,7 +78,6 @@ export class GfHistoricalMarketDataEditorComponent
csvString: '' csvString: ''
}) })
}); });
public historicalDataItems: LineChartItem[];
public marketDataByMonth: { public marketDataByMonth: {
[yearMonth: string]: { [yearMonth: string]: {
[day: string]: { [day: string]: {
@ -101,6 +100,14 @@ export class GfHistoricalMarketDataEditorComponent
private readonly deviceType = computed( private readonly deviceType = computed(
() => this.deviceDetectorService.deviceInfo().deviceType () => this.deviceDetectorService.deviceInfo().deviceType
); );
private readonly historicalDataItems = computed<LineChartItem[]>(() =>
this.marketData().map(({ date, marketPrice }) => {
return {
date: format(date, DATE_FORMAT),
value: marketPrice
};
})
);
private readonly unsubscribeSubject = new Subject<void>(); private readonly unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
@ -115,25 +122,16 @@ export class GfHistoricalMarketDataEditorComponent
} }
public ngOnChanges() { public ngOnChanges() {
this.historicalDataItems = this.marketData().map(
({ date, marketPrice }) => {
return {
date: format(date, DATE_FORMAT),
value: marketPrice
};
}
);
if (this.dateOfFirstActivity) { if (this.dateOfFirstActivity) {
let date = parseISO(this.dateOfFirstActivity); let date = parseISO(this.dateOfFirstActivity);
const missingMarketData: { date: Date; marketPrice?: number }[] = []; const missingMarketData: { date: Date; marketPrice?: number }[] = [];
if (this.historicalDataItems?.[0]?.date) { if (this.historicalDataItems()?.[0]?.date) {
while ( while (
isBefore( isBefore(
date, date,
parse(this.historicalDataItems[0].date, DATE_FORMAT, new Date()) parse(this.historicalDataItems()[0].date, DATE_FORMAT, new Date())
) )
) { ) {
missingMarketData.push({ missingMarketData.push({

Loading…
Cancel
Save