Skip to content

Commit

Permalink
feat update
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Nov 15, 2023
1 parent a850879 commit faa5cb6
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 395 deletions.
4 changes: 4 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ const routes: Routes = [
path: 'helfer-add',
loadChildren: () => import('./pages/helfer/helfer-add/helfer-add.module').then( m => m.HelferAddPageModule)
},
{
path: 'helfer-detail',
loadChildren: () => import('./pages/helfer/helfer-detail/helfer-detail.module').then( m => m.HelferDetailPageModule)
},

];

Expand Down
145 changes: 1 addition & 144 deletions src/app/pages/championship/championship/championship.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,153 +90,10 @@ export class ChampionshipPage implements OnInit {
});


/*
const TIMEOUT_DURATION = 1000; // 5 seconds, adjust as needed
const teamGameList: Game[] = [];
const teamGamePastList: Game[] = [];
// CURRENT GAMES
const teamGame$ = this.authService.getUser$().pipe(
take(1),
tap(() => console.log("Fetching user...")),
switchMap(user => {
console.log("Got user:", user);
this.user = user;
return 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.championshipService.getTeamGamesRefs(team.id).pipe(
timeout(TIMEOUT_DURATION), // Adding timeout here
take(1),
tap(games => console.log(`Fetched games for team ${team.id}:`, games)),
switchMap(games => {
// Fetch attendees for each game and combine the results
const gameWithAttendees$ = games.map(game =>
this.championshipService.getTeamGameAttendeesRef(team.id, game.id).pipe(
take(1),
map(attendees => {
const userAttendee = attendees.find(att => att.id == this.user.uid);
const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list
return {
...game,
teamId: team.id,
status: status,
countAttendees: attendees.filter(att => att.status == true).length,
attendees: attendees
};
})
)
);
return forkJoin(gameWithAttendees$);
}),
catchError(error => {
if (error.name === 'TimeoutError') {
console.error(`Error fetching games for team ${team.id}:`);
return of([]);
} else {
// Handle other errors, maybe rethrow or return a default object
throw error;
}
})
)),
tap(games => games.forEach(game => teamGameList.push(game))),
finalize(() => console.log("Team Game fetching completed"))
);
// PAST GAMES
const teamGamePast$ = this.authService.getUser$().pipe(
take(1),
tap(() => console.log("Fetching user...")),
switchMap(user => {
console.log("Got user:", user);
this.user = user;
return 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.championshipService.getTeamGamesPastRefs(team.id).pipe(
timeout(TIMEOUT_DURATION), // Adding timeout here
take(1),
tap(games => console.log(`Fetched games for team ${team.id}:`, games)),
switchMap(games => {
// Fetch attendees for each game and combine the results
const gameWithAttendees$ = games.map(game =>
this.championshipService.getTeamGameAttendeesRef(team.id, game.id).pipe(
take(1),
map(attendees => {
const userAttendee = attendees.find(att => att.id == this.user.uid);
console.log(">>>>" + JSON.stringify(userAttendee))
const status = userAttendee ? userAttendee.status : null; // default to false if user is not found in attendees list
return {
...game,
teamId: team.id,
status: status,
countAttendees: attendees.filter(att => att.status == true).length,
attendees: attendees
};
})
)
);
return forkJoin(gameWithAttendees$);
}),
catchError(error => {
if (error.name === 'TimeoutError') {
console.error(`Error fetching games for team ${team.id}:`);
return of([]);
} else {
// Handle other errors, maybe rethrow or return a default object
throw error;
}
})
)),
tap(games => games.forEach(game => teamGamePastList.push(game))),
finalize(() => console.log("Team Game fetching completed"))
);
// Use combineLatest to get results when both observables have emitted
this.subscription = combineLatest([teamGame$]).subscribe({
next: () => {
this.gameList = [...teamGameList].sort((a, b):any => {
return a.dateTime.seconds > b.dateTime.seconds;
});
this.gameList = this.gameList.filter((game, index, self) =>
index === self.findIndex((t) => (t.id === game.id))
);
this.gameList$ = of(this.gameList);
console.log("Combined Game list created");
},
error: err => console.error('Error in the observable chain:', err)
});
this.subscriptionPast = combineLatest([teamGamePast$]).subscribe({
next: () => {
this.gameListPast = [...teamGamePastList].sort((a, b):any => {
return a.dateTime.seconds < b.dateTime.seconds;
});
this.gameListPast = this.gameListPast.filter((game, index, self) =>
index === self.findIndex((t) => (t.id === game.id))
);
this.gameListPast$ = of(this.gameListPast);
console.log("Combined Game list PAST created");
},
error: err => console.error('Error in the observable chain:', err)
});
*/

}

ngOnDestroy(): void {
/* if (this.subscription) {
this.subscription.unsubscribe();
}
if (this.subscriptionPast) {
this.subscriptionPast.unsubscribe();
}*/

}

getTeamsWithRankingsForYear(year: string = '2023') {
Expand Down
20 changes: 18 additions & 2 deletions src/app/pages/event/events/events.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</ion-toolbar>
</ion-header>

<ng-container *ngIf="eventsList$ | async as eventsList; else loading">
<ng-container *ngIf="eventList$ | async as eventsList; else loading">
<ion-list *ngIf="eventsList.length > 0">
<ion-list-header>
<ion-label>Kommende Veranstaltungen</ion-label>
Expand Down Expand Up @@ -105,9 +105,17 @@ <h3>
</ion-item-options>-->
</ion-item-sliding>
</ion-list>
<ion-list class="ion-padding" *ngIf="eventsList.length==0">
<ion-list-header>
<ion-label>Kommende Veranstaltungen</ion-label>
</ion-list-header>
<ion-note>
keine Veranstaltungen gefunden
</ion-note>
</ion-list>
</ng-container>

<ng-container *ngIf="eventsListPast$ | async as eventsListPast; else loading">
<ng-container *ngIf="eventListPast$ | async as eventsListPast; else loading">
<ion-list *ngIf="eventsListPast.length > 0">
<ion-list-header>
<ion-label>Vergangene Veranstaltungen</ion-label>
Expand Down Expand Up @@ -188,6 +196,14 @@ <h3>
</ion-item-options>-->
</ion-item-sliding>
</ion-list>
<ion-list class="ion-padding" *ngIf="eventsListPast.length==0">
<ion-list-header>
<ion-label>Vergangene Veranstaltungen</ion-label>
</ion-list-header>
<ion-note>
keine Veranstaltungen gefunden
</ion-note>
</ion-list>
</ng-container>

<ion-fab vertical="bottom" horizontal="end" slot="fixed">
Expand Down
Loading

0 comments on commit faa5cb6

Please sign in to comment.