Skip to content

Commit

Permalink
feat members
Browse files Browse the repository at this point in the history
  • Loading branch information
sansan88 committed Sep 11, 2023
1 parent 6a0b6f0 commit f6d677d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 97 deletions.
41 changes: 22 additions & 19 deletions src/app/pages/club/club.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,23 @@
</ion-list>
-->

<ion-list >
<ion-list-header> Anfragen </ion-list-header>
<ion-item *ngFor="let request of requestList$ | async">
<ion-avatar slot="start">
<img src="{{request?.profilePicture}}" />
</ion-avatar>
<ion-label> {{request?.firstName}} {{request?.lastName}} </ion-label>
<ion-button color="danger" (click)="deleteClubRequest(request)" slot="end">
<ion-icon icon-only name="trash"></ion-icon>
</ion-button>
<ion-button
color="success"
(click)="approveClubRequest(request)"
slot="end"
>
<ion-icon icon-only name="checkmark-outline"></ion-icon>
</ion-button>
</ion-item>
</ion-list>
<ng-container *ngIf="requestList$ | async as requests; else noRequests">
<ion-list *ngIf="requests.length > 0">
<ion-list-header> Anfragen </ion-list-header>
<ion-item *ngFor="let request of requests">
<ion-avatar slot="start">
<img [src]="request?.profilePicture" />
</ion-avatar>
<ion-label> {{request?.firstName}} {{request?.lastName}} </ion-label>
<ion-button color="danger" (click)="deleteClubRequest(request)" slot="end">
<ion-icon icon-only name="trash"></ion-icon>
</ion-button>
<ion-button color="success" (click)="approveClubRequest(request)" slot="end">
<ion-icon icon-only name="checkmark-outline"></ion-icon>
</ion-button>
</ion-item>
</ion-list>
</ng-container>

<ion-list >
<ion-list-header> Mitglieder </ion-list-header>
Expand All @@ -76,3 +74,8 @@
</ion-item>
</ion-list>
</ion-content>


<ng-template #noRequests>
<!-- You can put any placeholder or message here if needed when there are no requests -->
</ng-template>
2 changes: 0 additions & 2 deletions src/app/pages/club/club.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ export class ClubPage implements OnInit {
await this.toastActionCanceled();
}



}

async deleteClubRequest(user) {
Expand Down
63 changes: 22 additions & 41 deletions src/app/pages/team/team.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,24 @@
<ion-title size="large">{{team.name}}</ion-title>
</ion-toolbar>
</ion-header>
<!--

<ion-list *ngIf="requestList.length > 0">
<ion-list-header> Anfragen </ion-list-header>
<ion-item *ngFor="let member of requestList">
<ion-avatar slot="start">
<img src="{{member?.profilePicture}}" />
</ion-avatar>
<ion-label> {{member?.firstName}} {{member?.lastName}} </ion-label>
<ion-button color="danger" (click)="deleteteamRequest(member)" slot="end">
<ion-icon icon-only name="trash"></ion-icon>
</ion-button>
<ion-button
color="success"
(click)="approveteamRequest(member)"
slot="end"
>
<ion-icon icon-only name="checkmark-outline"></ion-icon>
</ion-button>
</ion-item>
</ion-list>
-->

<ion-list >
<ion-list-header> Anfragen </ion-list-header>
<ion-item *ngFor="let request of requestList$ | async">
<ion-avatar slot="start">
<img src="{{request?.profilePicture}}" />
</ion-avatar>
<ion-label> {{request?.firstName}} {{request?.lastName}} </ion-label>
<ion-button color="danger" (click)="deleteTeamRequest(request)" slot="end">
<ion-icon icon-only name="trash"></ion-icon>
</ion-button>
<ion-button
color="success"
(click)="approveTeamRequest(request)"
slot="end"
>
<ion-icon icon-only name="checkmark-outline"></ion-icon>
</ion-button>
</ion-item>
</ion-list>
<ng-container *ngIf="requestList$ | async as requests; else noRequests">
<ion-list *ngIf="requests.length > 0">
<ion-list-header> Anfragen </ion-list-header>
<ion-item *ngFor="let request of requests">
<ion-avatar slot="start">
<img [src]="request?.profilePicture" />
</ion-avatar>
<ion-label> {{request?.firstName}} {{request?.lastName}} </ion-label>
<ion-button color="danger" (click)="deleteTeamRequest(request)" slot="end">
<ion-icon icon-only name="trash"></ion-icon>
</ion-button>
<ion-button color="success" (click)="approveTeamRequest(request)" slot="end">
<ion-icon icon-only name="checkmark-outline"></ion-icon>
</ion-button>
</ion-item>
</ion-list>
</ng-container>

<ion-list >
<ion-list-header> Mitglieder </ion-list-header>
Expand All @@ -76,3 +52,8 @@
</ion-item>
</ion-list>
</ion-content>


<ng-template #noRequests>
<!-- You can put any placeholder or message here if needed when there are no requests -->
</ng-template>
101 changes: 66 additions & 35 deletions src/app/pages/team/team.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class TeamPage implements OnInit {

private subscription: Subscription;

private subscriptionRequest: Subscription;
private subscriptionAdmin: Subscription;
private subscriptionMember: Subscription;

constructor(
private readonly modalCtrl: ModalController,
Expand All @@ -36,106 +39,134 @@ export class TeamPage implements OnInit {
const adminList: Profile[] = [];
const requestList: any[] = [];


const member$ = this.fbService.getTeamRef(this.team.id).pipe(
take(1),
switchMap(team => this.fbService.getTeamMemberRefs(team.id).pipe(
take(1),
switchMap(club => this.fbService.getTeamMemberRefs(club.id).pipe(
defaultIfEmpty([{}]),
startWith([{}]),
startWith([{}])
)),
concatMap((teamMemberArray:any) => from(teamMemberArray)),
tap((member:any)=>console.log(member.id)),
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, teamId: this.team.id}]
map(user => {
return [{...user, clubId: this.team.id}]
}),
catchError(error => {
console.error('Error fetching team member:', error);
console.error('Error fetching member:', error);
return of([]);
})
)
),
tap(user => user.forEach(n => memberList.push(n))),
tap(users => users.forEach(n => memberList.push(n))),
finalize(() => console.log("Team 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.getTeamRef(this.team.id).pipe(
take(1),
switchMap(team => this.fbService.getTeamAdminRefs(team.id).pipe(
take(1),
switchMap(club => this.fbService.getTeamAdminRefs(club.id).pipe(
defaultIfEmpty([{}]),
startWith([{}]),
startWith([{}])
)),
concatMap((teamAdminArray:any) => from(teamAdminArray)),
tap((admin:any)=>console.log(admin.id)),
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, teamId: this.team.id}]
map(user => {
return [{...user, clubId: this.team.id}]
}),
catchError(error => {
console.error('Error fetching teamadmin:', error);
return of([]);
})
)
),
tap(user => user.forEach(n => adminList.push(n))),
tap(users => users.forEach(n => adminList.push(n))),
finalize(() => console.log("Team 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.getTeamRef(this.team.id).pipe(
take(1),
switchMap(team => this.fbService.getTeamRequestRefs(team.id).pipe(
take(1),
switchMap(club => this.fbService.getTeamRequestRefs(club.id).pipe(
defaultIfEmpty([{}]),
startWith([{}]),
startWith([{}])
)),
concatMap((teamRequestsArray:any) => from(teamRequestsArray)),
tap((request:any)=>console.log(request.id)),
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, teamId: this.team.id}]
map(user => {
return [{...user, clubId: this.team.id}]
}),
catchError(error => {
console.error('Error fetching teamadmin:', error);
return of([]);
})
)
),
tap(user => user.forEach(n => requestList.push(n))),
finalize(() => console.log("Team Admin"))
tap(users => users.forEach(n => requestList.push(n))),
finalize(() => console.log("Team Requests"))
)

// Use combineLatest to get results when both observables have emitted
this.subscription = combineLatest([member$, admin$, requests$]).subscribe({
this.subscriptionRequest = requests$.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.subscription) {
if (this.subscriptionAdmin) {
this.subscription.unsubscribe();
}

}
if (this.subscriptionMember) {
this.subscription.unsubscribe();
}
if (this.subscriptionRequest) {
this.subscription.unsubscribe();
}

}

async deleteTeamRequest(request) {
await this.fbService.deleteUserTeamRequest(request.teamId, request.id);
await this.toastActionSaved();

}

async approveTeamRequest(request) {
await this.fbService.approveUserTeamRequest(request.teamId, request.id);
await this.toastActionSaved();
Expand Down

0 comments on commit f6d677d

Please sign in to comment.