import { AppStore , SetSelectedNodesAction , SnackbarErrorAction , SnackbarInfoAction , getAppSelection , getUserProfile } from '@alfresco/aca-shared/store' ; import { AppHookService } from '@alfresco/aca-shared' ; import { ProfileState , SelectionState } from '@alfresco/adf-extensions' ; import { Component , ViewEncapsulation } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { Observable } from 'rxjs' ; import { LibraryMembershipErrorEvent , LibraryMembershipToggleEvent } from '@alfresco/adf-core' ; @ Component ( { selector : 'app-toggle-join-library-button' , template : `
    <button
      mat-icon-button
      color="primary"
      #membership="libraryMembership"
      (toggle)="onToggleEvent($event)"
      (error)="onErrorEvent($event)"
      [adf-library-membership]="(selection$ | async).library"
      [isAdmin]="(profile$ | async).isAdmin"
      [attr.title]="(membership.isJoinRequested | async) ? ('APP.ACTIONS.CANCEL_JOIN' | translate) : ('APP.ACTIONS.JOIN' | translate)"
    >
      <mat-icon *ngIf="membership.isJoinRequested | async">cancel</mat-icon>
      <mat-icon *ngIf="!(membership.isJoinRequested | async)" svgIcon="adf:join_library"></mat-icon>
    </button>
  ` , encapsulation : ViewEncapsulation . None , host : { class : 'app-toggle-join-library' } } ) export class ToggleJoinLibraryButtonComponent { selection$ : Observable < SelectionState > ; profile$ : Observable < ProfileState > ; constructor ( private store , private appHookService ) { this . selection$ = this . store . select ( getAppSelection ) ; this . profile$ = this . store . select ( getUserProfile ) ; } onToggleEvent ( event ) { this . store . dispatch ( new SnackbarInfoAction ( event . i18nKey ) ) ; if ( event . shouldReload ) { this . appHookService . libraryJoined . next ( ) ; } else { if ( event . updatedEntry ) { this . store . dispatch ( new SetSelectedNodesAction ( [ { entry : event . updatedEntry , isLibrary : true } as any ] ) ) ; } this . appHookService . joinLibraryToggle . next ( ) ; } } onErrorEvent ( event ) { this . store . dispatch ( new SnackbarErrorAction ( event . i18nKey ) ) ; } }