fix: calculating SCDateSeries for next unit view

This commit is contained in:
Rainer Killinger
2022-10-26 13:30:07 +02:00
parent 9c6b5131cd
commit 82ba5f8121

View File

@@ -62,12 +62,12 @@ export class DashboardComponent implements OnInit, OnDestroy {
/**
* UUID subscription
*/
private _uuidSubscription: Subscription;
private _eventUuidSubscription: Subscription;
/**
* The events to display
*/
private uuids: SCUuid[];
private eventUuids: SCUuid[];
/**
* Next event in calendar
@@ -103,9 +103,9 @@ export class DashboardComponent implements OnInit, OnDestroy {
}
async ngOnInit() {
this._uuidSubscription = this.scheduleProvider.uuids$.subscribe(
this._eventUuidSubscription = this.scheduleProvider.uuids$.subscribe(
async result => {
this.uuids = result;
this.eventUuids = result;
await this.loadNextEvent();
},
);
@@ -131,13 +131,23 @@ export class DashboardComponent implements OnInit, OnDestroy {
async loadNextEvent() {
const dataSeries = await this.scheduleProvider.getDateSeries(
this.uuids,
['P1W', 'P2W', 'P3W', 'P4W'],
this.eventUuids,
undefined,
moment(moment.now()).startOf('week').toISOString(),
);
this.nextEvent =
(dataSeries && dataSeries.dates && dataSeries.dates[0]) || undefined;
this.nextEvent = dataSeries.dates
.map(series => ({
time: new Date(
series.dates
.sort((a, b) => new Date(a).getTime() - new Date(b).getTime())
.find(date => new Date(date) > new Date()) ||
Number.POSITIVE_INFINITY,
).getTime(),
series,
}))
.sort(({time: a}, {time: b}) => a - b)
.find(({time}) => !!time)?.series;
}
/**
@@ -147,7 +157,7 @@ export class DashboardComponent implements OnInit, OnDestroy {
for (const sub of this.subscriptions) {
sub.unsubscribe();
}
this._uuidSubscription.unsubscribe();
this._eventUuidSubscription.unsubscribe();
this.collapseAnimation.destroy();
}