22// SPDX-License-Identifier: MIT
33
44import { CommonModule } from '@angular/common' ;
5- import { Component , computed , inject , output } from '@angular/core' ;
5+ import { Component , computed , inject } from '@angular/core' ;
66import { toSignal } from '@angular/core/rxjs-interop' ;
7+ import { Router } from '@angular/router' ;
78import { MeetingService } from '@app/shared/services/meeting.service' ;
8- import { CardComponent } from '@components/card/card.component' ;
9+ import { ButtonComponent } from '@components/button/button.component' ;
10+ import { DashboardMeetingCardComponent } from '@components/dashboard-meeting-card/dashboard-meeting-card.component' ;
911
10- import type { Meeting , MeetingItem , MeetingOccurrence } from '@lfx-one/shared/interfaces' ;
12+ import type { Meeting , MeetingOccurrence } from '@lfx-one/shared/interfaces' ;
13+
14+ interface MeetingWithOccurrence {
15+ meeting : Meeting ;
16+ occurrence : MeetingOccurrence ;
17+ sortTime : number ;
18+ }
1119
1220@Component ( {
1321 selector : 'lfx-my-meetings' ,
1422 standalone : true ,
15- imports : [ CommonModule , CardComponent ] ,
23+ imports : [ CommonModule , DashboardMeetingCardComponent , ButtonComponent ] ,
1624 templateUrl : './my-meetings.component.html' ,
1725 styleUrl : './my-meetings.component.scss' ,
1826} )
1927export class MyMeetingsComponent {
2028 private readonly meetingService = inject ( MeetingService ) ;
29+ private readonly router = inject ( Router ) ;
2130 private readonly allMeetings = toSignal ( this . meetingService . getMeetings ( ) , { initialValue : [ ] } ) ;
2231
23- public readonly joinMeeting = output < MeetingItem > ( ) ;
24-
25- protected readonly meetings = computed < MeetingItem [ ] > ( ( ) => {
32+ protected readonly todayMeetings = computed < MeetingWithOccurrence [ ] > ( ( ) => {
2633 const now = new Date ( ) ;
34+ const today = new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) ) ;
35+ const todayEnd = new Date ( today . getTime ( ) + 24 * 60 * 60 * 1000 ) ;
2736 const currentTime = now . getTime ( ) ;
2837 const buffer = 40 * 60 * 1000 ; // 40 minutes in milliseconds
2938
30- const upcomingMeetings : Array < { meeting : Meeting ; occurrence : MeetingOccurrence ; sortTime : number } > = [ ] ;
39+ const meetings : MeetingWithOccurrence [ ] = [ ] ;
3140
3241 for ( const meeting of this . allMeetings ( ) ) {
3342 // Process occurrences if they exist
3443 if ( meeting . occurrences && meeting . occurrences . length > 0 ) {
3544 for ( const occurrence of meeting . occurrences ) {
36- const startTime = new Date ( occurrence . start_time ) . getTime ( ) ;
37- const endTime = startTime + occurrence . duration * 60 * 1000 + buffer ;
45+ const startTime = new Date ( occurrence . start_time ) ;
46+ const startTimeMs = startTime . getTime ( ) ;
47+ const endTime = startTimeMs + occurrence . duration * 60 * 1000 + buffer ;
3848
39- // Only include if meeting hasn't ended yet (including buffer)
40- if ( endTime >= currentTime ) {
41- upcomingMeetings . push ( {
49+ // Include if meeting is today and hasn't ended yet (including buffer)
50+ if ( startTime >= today && startTime < todayEnd && endTime >= currentTime ) {
51+ meetings . push ( {
4252 meeting,
4353 occurrence,
44- sortTime : startTime ,
54+ sortTime : startTimeMs ,
4555 } ) ;
4656 }
4757 }
4858 } else {
4959 // Handle meetings without occurrences (single meetings)
50- const startTime = new Date ( meeting . start_time ) . getTime ( ) ;
51- const endTime = startTime + meeting . duration * 60 * 1000 + buffer ;
60+ const startTime = new Date ( meeting . start_time ) ;
61+ const startTimeMs = startTime . getTime ( ) ;
62+ const endTime = startTimeMs + meeting . duration * 60 * 1000 + buffer ;
5263
53- // Only include if meeting hasn't ended yet (including buffer)
54- if ( endTime >= currentTime ) {
55- upcomingMeetings . push ( {
64+ // Include if meeting is today and hasn't ended yet (including buffer)
65+ if ( startTime >= today && startTime < todayEnd && endTime >= currentTime ) {
66+ meetings . push ( {
5667 meeting,
5768 occurrence : {
5869 occurrence_id : '' ,
@@ -61,52 +72,70 @@ export class MyMeetingsComponent {
6172 start_time : meeting . start_time ,
6273 duration : meeting . duration ,
6374 } ,
64- sortTime : startTime ,
75+ sortTime : startTimeMs ,
6576 } ) ;
6677 }
6778 }
6879 }
6980
70- // Sort by earliest time first and limit to 5
71- return upcomingMeetings
72- . sort ( ( a , b ) => a . sortTime - b . sortTime )
73- . slice ( 0 , 5 )
74- . map ( ( item ) => ( {
75- title : item . occurrence . title ,
76- time : this . formatMeetingTime ( item . occurrence . start_time ) ,
77- attendees : item . meeting . individual_registrants_count + item . meeting . committee_members_count ,
78- } ) ) ;
81+ // Sort by earliest time first
82+ return meetings . sort ( ( a , b ) => a . sortTime - b . sortTime ) ;
7983 } ) ;
8084
81- public handleJoinMeeting ( meeting : MeetingItem ) : void {
82- this . joinMeeting . emit ( meeting ) ;
83- }
84-
85- private formatMeetingTime ( startTime : string ) : string {
86- const meetingDate = new Date ( startTime ) ;
85+ protected readonly upcomingMeetings = computed < MeetingWithOccurrence [ ] > ( ( ) => {
8786 const now = new Date ( ) ;
8887 const today = new Date ( now . getFullYear ( ) , now . getMonth ( ) , now . getDate ( ) ) ;
89- const tomorrow = new Date ( today . getTime ( ) + 24 * 60 * 60 * 1000 ) ;
90- const meetingDateOnly = new Date ( meetingDate . getFullYear ( ) , meetingDate . getMonth ( ) , meetingDate . getDate ( ) ) ;
88+ const todayEnd = new Date ( today . getTime ( ) + 24 * 60 * 60 * 1000 ) ;
9189
92- const timeFormatter = new Intl . DateTimeFormat ( 'en-US' , {
93- hour : 'numeric' ,
94- minute : '2-digit' ,
95- hour12 : true ,
96- } ) ;
90+ const meetings : MeetingWithOccurrence [ ] = [ ] ;
91+
92+ for ( const meeting of this . allMeetings ( ) ) {
93+ // Process occurrences if they exist
94+ if ( meeting . occurrences && meeting . occurrences . length > 0 ) {
95+ for ( const occurrence of meeting . occurrences ) {
96+ const startTime = new Date ( occurrence . start_time ) ;
97+ const startTimeMs = startTime . getTime ( ) ;
9798
98- const formattedTime = timeFormatter . format ( meetingDate ) ;
99+ // Include if meeting is after today
100+ if ( startTime >= todayEnd ) {
101+ meetings . push ( {
102+ meeting,
103+ occurrence,
104+ sortTime : startTimeMs ,
105+ } ) ;
106+ }
107+ }
108+ } else {
109+ // Handle meetings without occurrences (single meetings)
110+ const startTime = new Date ( meeting . start_time ) ;
111+ const startTimeMs = startTime . getTime ( ) ;
99112
100- if ( meetingDateOnly . getTime ( ) === today . getTime ( ) ) {
101- return `Today, ${ formattedTime } ` ;
102- } else if ( meetingDateOnly . getTime ( ) === tomorrow . getTime ( ) ) {
103- return `Tomorrow, ${ formattedTime } ` ;
113+ // Include if meeting is after today
114+ if ( startTime >= todayEnd ) {
115+ meetings . push ( {
116+ meeting,
117+ occurrence : {
118+ occurrence_id : '' ,
119+ title : meeting . title ,
120+ description : meeting . description ,
121+ start_time : meeting . start_time ,
122+ duration : meeting . duration ,
123+ } ,
124+ sortTime : startTimeMs ,
125+ } ) ;
126+ }
127+ }
104128 }
105- const dateFormatter = new Intl . DateTimeFormat ( 'en-US' , {
106- weekday : 'long' ,
107- month : 'short' ,
108- day : 'numeric' ,
109- } ) ;
110- return `${ dateFormatter . format ( meetingDate ) } , ${ formattedTime } ` ;
129+
130+ // Sort by earliest time first and limit to 5
131+ return meetings . sort ( ( a , b ) => a . sortTime - b . sortTime ) . slice ( 0 , 5 ) ;
132+ } ) ;
133+
134+ public handleSeeMeeting ( meetingId : string ) : void {
135+ this . router . navigate ( [ '/meetings' , meetingId ] ) ;
136+ }
137+
138+ public handleViewAll ( ) : void {
139+ this . router . navigate ( [ '/meetings' ] ) ;
111140 }
112141}
0 commit comments