diff --git a/src/app/modules/dashboard/dashboard.component.ts b/src/app/modules/dashboard/dashboard.component.ts index 11b492d9..c11d5bff 100644 --- a/src/app/modules/dashboard/dashboard.component.ts +++ b/src/app/modules/dashboard/dashboard.component.ts @@ -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(); }