import { Component } from '@angular/core' ; import { FileUploadSelectEvent } from '../../../../common/components/file-upload/file-upload.component' ; import { DomSanitizer , SafeResourceUrl } from '@angular/platform-browser' ; import { ComposerService } from '../../services/composer.service' ; import { Attachment } from '../../services/attachment.service' ; import { VideoPoster } from '../../services/video-poster.service' ; @ Component ( { selector : 'm-composer__coverPhotoSelector' , templateUrl : './cover-photo-selector.component.html' , } ) export class ComposerCoverPhotoSelectorComponent { isExpanded = false ; filePreview : SafeResourceUrl ; constructor ( private service , private domSanitizer ) { } onExpandToggle ( e ) { this . isExpanded = ! this . isExpanded ; } async onFileSelect ( e ) { if ( ! e ) return ; if ( ! ( e instanceof File ) ) { console . warn ( 'Composer/Toolbar: Unsupported attachment type' , e ) ; return ; } this . filePreview = this . domSanitizer . bypassSecurityTrustResourceUrl ( URL . createObjectURL ( e ) ) ; let fileBase64 = await new Promise ( ( resolve , reject ) => { const reader = new FileReader ( ) ; reader . addEventListener ( 'load' , ( ) => { resolve ( reader . result . toString ( ) ) ; } , false ) ; reader . readAsDataURL ( e ) ; } ) ; const videoPoster = { url : URL . createObjectURL ( e ) , file : e , fileBase64 , } ; this . service . videoPoster$ . next ( videoPoster ) ; this . isExpanded = false ; } onRemoveFileClick ( e ) { this . filePreview = null ; this . service . videoPoster$ . next ( null ) ; } }