Skip to content

Commit 8e215f4

Browse files
committed
fix: revert empty avatar placeholder #464
1 parent 046de8c commit 8e215f4

File tree

2 files changed

+9
-76
lines changed

2 files changed

+9
-76
lines changed

projects/stream-chat-angular/src/lib/avatar-placeholder/avatar-placeholder.component.html

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,9 @@
2222
[showOnlineIndicator]="showOnlineIndicator"
2323
></stream-avatar>
2424
</ng-template>
25-
<ng-container *ngIf="isVisible; else emptyPlaceholder">
26-
<ng-container
27-
*ngTemplateOutlet="
28-
(customTemplatesService.avatarTemplate$ | async) || defaultAvatar;
29-
context: context
30-
"
31-
></ng-container>
32-
</ng-container>
33-
<ng-template #emptyPlaceholder>
34-
<div
35-
class="str-chat__avatar"
36-
[ngStyle]="{
37-
width: 'calc(var(--str-chat__spacing-px, 1px) * ' + size + ')',
38-
height: 'calc(var(--str-chat__spacing-px, 1px) * ' + size + ')'
39-
}"
40-
></div>
41-
</ng-template>
25+
<ng-container
26+
*ngTemplateOutlet="
27+
(customTemplatesService.avatarTemplate$ | async) || defaultAvatar;
28+
context: context
29+
"
30+
></ng-container>
Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
import {
2-
AfterViewInit,
3-
ChangeDetectorRef,
4-
Component,
5-
ElementRef,
6-
Input,
7-
OnChanges,
8-
OnDestroy,
9-
} from '@angular/core';
1+
import { Component, Input, OnChanges } from '@angular/core';
102
import { Channel, User } from 'stream-chat';
113
import { CustomTemplatesService } from '../custom-templates.service';
124
import {
@@ -15,7 +7,6 @@ import {
157
AvatarType,
168
DefaultStreamChatGenerics,
179
} from '../types';
18-
import { ThemeService } from '../theme.service';
1910

2011
/**
2112
* The `AvatarPlaceholder` component displays the [default avatar](./AvatarComponent.mdx) unless a [custom template](../services/CustomTemplatesService.mdx) is provided. This component is used by the SDK internally, you likely won't need to use it.
@@ -25,9 +16,7 @@ import { ThemeService } from '../theme.service';
2516
templateUrl: './avatar-placeholder.component.html',
2617
styles: [],
2718
})
28-
export class AvatarPlaceholderComponent
29-
implements OnChanges, AfterViewInit, OnDestroy
30-
{
19+
export class AvatarPlaceholderComponent implements OnChanges {
3120
/**
3221
* An optional name of the image, used for fallback image or image title (if `imageUrl` is provided)
3322
*/
@@ -77,37 +66,7 @@ export class AvatarPlaceholderComponent
7766
initialsType: undefined,
7867
showOnlineIndicator: undefined,
7968
};
80-
isVisible = true;
81-
private mutationObserver?: MutationObserver;
82-
constructor(
83-
public customTemplatesService: CustomTemplatesService,
84-
private hostElement: ElementRef<HTMLElement>,
85-
private cdRef: ChangeDetectorRef,
86-
private themeService: ThemeService
87-
) {}
88-
89-
ngAfterViewInit(): void {
90-
const elementToObserve =
91-
this.hostElement.nativeElement.parentElement?.parentElement
92-
?.parentElement;
93-
if (
94-
this.location !== 'message-sender' ||
95-
!elementToObserve ||
96-
!elementToObserve.classList.contains('str-chat__li') ||
97-
this.themeService.themeVersion === '1'
98-
) {
99-
this.isVisible = true;
100-
this.cdRef.detectChanges();
101-
return;
102-
}
103-
this.checkIfVisible();
104-
this.mutationObserver = new MutationObserver(() => {
105-
this.checkIfVisible();
106-
});
107-
this.mutationObserver.observe(elementToObserve, {
108-
attributeFilter: ['class'],
109-
});
110-
}
69+
constructor(public customTemplatesService: CustomTemplatesService) {}
11170

11271
ngOnChanges(): void {
11372
this.context = {
@@ -122,19 +81,4 @@ export class AvatarPlaceholderComponent
12281
showOnlineIndicator: this.showOnlineIndicator,
12382
};
12483
}
125-
126-
ngOnDestroy(): void {
127-
this.mutationObserver?.disconnect();
128-
}
129-
130-
private checkIfVisible() {
131-
const isVisible =
132-
getComputedStyle(this.hostElement.nativeElement).getPropertyValue(
133-
'visibility'
134-
) === 'visible';
135-
if (isVisible !== this.isVisible) {
136-
this.isVisible = isVisible;
137-
this.cdRef.detectChanges();
138-
}
139-
}
14084
}

0 commit comments

Comments
 (0)