From 7f5e19ddfe2c4d0ca00bb609aabf132e3443c0f1 Mon Sep 17 00:00:00 2001 From: Alec Menconi Date: Sun, 10 Mar 2024 19:09:10 -0400 Subject: [PATCH] More DataService member$ and space$ fixes --- .../member-about/member-about.component.html | 8 +++++++ .../member-about/member-about.component.ts | 13 ++++------- .../pages/member/pages/awards/awards.page.ts | 5 ++-- .../pages/member/pages/badges/badges.page.ts | 5 ++-- .../pages/member/pages/member/member.page.ts | 23 ++++++++++++++----- src/app/pages/member/pages/nfts/nfts.page.ts | 3 ++- .../pages/spaces/member-spaces.component.ts | 5 ++-- .../pages/transactions/transactions.page.ts | 3 ++- src/app/pages/member/services/data.service.ts | 1 + 9 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/app/components/member/components/member-about/member-about.component.html b/src/app/components/member/components/member-about/member-about.component.html index d47093f..7614d42 100644 --- a/src/app/components/member/components/member-about/member-about.component.html +++ b/src/app/components/member/components/member-about/member-about.component.html @@ -154,6 +154,14 @@

> No Contribution Yet. + +
+ MemberId: {{ (data.member$ | async)?.uid }}
+ Spaces: {{ (data.space$ | async) }} +
+ Space Item: {{ s.uid }}
+
+
diff --git a/src/app/components/member/components/member-about/member-about.component.ts b/src/app/components/member/components/member-about/member-about.component.ts index 80932f2..264d6bb 100644 --- a/src/app/components/member/components/member-about/member-about.component.ts +++ b/src/app/components/member/components/member-about/member-about.component.ts @@ -34,7 +34,8 @@ export class MemberAboutComponent implements OnInit { public previewImageService: PreviewImageService, public auth: AuthService, public cd: ChangeDetectorRef, - ) {} + ) { + } public ngOnInit(): void { this.data.triggerAction$.pipe(skip(1), untilDestroyed(this)).subscribe((s) => { @@ -63,14 +64,8 @@ export class MemberAboutComponent implements OnInit { this.drawerVisible$.next(false); } - /* - public trackByUid(index: number, item: any): number { - return item.uid; - } - */ - public trackByUid(index: number, item: any): any { - console.log('member-about trackByUid fired, (index, item): ', index, item); - return item ? item.uid : undefined; + return item ? item.uid : index; } + } diff --git a/src/app/pages/member/pages/awards/awards.page.ts b/src/app/pages/member/pages/awards/awards.page.ts index a4c0e1d..90efbfb 100644 --- a/src/app/pages/member/pages/awards/awards.page.ts +++ b/src/app/pages/member/pages/awards/awards.page.ts @@ -50,7 +50,8 @@ export class AwardsPage { return this.auth.isLoggedIn$; } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } + } diff --git a/src/app/pages/member/pages/badges/badges.page.ts b/src/app/pages/member/pages/badges/badges.page.ts index 73b7372..a533edc 100644 --- a/src/app/pages/member/pages/badges/badges.page.ts +++ b/src/app/pages/member/pages/badges/badges.page.ts @@ -124,7 +124,8 @@ export class BadgesPage implements OnInit { return this.auth.isLoggedIn$; } - public trackByUid(index: number, item: Transaction) { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } + } diff --git a/src/app/pages/member/pages/member/member.page.ts b/src/app/pages/member/pages/member/member.page.ts index 6043451..6a3904d 100644 --- a/src/app/pages/member/pages/member/member.page.ts +++ b/src/app/pages/member/pages/member/member.page.ts @@ -16,7 +16,7 @@ import { SeoService } from '@core/services/seo'; import { ROUTER_UTILS } from '@core/utils/router.utils'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { FILE_SIZES, Member } from '@build-5/interfaces'; -import { BehaviorSubject, Subscription, skip } from 'rxjs'; +import { BehaviorSubject, Subscription, filter, map, skip } from 'rxjs'; import { MemberApi } from './../../../../@api/member.api'; import { NavigationService } from './../../../../@core/services/navigation/navigation.service'; import { DataService } from './../../services/data.service'; @@ -116,17 +116,28 @@ export class MemberPage implements OnInit, OnDestroy { .pipe(untilDestroyed(this)) .subscribe(this.data.awardsPending$), ); + // TODO Implement search. This is parked since we will be implementing new search here. + this.subscriptions$.push( - this.memberApi.topSpaces(memberId).pipe(untilDestroyed(this)).subscribe(this.data.space$), + this.memberApi.topSpaces(memberId).pipe( + untilDestroyed(this), + map(spaces => spaces.filter(space => space && typeof space.uid === 'string' && space.uid.trim() !== '')) + ).subscribe((filteredSpaces) => { + this.data.space$.next(filteredSpaces); + }), ); + this.subscriptions$.push( this.memberApi .listen(memberId) - .pipe(untilDestroyed(this)) - .subscribe((v) => { - // Only pass next stage. - this.data.member$.next(v); + .pipe( + untilDestroyed(this), + filter(v => v && typeof v.uid === 'string' && v.uid.trim() !== '') + ) + .subscribe((validMember) => { + // Only pass next stage if valid. + this.data.member$.next(validMember); }), ); diff --git a/src/app/pages/member/pages/nfts/nfts.page.ts b/src/app/pages/member/pages/nfts/nfts.page.ts index aab14d2..c1f0d77 100644 --- a/src/app/pages/member/pages/nfts/nfts.page.ts +++ b/src/app/pages/member/pages/nfts/nfts.page.ts @@ -42,7 +42,8 @@ export class NFTsPage implements OnInit { private route: ActivatedRoute, private router: Router, private nftSelectionService: NftSelectionService, - ) {} + ) { + } public ngOnInit(): void { this.route.params.subscribe((params) => { diff --git a/src/app/pages/member/pages/spaces/member-spaces.component.ts b/src/app/pages/member/pages/spaces/member-spaces.component.ts index af34481..2fab35d 100644 --- a/src/app/pages/member/pages/spaces/member-spaces.component.ts +++ b/src/app/pages/member/pages/spaces/member-spaces.component.ts @@ -49,7 +49,8 @@ export class MemberSpacesComponent implements OnInit { ); } - public trackByUid(index: number, item: any): number { - return item.uid; + public trackByUid(index: number, item: any): any { + return item ? item.uid : index; } + } diff --git a/src/app/pages/member/pages/transactions/transactions.page.ts b/src/app/pages/member/pages/transactions/transactions.page.ts index dd547e2..e30ecf8 100644 --- a/src/app/pages/member/pages/transactions/transactions.page.ts +++ b/src/app/pages/member/pages/transactions/transactions.page.ts @@ -46,7 +46,8 @@ export class TransactionsPage implements OnInit, OnDestroy { private memberApi: MemberApi, private cd: ChangeDetectorRef, private route: ActivatedRoute, - ) {} + ) { + } public ngOnInit(): void { this.route.params.subscribe((params) => { diff --git a/src/app/pages/member/services/data.service.ts b/src/app/pages/member/services/data.service.ts index 770110a..da95fbe 100644 --- a/src/app/pages/member/services/data.service.ts +++ b/src/app/pages/member/services/data.service.ts @@ -22,6 +22,7 @@ export class DataService { public member$: BehaviorSubject = new BehaviorSubject( undefined, ); + public awardsCompleted$: BehaviorSubject = new BehaviorSubject< Award[] | undefined >(undefined);