22// SPDX-License-Identifier: MIT
33
44import { CommonModule } from '@angular/common' ;
5- import { Component , computed , inject , Injector , input , output , runInInjectionContext , signal , Signal , WritableSignal } from '@angular/core' ;
5+ import { Component , computed , effect , inject , Injector , input , output , runInInjectionContext , signal , Signal , WritableSignal } from '@angular/core' ;
66import { toSignal } from '@angular/core/rxjs-interop' ;
77import { RouterLink } from '@angular/router' ;
88import { AvatarComponent } from '@components/avatar/avatar.component' ;
@@ -52,21 +52,27 @@ export class MeetingCardComponent {
5252 private readonly dialogService = inject ( DialogService ) ;
5353 private readonly injector = inject ( Injector ) ;
5454
55- public readonly meeting = input . required < Meeting > ( ) ;
55+ public readonly meetingInput = input . required < Meeting > ( ) ;
5656 public readonly pastMeeting = input < boolean > ( false ) ;
5757 public readonly loading = input < boolean > ( false ) ;
5858 public readonly meetingParticipantCount : Signal < number > = this . initMeetingParticipantCount ( ) ;
5959 public showParticipants : WritableSignal < boolean > = signal ( false ) ;
60+ public meeting : WritableSignal < Meeting > = signal ( { } as Meeting ) ;
6061 public participantsLoading : WritableSignal < boolean > = signal ( true ) ;
6162 public participants ! : Signal < MeetingParticipant [ ] > ;
6263 public participantsLabel : Signal < string > = this . initParticipantsLabel ( ) ;
6364 public additionalParticipantsCount : WritableSignal < number > = signal ( 0 ) ;
6465 public actionMenuItems : Signal < MenuItem [ ] > = this . initializeActionMenuItems ( ) ;
6566
66- public readonly meetingUpdated = output < void > ( ) ;
6767 public readonly meetingDeleted = output < void > ( ) ;
6868 public readonly project = this . projectService . project ;
6969
70+ public constructor ( ) {
71+ effect ( ( ) => {
72+ this . meeting . set ( this . meetingInput ( ) ) ;
73+ } ) ;
74+ }
75+
7076 public onParticipantsToggle ( event : Event ) : void {
7177 event . stopPropagation ( ) ;
7278
@@ -78,43 +84,6 @@ export class MeetingCardComponent {
7884
7985 // Show/hide inline participants display
8086 this . participantsLoading . set ( true ) ;
81- if ( ! this . showParticipants ( ) ) {
82- const queries = combineLatest ( [
83- this . meetingService . getMeetingParticipants ( this . meeting ( ) . id ) ,
84- ...( this . meeting ( ) . committees ?. map ( ( c ) => this . committeeService . getCommitteeMembers ( c ) . pipe ( catchError ( ( ) => of ( [ ] ) ) ) ) ?? [ ] ) ,
85- ] ) . pipe (
86- map ( ( [ participants , ...committeeMembers ] ) => {
87- return [
88- ...participants ,
89- ...committeeMembers
90- . filter ( ( c ) => c . length > 0 )
91- . flatMap ( ( c ) => {
92- return c . map ( ( m ) => ( {
93- id : m . id ,
94- meeting_id : this . meeting ( ) . id ,
95- first_name : m . first_name ,
96- last_name : m . last_name ,
97- email : m . email ,
98- organization : m . organization ,
99- is_host : false ,
100- type : 'committee' ,
101- invite_accepted : true ,
102- attended : true ,
103- } ) ) ;
104- } ) ,
105- ] ;
106- } ) ,
107- // Sort participants by first name
108- map ( ( participants ) => participants . sort ( ( a , b ) => a . first_name ?. localeCompare ( b . first_name ?? '' ) ?? 0 ) as MeetingParticipant [ ] ) ,
109- finalize ( ( ) => this . participantsLoading . set ( false ) )
110- ) ;
111-
112- runInInjectionContext ( this . injector , ( ) => {
113- this . participants = toSignal ( queries , {
114- initialValue : [ ] ,
115- } ) ;
116- } ) ;
117- }
11887
11988 this . showParticipants . set ( ! this . showParticipants ( ) ) ;
12089 }
@@ -277,7 +246,7 @@ export class MeetingCardComponent {
277246 . onClose . pipe ( take ( 1 ) )
278247 . subscribe ( ( updatedMeeting ) => {
279248 if ( updatedMeeting ) {
280- this . meetingUpdated . emit ( ) ;
249+ this . refreshMeeting ( ) ;
281250 }
282251 } ) ;
283252 }
@@ -340,4 +309,18 @@ export class MeetingCardComponent {
340309 return baseItems ;
341310 } ) ;
342311 }
312+
313+ private refreshMeeting ( ) : void {
314+ this . meetingService
315+ . getMeeting ( this . meeting ( ) . id )
316+ . pipe (
317+ take ( 1 ) ,
318+ tap ( ( meeting ) => {
319+ this . additionalParticipantsCount . set ( 0 ) ;
320+ this . meeting . set ( meeting ) ;
321+ } ) ,
322+ finalize ( ( ) => this . refreshParticipantsList ( ) )
323+ )
324+ . subscribe ( ) ;
325+ }
343326}
0 commit comments