From ea8a2cec3fbb4a76460a4ad6fed48797ff0c6fc2 Mon Sep 17 00:00:00 2001 From: Adrian Kunz Date: Wed, 21 Feb 2024 08:50:04 +0100 Subject: [PATCH 1/2] fix(frontend): Error because validateNew is called too soon --- .../src/app/poll/choose-events/choose-events.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/frontend/src/app/poll/choose-events/choose-events.component.ts b/apps/frontend/src/app/poll/choose-events/choose-events.component.ts index a10a92c8..b1fa423c 100644 --- a/apps/frontend/src/app/poll/choose-events/choose-events.component.ts +++ b/apps/frontend/src/app/poll/choose-events/choose-events.component.ts @@ -72,7 +72,6 @@ export class ChooseEventsComponent implements OnInit { this.pollService.getEvents(id).pipe(tap(events => { this.pollEvents = events; this.bookedEvents = new Array(this.pollEvents.length).fill(false); - this.validateNew(); })), this.pollService.getParticipants(id).pipe(tap(participants => this.participants = participants)), this.pollService.isAdmin(id, this.token), @@ -81,6 +80,7 @@ export class ChooseEventsComponent implements OnInit { this.setDescription(poll, events, participants); this.clearSelection(); + this.validateNew(); this.bookedEvents = events.map(e => poll.bookedEvents.includes(e._id)); this.isAdmin = isAdmin; this.updateHelpers(); From 4a677194f0c234262a564b07f754012c314a2835 Mon Sep 17 00:00:00 2001 From: Adrian Kunz Date: Wed, 21 Feb 2024 08:52:03 +0100 Subject: [PATCH 2/2] refactor(frontend): Reorder choose-events methods to show their purpose --- .../poll/choose-events/choose-events.component.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/frontend/src/app/poll/choose-events/choose-events.component.ts b/apps/frontend/src/app/poll/choose-events/choose-events.component.ts index b1fa423c..5f72a16c 100644 --- a/apps/frontend/src/app/poll/choose-events/choose-events.component.ts +++ b/apps/frontend/src/app/poll/choose-events/choose-events.component.ts @@ -161,9 +161,6 @@ export class ChooseEventsComponent implements OnInit { }); } - // View Helpers - // TODO called from template, bad practice - validateNew() { this.errors = checkParticipant(this.newParticipant, this.poll!, this.participants); } @@ -172,14 +169,17 @@ export class ChooseEventsComponent implements OnInit { this.errors = checkParticipant(this.editDto!, this.poll!, this.participants, this.editParticipant!._id); } + // View Helpers + // TODO called from template, bad practice + countParticipants(pollEvent: PollEvent) { const participants = this.participants.filter(p => p.selection[pollEvent._id] === 'yes'); const indeterminateParticipants = this.participants.filter(p => p.selection[pollEvent._id] === 'maybe'); return participants.length + indeterminateParticipants.length; } - userVoted() { - return this.participants.some(participant => participant.token === this.token); + isPastEvent(event: PollEvent) { + return Date.parse(event.start) < this.now; } // Helpers @@ -216,7 +216,7 @@ export class ChooseEventsComponent implements OnInit { return this.countParticipants(event) >= this.poll.settings.maxEventParticipants; } - isPastEvent(event: PollEvent) { - return Date.parse(event.start) < this.now; + private userVoted() { + return this.participants.some(participant => participant.token === this.token); } }