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"
|
||||
>
|
||||
<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)"
|
||||
[linkUrl]="'/collections/' + item.id"
|
||||
[count]="item.itemCount"
|
||||
|
|
|
|||
|
|
@ -92,12 +92,24 @@ export class AllCollectionsComponent implements OnInit {
|
|||
|
||||
this.accountService.currentUser$.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(user => {
|
||||
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));
|
||||
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) {
|
||||
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 => {
|
||||
if (!user) return;
|
||||
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));
|
||||
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 {
|
||||
this.scrollService.setScrollContainer(this.scrollingBlock);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue