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 * UUID subscription
*/ */
private _uuidSubscription: Subscription; private _eventUuidSubscription: Subscription;
/** /**
* The events to display * The events to display
*/ */
private uuids: SCUuid[]; private eventUuids: SCUuid[];
/** /**
* Next event in calendar * Next event in calendar
@@ -103,9 +103,9 @@ export class DashboardComponent implements OnInit, OnDestroy {
} }
async ngOnInit() { async ngOnInit() {
this._uuidSubscription = this.scheduleProvider.uuids$.subscribe( this._eventUuidSubscription = this.scheduleProvider.uuids$.subscribe(
async result => { async result => {
this.uuids = result; this.eventUuids = result;
await this.loadNextEvent(); await this.loadNextEvent();
}, },
); );
@@ -131,13 +131,23 @@ export class DashboardComponent implements OnInit, OnDestroy {
async loadNextEvent() { async loadNextEvent() {
const dataSeries = await this.scheduleProvider.getDateSeries( const dataSeries = await this.scheduleProvider.getDateSeries(
this.uuids, this.eventUuids,
['P1W', 'P2W', 'P3W', 'P4W'], undefined,
moment(moment.now()).startOf('week').toISOString(), moment(moment.now()).startOf('week').toISOString(),
); );
this.nextEvent = this.nextEvent = dataSeries.dates
(dataSeries && dataSeries.dates && dataSeries.dates[0]) || undefined; .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) { for (const sub of this.subscriptions) {
sub.unsubscribe(); sub.unsubscribe();
} }
this._uuidSubscription.unsubscribe(); this._eventUuidSubscription.unsubscribe();
this.collapseAnimation.destroy(); this.collapseAnimation.destroy();
} }