import { Component , ComponentFactoryResolver , ComponentRef , ChangeDetectorRef , Input , OnDestroy , OnInit , Output , EventEmitter , ViewChild , } from '@angular/core' ; import { GroupsTileComponent } from '../../groups/tile/tile.component' ; import { DynamicHostDirective } from '../../../common/directives/dynamic-host.directive' ; import { FeaturesService } from '../../../services/features.service' ; @ Component ( { selector : 'm-newsfeed__entity' , templateUrl : 'entity.component.html' , } ) export class NewsfeedEntityComponent { @ Output ( ) deleted = new EventEmitter < any > ( ) ; @ ViewChild ( DynamicHostDirective ) host : DynamicHostDirective ; entity ; @ Input ( ) displayOptions = { v2 : false , isFeed : true } ; constructor ( protected componentFactoryResolver , protected cd , public featuresService ) { } @ Input ( 'entity' ) set setEntity ( entity ) { this . entity = entity ; this . updateComponents ( ) ; } private getComponent ( type ) { return type === 'user' ? null : GroupsTileComponent ; } @ Input ( ) slot : number ; clear ( ) { this . cd . detectChanges ( ) ; this . cd . markForCheck ( ) ; if ( this . host ) this . host . viewContainerRef . clear ( ) ; } updateComponents ( ) { if ( this . entity && this . entity . type === 'group' ) { this . clear ( ) ; const componentFactory = this . componentFactoryResolver . resolveComponentFactory ( this . getComponent ( this . entity . type ) ) ; let componentRef = this . host . viewContainerRef . createComponent ( componentFactory ) ; componentRef . instance . entity = this . entity ; componentRef . changeDetectorRef . detectChanges ( ) ; } } /**
     * Sets entity to null and by extension hides it.
     */ delete ( ) { this . deleted . emit ( this . entity ) ; } }