Skip to content

Commit

Permalink
Merge pull request #157 from GetStream/fix-message-edit
Browse files Browse the repository at this point in the history
fix: Message edit
  • Loading branch information
szuperaz authored Dec 8, 2021
2 parents fd3bb62 + 8c300a2 commit 6ba9032
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { OnInit } from '@angular/core';
import {
AfterViewInit,
ChangeDetectorRef,
Expand Down Expand Up @@ -40,7 +39,7 @@ import { TextareaInterface } from './textarea.interface';
providers: [AttachmentService],
})
export class MessageInputComponent
implements OnInit, OnChanges, OnDestroy, AfterViewInit
implements OnChanges, OnDestroy, AfterViewInit
{
@Input() isFileUploadEnabled: boolean | undefined;
@Input() areMentionsEnabled: boolean | undefined;
Expand All @@ -64,6 +63,7 @@ export class MessageInputComponent
private textareaAnchor!: TextareaDirective;
private subscriptions: Subscription[] = [];
private hideNotification: Function | undefined;
private isViewInited = false;

constructor(
private channelService: ChannelService,
Expand All @@ -85,17 +85,6 @@ export class MessageInputComponent
}
)
);
this.attachmentUploads$ = this.attachmentService.attachmentUploads$;
this.isFileUploadEnabled = this.configService.isFileUploadEnabled;
this.acceptedFileTypes = this.configService.acceptedFileTypes;
this.isMultipleFileUploadEnabled =
this.configService.isMultipleFileUploadEnabled;
this.areMentionsEnabled = this.configService.areMentionsEnabled;
this.mentionAutocompleteItemTemplate =
this.configService.mentionAutocompleteItemTemplate;
this.mentionScope = this.configService.mentionScope;
}
ngOnInit(): void {
this.subscriptions.push(
this.channelService.activeChannel$.subscribe((channel) => {
this.textareaValue = '';
Expand All @@ -106,14 +95,26 @@ export class MessageInputComponent
capabilities.indexOf('upload-file') !== -1;
this.canSendLinks = capabilities.indexOf('send-links') !== -1;
this.canSendMessages = capabilities.indexOf('send-message') !== -1;
this.cdRef.detectChanges();
this.initTextarea();
if (this.isViewInited) {
this.cdRef.detectChanges();
this.initTextarea();
}
}
})
);
this.attachmentUploads$ = this.attachmentService.attachmentUploads$;
this.isFileUploadEnabled = this.configService.isFileUploadEnabled;
this.acceptedFileTypes = this.configService.acceptedFileTypes;
this.isMultipleFileUploadEnabled =
this.configService.isMultipleFileUploadEnabled;
this.areMentionsEnabled = this.configService.areMentionsEnabled;
this.mentionAutocompleteItemTemplate =
this.configService.mentionAutocompleteItemTemplate;
this.mentionScope = this.configService.mentionScope;
}

ngAfterViewInit(): void {
this.isViewInited = true;
this.initTextarea();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export class TextareaDirective implements OnChanges {
@Output() readonly send = new EventEmitter<void>();
@Output() readonly userMentions = new EventEmitter<UserResponse[]>();
private subscriptions: Subscription[] = [];

private unpropagatedChanges: SimpleChanges[] = [];
constructor(public viewContainerRef: ViewContainerRef) {}

ngOnChanges(changes: SimpleChanges): void {
this.unpropagatedChanges.push(changes);
if (!this.componentRef) {
return;
}
Expand All @@ -56,6 +57,11 @@ export class TextareaDirective implements OnChanges {
)
);
}
this.componentRef.instance.areMentionsEnabled = this.areMentionsEnabled;
this.componentRef.instance.mentionAutocompleteItemTemplate =
this.mentionAutocompleteItemTemplate;
this.componentRef.instance.mentionScope = this.mentionScope;
this.componentRef.instance.value = this.value;
}
}
if (changes.areMentionsEnabled) {
Expand All @@ -72,7 +78,12 @@ export class TextareaDirective implements OnChanges {
this.componentRef.instance.value = this.value;
}
// ngOnChanges not called for dynamic components since we don't use template binding
let changesToPropagate = {};
this.unpropagatedChanges.forEach(
(c) => (changesToPropagate = { ...changesToPropagate, ...c })
);
// eslint-disable-next-line @angular-eslint/no-lifecycle-call
this.componentRef.instance.ngOnChanges(changes);
this.componentRef.instance.ngOnChanges(changesToPropagate);
this.unpropagatedChanges = [];
}
}

0 comments on commit 6ba9032

Please sign in to comment.