Same promote/unpromote logic but for collections
Found a bug where the shouldRender isn't called again when the entity state updates!
This commit is contained in:
parent
3fabf9e658
commit
6d44f13af7
3 changed files with 27 additions and 3 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
[trackByIdentity]="trackByIdentity"
|
[trackByIdentity]="trackByIdentity"
|
||||||
>
|
>
|
||||||
<ng-template #cardItem let-item let-position="idx">
|
<ng-template #cardItem let-item let-position="idx">
|
||||||
<app-card-item [title]="item.title" [entity]="item" [actions]="collectionTagActions"
|
<app-card-item [title]="item.title" [entity]="item" [actions]="collectionTagActions" [actionEntity]="item"
|
||||||
[imageUrl]="imageService.getCollectionCoverImage(item.id)"
|
[imageUrl]="imageService.getCollectionCoverImage(item.id)"
|
||||||
[linkUrl]="'/collections/' + item.id"
|
[linkUrl]="'/collections/' + item.id"
|
||||||
[count]="item.itemCount"
|
[count]="item.itemCount"
|
||||||
|
|
|
||||||
|
|
@ -92,12 +92,24 @@ export class AllCollectionsComponent implements OnInit {
|
||||||
|
|
||||||
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(user => {
|
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(user => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
this.collectionTagActions = this.actionFactoryService.getCollectionTagActions(this.handleCollectionActionCallback.bind(this))
|
this.collectionTagActions = this.actionFactoryService.getCollectionTagActions(
|
||||||
|
this.handleCollectionActionCallback.bind(this), this.shouldRenderCollection.bind(this))
|
||||||
.filter(action => this.collectionService.actionListFilter(action, user));
|
.filter(action => this.collectionService.actionListFilter(action, user));
|
||||||
this.cdRef.markForCheck();
|
this.cdRef.markForCheck();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldRenderCollection(action: ActionItem<UserCollection>, entity: UserCollection, user: User) {
|
||||||
|
switch (action.action) {
|
||||||
|
case Action.Promote:
|
||||||
|
return !entity.promoted;
|
||||||
|
case Action.UnPromote:
|
||||||
|
return entity.promoted;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loadCollection(item: UserCollection) {
|
loadCollection(item: UserCollection) {
|
||||||
this.router.navigate(['collections', item.id]);
|
this.router.navigate(['collections', item.id]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,8 @@ export class CollectionDetailComponent implements OnInit, AfterContentChecked {
|
||||||
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(user => {
|
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(user => {
|
||||||
if (!user) return;
|
if (!user) return;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.collectionTagActions = this.actionFactoryService.getCollectionTagActions(this.handleCollectionActionCallback.bind(this))
|
this.collectionTagActions = this.actionFactoryService.getCollectionTagActions(
|
||||||
|
this.handleCollectionActionCallback.bind(this), this.shouldRenderCollection.bind(this))
|
||||||
.filter(action => this.collectionService.actionListFilter(action, user));
|
.filter(action => this.collectionService.actionListFilter(action, user));
|
||||||
this.cdRef.markForCheck();
|
this.cdRef.markForCheck();
|
||||||
});
|
});
|
||||||
|
|
@ -225,6 +226,17 @@ export class CollectionDetailComponent implements OnInit, AfterContentChecked {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shouldRenderCollection(action: ActionItem<UserCollection>, entity: UserCollection, user: User) {
|
||||||
|
switch (action.action) {
|
||||||
|
case Action.Promote:
|
||||||
|
return !entity.promoted;
|
||||||
|
case Action.UnPromote:
|
||||||
|
return entity.promoted;
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ngAfterContentChecked(): void {
|
ngAfterContentChecked(): void {
|
||||||
this.scrollService.setScrollContainer(this.scrollingBlock);
|
this.scrollService.setScrollContainer(this.scrollingBlock);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue