From 93d57d639d686c632c9725f6810fec82b868af55 Mon Sep 17 00:00:00 2001 From: Sandro Date: Thu, 23 Nov 2023 21:36:28 +0100 Subject: [PATCH] feat update training status --- ios/App/App.xcodeproj/project.pbxproj | 9 ++- src/app/pages/club/club.page.ts | 2 - .../training-detail/training-detail.page.html | 16 ++--- .../training-detail/training-detail.page.ts | 60 +++++++++---------- 4 files changed, 42 insertions(+), 45 deletions(-) diff --git a/ios/App/App.xcodeproj/project.pbxproj b/ios/App/App.xcodeproj/project.pbxproj index 4ac33b81..d7029a40 100644 --- a/ios/App/App.xcodeproj/project.pbxproj +++ b/ios/App/App.xcodeproj/project.pbxproj @@ -91,7 +91,6 @@ 6068B69F868D1149E79B8A79 /* Pods-App.debug.xcconfig */, E55BD740173AD78B07A75E55 /* Pods-App.release.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -367,12 +366,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = U7DQUX87VS; INFOPLIST_FILE = App/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 1.1; OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\""; PRODUCT_BUNDLE_IDENTIFIER = app.myclub.default; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -388,12 +387,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_TEAM = U7DQUX87VS; INFOPLIST_FILE = App/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - MARKETING_VERSION = 1.0; + MARKETING_VERSION = 1.1; PRODUCT_BUNDLE_IDENTIFIER = app.myclub.default; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = ""; diff --git a/src/app/pages/club/club.page.ts b/src/app/pages/club/club.page.ts index 1e4d6e75..876aba9b 100644 --- a/src/app/pages/club/club.page.ts +++ b/src/app/pages/club/club.page.ts @@ -55,8 +55,6 @@ export class ClubPage implements OnInit { console.log(">> Club Data" ); console.log( data); this.cdr.detectChanges(); - - }, error: (err) => console.error("Club Error in subscription:", err), complete: () => console.log("Club Observable completed") diff --git a/src/app/pages/training/training-detail/training-detail.page.html b/src/app/pages/training/training-detail/training-detail.page.html index 7a7ef9d1..d62c6dc9 100644 --- a/src/app/pages/training/training-detail/training-detail.page.html +++ b/src/app/pages/training/training-detail/training-detail.page.html @@ -8,6 +8,8 @@ + + @@ -87,11 +89,11 @@

- Anwesend: {{attendeeListTrue.length}} + Anwesend: {{training['attendeeListTrue'].length}}
- + @@ -102,11 +104,11 @@

- Abwesend: {{attendeeListFalse.length}} + Abwesend: {{training['attendeeListFalse'].length}}
- + @@ -117,11 +119,11 @@

- + +
@@ -130,7 +132,7 @@

-
+ --> diff --git a/src/app/pages/training/training-detail/training-detail.page.ts b/src/app/pages/training/training-detail/training-detail.page.ts index 5558ce6f..18dea80c 100644 --- a/src/app/pages/training/training-detail/training-detail.page.ts +++ b/src/app/pages/training/training-detail/training-detail.page.ts @@ -1,10 +1,11 @@ import { ChangeDetectorRef, Component, Input, OnInit } from '@angular/core'; import { ModalController, NavParams, ToastController } from '@ionic/angular'; import { User } from 'firebase/auth'; -import { Observable, catchError, map, of, switchMap, take, tap } from 'rxjs'; +import { Observable, catchError, forkJoin, map, of, switchMap, take, tap } from 'rxjs'; import { Training } from 'src/app/models/training'; import { AuthService } from 'src/app/services/auth.service'; import { TrainingService } from 'src/app/services/firebase/training.service'; +import { UserProfileService } from 'src/app/services/firebase/user-profile.service'; @Component({ selector: 'app-training-detail', @@ -14,7 +15,7 @@ import { TrainingService } from 'src/app/services/firebase/training.service'; export class TrainingDetailPage implements OnInit { @Input("data") training: Training; - training$: Observable; + training$: Observable; mode = "yes"; @@ -27,6 +28,7 @@ export class TrainingDetailPage implements OnInit { constructor ( private readonly modalCtrl: ModalController, public navParams: NavParams, + private readonly userProfileService: UserProfileService, private readonly trainingService: TrainingService, private readonly toastController: ToastController, private readonly authService: AuthService, @@ -45,6 +47,7 @@ export class TrainingDetailPage implements OnInit { this.training$.subscribe({ next: (data) => { console.log("TRAINING Data received"); + console.log(data); this.training = { ...this.training, ...data }; @@ -62,45 +65,40 @@ export class TrainingDetailPage implements OnInit { take(1), tap(user => { this.user = user; - if (!user) { - console.log("No user found"); - throw new Error("User not found"); - } + if (!user) throw new Error("User not found"); }), switchMap(() => this.trainingService.getTeamTrainingRef(teamId, trainingId)), - switchMap(game => { - if (!game) return of(null); // If no game is found, return null + switchMap(training => { + if (!training) return of(null); return this.trainingService.getTeamTrainingsAttendeesRef(teamId, trainingId).pipe( - map(attendees => { - - // get firstName & lastName from userProfile Method call for each attendees element - // this.userProfileService.getUserProfileById(attendee.id) - - const userAttendee = attendees.find(att => att.id == this.user.uid); - const status = userAttendee ? userAttendee.status : null; - - //this.attendeeListUndefined - - this.attendeeListTrue = attendees.filter(att => att.status == true) || []; - this.attendeeListFalse = attendees.filter(att => att.status == false) || []; - this.attendeeListUndefined = []; - - return { - ...game, - attendees, - status, - }; + switchMap(attendees => { + const attendeeProfiles$ = attendees.map(attendee => + this.userProfileService.getUserProfileById(attendee.id).pipe( + take(1), + map(profile => ({ ...profile, ...attendee })), // Combine attendee object with profile + catchError(() => of({ ...attendee, firstName: 'Unknown', lastName: 'Unknown' })) + ) + ); + return forkJoin(attendeeProfiles$).pipe( + map(attendeesWithDetails => ({ + ...training, + attendees: attendeesWithDetails, + attendeeListTrue: attendeesWithDetails.filter(e=>e.status==true), + attendeeListFalse: attendeesWithDetails.filter(e=>e.status==false), + status: attendeesWithDetails.find(att => att.id == this.user.uid)?.status + })) + ); }), catchError(() => of({ - ...game, + ...training, attendees: [], status: null, - })) // If error in fetching attendees, return game with empty attendees + })) ); }), catchError(err => { - console.error("Error in getSingleGameWithAttendees:", err); - return of(null); // Return null on error + console.error("Error in getTrainingWithAttendees:", err); + return of(null); }) ); }