Skip to content

Commit

Permalink
feat update user list for clubs
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Nov 23, 2023
1 parent 6079e96 commit a91db51
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 405 deletions.
280 changes: 2 additions & 278 deletions src/app/pages/club/club.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,290 +69,14 @@ export class ClubPage implements OnInit {
error: (err) => console.error("Club Error in subscription:", err),
complete: () => console.log("Club Observable completed")
});


/*
const teamList: any[] = [];
const teams$ = this.fbService.getClubTeamRefs(this.club.id).pipe(
take(1),
concatMap((teamArray:any) => from(teamArray)),
tap((team:any)=>console.log(team.id)),
concatMap((team:any) =>
this.fbService.getTeamRef(team.id).pipe(
take(1),
tap(team=>teamList.push(team)),
)),
finalize(()=>console.log("teams done"))
);
this.subscriptionTeamList = forkJoin([teams$]).subscribe({
next: () => {
console.log("teams");
this.alertTeamSelection = [];
for (const item of teamList){
// console.log(item)
this.alertTeamSelection.push({
label: item.name,
type: 'checkbox',
value: item.id,
});
}
},
error: err => console.error('Error in the observable chain:', err)
});
const memberList: Profile[] = [];
const adminList: Profile[] = [];
const requestList: any[] = [];
*/

/*
const member$ = this.fbService.getClubRef(this.club.id).pipe(
take(1),
switchMap(club => this.fbService.getClubMemberRefs(club.id).pipe(
take(1),
defaultIfEmpty([{}]),
startWith([{}]),
)),
concatMap((clubMemberArray:any) => from(clubMemberArray)),
tap((member:any)=>console.log(member.id)),
concatMap(user =>
this.userProfileService.getUserProfileById(user.id).pipe(
take(1),
map(user=>{
return [{...user, clubId: this.club.id}]
}),
catchError(error => {
console.error('Error fetching team member:', error);
return of([]);
})
)
),
tap(users => users.forEach(n => memberList.push(n))),
finalize(() => console.log("Club Member"))
)
const admin$ = this.fbService.getClubRef(this.club.id).pipe(
take(1),
switchMap(club => this.fbService.getClubAdminRefs(club.id).pipe(
take(1),
defaultIfEmpty([{}]),
startWith([{}]),
)),
concatMap((clubAdminArray:any) => from(clubAdminArray)),
tap((admin:any)=>console.log(admin.id)),
concatMap(user =>
this.userProfileService.getUserProfileById(user.id).pipe(
take(1),
map(user=>{
return [{...user, clubId: this.club.id}]
}),
catchError(error => {
console.error('Error fetching teamadmin:', error);
return of([]);
})
)
),
tap(users => users.forEach(n => adminList.push(n))),
finalize(() => console.log("Club Admin"))
)*/
/*
const member$ = this.fbService.getClubRef(this.club.id).pipe(
take(1),
switchMap(club => this.fbService.getClubMemberRefs(club.id).pipe(
defaultIfEmpty([{}]),
startWith([{}])
)),
switchMap((clubMemberArray:any) => {
// Clear out the requestList when new data comes in
memberList.length = 0;
return from(clubMemberArray);
}),
tap((member:any) => console.log(member.id)),
concatMap(user =>
this.userProfileService.getUserProfileById(user.id).pipe(
take(1),
map(user => {
return [{...user, clubId: this.club.id}]
}),
catchError(error => {
console.error('Error fetching member:', error);
return of([]);
})
)
),
tap(users => users.forEach(n => memberList.push(n))),
finalize(() => console.log("Club Member"))
)
this.subscriptionMember = member$.subscribe({
next: () => {
this.memberList$ = of(memberList.filter(obj => Object.keys(obj).length > 1));
},
error: err => console.error('Error in the observable chain:', err)
});
const admin$ = this.fbService.getClubRef(this.club.id).pipe(
take(1),
switchMap(club => this.fbService.getClubAdminRefs(club.id).pipe(
defaultIfEmpty([{}]),
startWith([{}])
)),
switchMap((clubAdminArray:any) => {
// Clear out the requestList when new data comes in
adminList.length = 0;
return from(clubAdminArray);
}),
tap((admin:any) => console.log(admin.id)),
concatMap(user =>
this.userProfileService.getUserProfileById(user.id).pipe(
take(1),
map(user => {
return [{...user, clubId: this.club.id}]
}),
catchError(error => {
console.error('Error fetching teamadmin:', error);
return of([]);
})
)
),
tap(users => users.forEach(n => adminList.push(n))),
finalize(() => console.log("Club Admin"))
)
this.subscriptionAdmin = admin$.subscribe({
next: () => {
this.adminList$ = of(adminList.filter(obj => Object.keys(obj).length > 1));
},
error: err => console.error('Error in the observable chain:', err)
});
const requests$ = this.fbService.getClubRef(this.club.id).pipe(
take(1),
switchMap(club => this.fbService.getClubRequestRefs(club.id).pipe(
defaultIfEmpty([{}]),
startWith([{}])
)),
switchMap((clubRequestArray:any) => {
// Clear out the requestList when new data comes in
requestList.length = 0;
return from(clubRequestArray);
}),
tap((request:any) => console.log(request.id)),
concatMap(user =>
this.userProfileService.getUserProfileById(user.id).pipe(
take(1),
map(user => {
return [{...user, clubId: this.club.id}]
}),
catchError(error => {
console.error('Error fetching teamadmin:', error);
return of([]);
})
)
),
tap(users => users.forEach(n => requestList.push(n))),
finalize(() => console.log("Club Requests"))
)
this.subscriptionRequest = requests$.subscribe({
next: () => {
this.requestList$ = of(requestList.filter(obj => Object.keys(obj).length > 1));
},
error: err => console.error('Error in the observable chain:', err)
});
*/
/*const requests$ = this.fbService.getClubRef(this.club.id).pipe(
take(1),
switchMap(club => this.fbService.getClubRequestRefs(club.id).pipe(
take(1),
defaultIfEmpty([{}]),
startWith([{}]),
)),
concatMap((clubRequestArray:any) => from(clubRequestArray)),
tap((request:any)=>console.log(request.id)),
concatMap(user =>
this.userProfileService.getUserProfileById(user.id).pipe(
take(1),
map(user=>{
return [{...user, clubId: this.club.id}]
}),
catchError(error => {
console.error('Error fetching teamadmin:', error);
return of([]);
})
)
),
tap(users => users.forEach(n => requestList.push(n))),
finalize(() => console.log("Club Requests"))
)
// Use combineLatest to get results when both observables have emitted
this.subscription = combineLatest([member$, admin$]).subscribe({
next: () => {
this.adminList$ = of(adminList.filter(obj => Object.keys(obj).length > 1))
this.memberList$ = of(memberList.filter(obj => Object.keys(obj).length > 1))
this.requestList$ = of(requestList.filter(obj => Object.keys(obj).length > 1));
},
error: err => console.error('Error in the observable chain:', err)
});*/
}

ngOnDestroy() {
/*
if (this.subscriptionAdmin) {
this.subscriptionAdmin.unsubscribe();
}
if (this.subscriptionMember) {
this.subscriptionMember.unsubscribe();
}
if (this.subscriptionRequest) {
this.subscriptionRequest.unsubscribe();
}
if (this.subscriptionTeamList) {
this.subscriptionTeamList.unsubscribe();
}*/
}

}

getClub(clubId: string) {
/*
return this.authService.getUser$().pipe(
take(1),
tap(user => {
this.user = user;
if (!user) {
console.log("No user found");
throw new Error("User not found");
}
}),
switchMap(() => this.fbService.getClubRef(clubId)),
switchMap(club => {
if (!club) return of(null); // If no club is found, return null
return combineLatest({
clubMembers: this.fbService.getClubMemberRefs(clubId),
clubAdmins: this.fbService.getClubAdminRefs(clubId)
}).pipe(
map(({ clubMembers, clubAdmins }) => ({
...club,
clubMembers,
clubAdmins
})),
catchError(() => of({
...club,
clubMembers: [],
clubAdmins: []
})) // If error in fetching members or admins, return club with empty arrays
);
}),
catchError(err => {
console.error("Error in getClubWithMembersAndAdmins:", err);
return of(null); // Return null on error
})
);*/

return this.authService.getUser$().pipe(
take(1),
tap(user => {
Expand Down
Loading

0 comments on commit a91db51

Please sign in to comment.