@@ -9,7 +9,6 @@ import { MeetupsHeaderComponent } from '../../components/meetups-header/meetups-
9
9
import { MatPaginator , PageEvent } from '@angular/material/paginator' ;
10
10
import { NavigationService } from '../../core/services/navigation.service' ;
11
11
import { map , Observable , switchMap } from 'rxjs' ;
12
- import { Category } from '../../core/model/categories.model' ;
13
12
import { ActivatedRoute , Router } from '@angular/router' ;
14
13
import { LocationsComponent } from '../../components/locations/locations.component' ;
15
14
import { Location } from '../../core/model/locations.model' ;
@@ -68,7 +67,25 @@ export class MeetupsComponent {
68
67
post => this . isMeetupCategory ( post ) ,
69
68
( a , b ) => this . compareByDate ( a , b )
70
69
)
71
- . pipe ( map ( result => result . posts [ 0 ] ) ) ;
70
+ . pipe ( map ( result => {
71
+ const startOfToday = new Date ( ) ;
72
+ startOfToday . setHours ( 0 , 0 , 0 , 0 ) ;
73
+
74
+ return this . findSoonestAfter ( result . posts , startOfToday . getTime ( ) ) ;
75
+ } ) ) ;
76
+ }
77
+
78
+ findSoonestAfter ( posts : Post [ ] , minValue : number ) : Post | null {
79
+ let soonest : Post | null = null ;
80
+
81
+ for ( const post of posts ) {
82
+ const num = new Date ( post . date ?. trim ( ) ?? '' ) . getTime ( ) ;
83
+ if ( num > minValue && ( soonest === null || num < new Date ( soonest . date ?. trim ( ) ?? '' ) . getTime ( ) ) ) {
84
+ soonest = post ;
85
+ }
86
+ }
87
+
88
+ return soonest ;
72
89
}
73
90
74
91
private getAllMeetups$ ( ) {
0 commit comments