Skip to content

Commit

Permalink
feat update code
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Oct 24, 2023
1 parent e8ac48c commit 9f87698
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 51 deletions.
2 changes: 2 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ export class AppComponent implements OnInit {
}

initializeFirebase() {


// https://cloud.google.com/firestore/docs/manage-data/enable-offline
// The default cache size threshold is 40 MB. Configure "cacheSizeBytes"
// for a different threshold (minimum 1 MB) or set to "CACHE_SIZE_UNLIMITED"
Expand Down
4 changes: 2 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ import { TeamPage } from './pages/team/team.page';
}),
// GraphQLModule,
HttpClientModule,
provideFirebaseApp(() => initializeApp(environment.firebase)),
provideFirebaseApp(() => initializeApp(environment.firebase),),
provideFirestore(() => getFirestore()),
provideAuth(() => getAuth()),
provideStorage(() => getStorage()),
provideMessaging(() => getMessaging())
provideMessaging(() => getMessaging()),
],
providers: [
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/news/news-detail/news-detail.page.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ion-header [translucent]="true">
<ion-toolbar>
<ion-title>{{news?.title}}</ion-title>
<ion-title></ion-title>
<ion-buttons slot="primary">
<ion-button (click)="close()">schliessen</ion-button>
</ion-buttons>
Expand Down
101 changes: 53 additions & 48 deletions src/app/pages/training/trainings/trainings.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,54 +53,59 @@ export class TrainingsPage implements OnInit {

ngOnInit() {

this.trainingList$ = this.authService.getUser$().pipe(
take(1),
tap(() => console.log("Fetching user...")),
tap(user => this.user = user),
switchMap(user => this.fbService.getUserTeamRefs(user)),
tap(teams => console.log("Fetched teams:", teams)),
concatMap(teamsArray => from(teamsArray)),
tap(team => console.log("Processing team:", team.id)),
concatMap(team => this.trainingService.getTeamTrainingsRefs(team.id).pipe(
// timeout(TIMEOUT_DURATION),
take(1),
tap(trainings => console.log(`Fetched trainings for team ${team.id}:`, trainings)),
switchMap(trainings => {
const trainingWithAttendees$ = trainings.map(training =>
this.trainingService.getTeamTrainingsAttendeesRef(team.id, training.id).pipe(
take(1),
map(attendees => {
const userAttendee = attendees.find(att => att.id == this.user.uid);
return {
...training,
date: training.date,
teamId: team.id,
status: userAttendee ? userAttendee.status : null,
countAttendees: attendees.filter(att => att.status).length,
attendees: attendees
};
})
)
);
return forkJoin(trainingWithAttendees$);
}),
catchError(error => {
console.error(`Error fetching trainings for team ${team.id}:`, error);
return of([]); // if there's an error, emit an empty array to continue the stream
})
)),
map(trainings => trainings.sort((a, b) => a.date.toMillis() - b.date.toMillis())),
map(trainings => trainings.filter((training, index, self) =>
index === self.findIndex(t => t.id === training.id))),
tap(() => console.log("Team training fetching completed")),
) as Observable<Training[]>;

this.subscription = this.trainingList$.subscribe({
next: trainings => {
console.log("Combined training list created", trainings);
},
error: err => console.error('Error in the observable chain:', err.message)
});
// Assuming Training is already imported

this.trainingList$ = this.authService.getUser$().pipe(
take(1),
tap(() => console.log("Fetching user...")),
tap(user => this.user = user),
switchMap(user => this.fbService.getUserTeamRefs(user)),
tap(teams => console.log("Fetched teams:", teams)),
concatMap(teamsArray => from(teamsArray)),
tap(team => console.log("Processing team:", team.id)),
concatMap(team => this.trainingService.getTeamTrainingsRefs(team.id).pipe(
take(1),
tap(trainings => console.log(`Fetched trainings for team ${team.id}:`, trainings)),
switchMap(trainings => {
const trainingWithAttendees$ = trainings.map(training =>
this.trainingService.getTeamTrainingsAttendeesRef(team.id, training.id).pipe(
take(1),
map(attendees => {
const userAttendee = attendees.find(att => att.id == this.user.uid);
const status = userAttendee ? userAttendee.status : null;
console.log(training.date);
return {
...training,
date: training.date,
teamId: team.id,
status: status,
countAttendees: attendees.filter(att => att.status == true).length,
attendees: attendees
};
})
)
);
return forkJoin(trainingWithAttendees$);
}),
catchError(error => {
console.error(`Error fetching trainings for team ${team.id}:`, error);
return of([] as Training[]); // if there's an error, emit an empty array to continue the stream
})
)),
map((trainingsArray: Training[]) => trainingsArray.flat()),
map(trainings => trainings.sort((a, b) => a.date.toMillis() - b.date.toMillis())),
map(trainings => trainings.filter((training, index, self) =>
index === self.findIndex(t => t.id === training.id))),
tap(() => console.log("Team training fetching completed"))
) as Observable<Training[]>;

this.subscription = this.trainingList$.subscribe({
next: trainings => {
console.log("Combined training list created", trainings);
},
error: err => console.error('Error in the observable chain:', err.message)
});



const TIMEOUT_DURATION = 1000; // adjust as needed
Expand Down

0 comments on commit 9f87698

Please sign in to comment.