use on push change detection with initials avatar

This commit is contained in:
Dan Percic 2021-06-30 19:36:37 +03:00 committed by Adina Țeudan
parent b1d38ba962
commit d50d165e96

View File

@ -1,4 +1,4 @@
import { Component, Input, OnChanges } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnChanges } from '@angular/core';
import { UserService } from '@services/user.service';
import { User } from '@redaction/red-ui-http';
import { TranslateService } from '@ngx-translate/core';
@ -6,7 +6,8 @@ import { TranslateService } from '@ngx-translate/core';
@Component({
selector: 'redaction-initials-avatar',
templateUrl: './initials-avatar.component.html',
styleUrls: ['./initials-avatar.component.scss']
styleUrls: ['./initials-avatar.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class InitialsAvatarComponent implements OnChanges {
@Input() userId: string;
@ -43,11 +44,11 @@ export class InitialsAvatarComponent implements OnChanges {
}
private get _isCurrentUser(): boolean {
return this.user && this._userService.userId === this.user.userId;
return this._userService.userId === this.user?.userId;
}
ngOnChanges(): void {
const isSystemUser = this.userId && this.userId.toLowerCase() === 'system';
const isSystemUser = this.userId?.toLowerCase() === 'system';
if (isSystemUser) {
this.displayName = 'System';
this.initials = 'SY';
@ -74,8 +75,7 @@ export class InitialsAvatarComponent implements OnChanges {
return this._userService
.getName(this.user)
.split(' ')
.filter(value => value !== ' ')
.filter((value, idx) => idx < 2)
.filter((value, idx) => idx < 2 && value !== ' ')
.map(str => str[0])
.join('');
}