2019-10-08 05:34:37 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
OnInit,
|
|
|
|
Output,
|
|
|
|
EventEmitter,
|
2019-10-29 09:17:48 +00:00
|
|
|
ViewChild,
|
2019-11-05 04:46:17 +00:00
|
|
|
ElementRef,
|
|
|
|
Input
|
2019-10-08 05:34:37 +00:00
|
|
|
} from '@angular/core';
|
|
|
|
import { NgForm } from '@angular/forms';
|
2019-11-05 04:46:17 +00:00
|
|
|
import { FileUploadItem } from '@ucap-webmessenger/api-common';
|
|
|
|
import { FileUploadQueueComponent } from '@ucap-webmessenger/ui';
|
2019-09-23 05:23:24 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ucap-chat-form',
|
|
|
|
templateUrl: './form.component.html',
|
|
|
|
styleUrls: ['./form.component.scss']
|
|
|
|
})
|
|
|
|
export class FormComponent implements OnInit {
|
2019-11-05 04:46:17 +00:00
|
|
|
@Input()
|
|
|
|
fileUploadQueue: FileUploadQueueComponent;
|
|
|
|
|
2019-10-08 05:34:37 +00:00
|
|
|
@Output()
|
|
|
|
send = new EventEmitter<string>();
|
|
|
|
|
2019-10-29 09:17:48 +00:00
|
|
|
@Output()
|
2019-11-05 04:46:17 +00:00
|
|
|
sendFiles = new EventEmitter<FileUploadItem[]>();
|
2019-10-29 09:17:48 +00:00
|
|
|
|
2019-11-20 09:04:24 +00:00
|
|
|
@Output()
|
|
|
|
toggleStickerSelector = new EventEmitter<void>();
|
|
|
|
|
2019-10-08 05:34:37 +00:00
|
|
|
@ViewChild('replyForm', { static: false })
|
|
|
|
replyForm: NgForm;
|
|
|
|
|
2019-11-01 06:06:37 +00:00
|
|
|
@ViewChild('replyInput', { static: false })
|
|
|
|
replyInput: ElementRef<HTMLTextAreaElement>;
|
|
|
|
|
2019-10-29 09:17:48 +00:00
|
|
|
@ViewChild('fileInput', { static: false })
|
|
|
|
fileInput: ElementRef<HTMLInputElement>;
|
|
|
|
|
2019-09-23 05:23:24 +00:00
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
2019-11-01 06:06:37 +00:00
|
|
|
focus(): void {
|
|
|
|
this.replyInput.nativeElement.focus();
|
|
|
|
}
|
|
|
|
|
2019-10-08 05:34:37 +00:00
|
|
|
onSend(event: Event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.send.emit(this.replyForm.form.value.message);
|
|
|
|
this.replyForm.reset();
|
|
|
|
}
|
2019-10-29 09:17:48 +00:00
|
|
|
|
|
|
|
onClickFileInput() {
|
|
|
|
this.fileInput.nativeElement.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
onChangeFileInput() {
|
2019-11-05 05:55:17 +00:00
|
|
|
const fileUploadItems = FileUploadItem.fromFiles(
|
|
|
|
this.fileInput.nativeElement.files
|
|
|
|
);
|
2019-11-05 04:46:17 +00:00
|
|
|
|
|
|
|
if (!!this.fileUploadQueue) {
|
|
|
|
this.fileUploadQueue.onFileSelected(fileUploadItems);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.sendFiles.emit(fileUploadItems);
|
2019-11-05 05:55:17 +00:00
|
|
|
|
|
|
|
this.fileInput.nativeElement.value = '';
|
2019-10-29 09:17:48 +00:00
|
|
|
}
|
2019-11-20 09:04:24 +00:00
|
|
|
|
|
|
|
onClickStickerSelector() {
|
|
|
|
this.toggleStickerSelector.emit();
|
|
|
|
}
|
2019-09-23 05:23:24 +00:00
|
|
|
}
|