Skip to content

Commit 4e4489a

Browse files
asithadejordane
authored andcommitted
refactor: improve meeting card state management and refresh logic
- Add effect-based meeting input synchronization for better reactivity - Implement refreshMeeting method to update meeting data after edits/deletes - Simplify participant list refresh logic - Update meeting modal delete method naming for consistency - Remove unnecessary meetingUpdated event emissions 🤖 Generated with [Claude Code](https://claude.ai/code) Signed-off-by: Asitha de Silva <asithade@gmail.com>
1 parent 62c3298 commit 4e4489a

File tree

4 files changed

+27
-44
lines changed

4 files changed

+27
-44
lines changed

apps/lfx-pcc/src/app/modules/project/meetings/components/meeting-card/meeting-card.component.ts

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: MIT
33

44
import { 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';
66
import { toSignal } from '@angular/core/rxjs-interop';
77
import { RouterLink } from '@angular/router';
88
import { 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
}

apps/lfx-pcc/src/app/modules/project/meetings/components/meeting-modal/meeting-modal.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
@if (meeting) {
55
<div class="p-0">
66
<!-- Show meeting card for view mode -->
7-
<lfx-meeting-card [meeting]="meeting" [pastMeeting]="false" (meetingDeleted)="onRefresh()" (meetingUpdated)="onRefresh()"></lfx-meeting-card>
7+
<lfx-meeting-card [meetingInput]="meeting" [pastMeeting]="false" (meetingDeleted)="onDelete()"></lfx-meeting-card>
88
</div>
99
}

apps/lfx-pcc/src/app/modules/project/meetings/components/meeting-modal/meeting-modal.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class MeetingModalComponent {
1818

1919
public readonly meeting = this.config.data?.meeting;
2020

21-
public onRefresh(): void {
21+
public onDelete(): void {
2222
this.dialogRef.close(true);
2323
}
2424
}

apps/lfx-pcc/src/app/modules/project/meetings/meeting-dashboard/meeting-dashboard.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<div class="bg-white rounded-lg border border-gray-200 shadow-sm hover:shadow-md transition-shadow h-full">
7676
<div class="p-6">
7777
<lfx-meeting-card
78-
[meeting]="meeting"
78+
[meetingInput]="meeting"
7979
(meetingUpdated)="refreshMeetings()"
8080
(meetingDeleted)="refreshMeetings()"
8181
[pastMeeting]="meetingListView() === 'past'"

0 commit comments

Comments
 (0)