Browse Source

feat(lib): change historicalDataItems to computed signal

pull/6337/head
KenTandrian 1 month 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: ''
})
});
public historicalDataItems: LineChartItem[];
public marketDataByMonth: {
[yearMonth: string]: {
[day: string]: {
@ -101,6 +100,14 @@ export class GfHistoricalMarketDataEditorComponent
private readonly deviceType = computed(
() => 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>();
public constructor(
@ -115,25 +122,16 @@ export class GfHistoricalMarketDataEditorComponent
}
public ngOnChanges() {
this.historicalDataItems = this.marketData().map(
({ date, marketPrice }) => {
return {
date: format(date, DATE_FORMAT),
value: marketPrice
};
}
);
if (this.dateOfFirstActivity) {
let date = parseISO(this.dateOfFirstActivity);
const missingMarketData: { date: Date; marketPrice?: number }[] = [];
if (this.historicalDataItems?.[0]?.date) {
if (this.historicalDataItems()?.[0]?.date) {
while (
isBefore(
date,
parse(this.historicalDataItems[0].date, DATE_FORMAT, new Date())
parse(this.historicalDataItems()[0].date, DATE_FORMAT, new Date())
)
) {
missingMarketData.push({

Loading…
Cancel
Save