mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
Add and remove opposing event listeners
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
5f1346568d
commit
8b6ff533e8
@ -44,7 +44,7 @@ export class AvatarView extends BaseUpdateView {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setAvatarError() {
|
_setAvatarError() {
|
||||||
this._avatarError = true;
|
this._avatarError = true;
|
||||||
this.update(this.value);
|
this.update(this.value);
|
||||||
}
|
}
|
||||||
@ -57,6 +57,20 @@ export class AvatarView extends BaseUpdateView {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_addListenersToAvatar(image) {
|
||||||
|
const handleAvatarError = (e) => {
|
||||||
|
const image = e.target;
|
||||||
|
image.removeEventListener("load", removeErrorHandler);
|
||||||
|
this._setAvatarError();
|
||||||
|
};
|
||||||
|
const removeErrorHandler = (e) => {
|
||||||
|
const image = e.target;
|
||||||
|
image.removeEventListener("error", handleAvatarError);
|
||||||
|
};
|
||||||
|
image?.addEventListener("error", handleAvatarError);
|
||||||
|
image?.addEventListener("load", removeErrorHandler);
|
||||||
|
}
|
||||||
|
|
||||||
_avatarLetterChanged() {
|
_avatarLetterChanged() {
|
||||||
if (this.value.avatarLetter !== this._avatarLetter) {
|
if (this.value.avatarLetter !== this._avatarLetter) {
|
||||||
this._avatarLetter = this.value.avatarLetter;
|
this._avatarLetter = this.value.avatarLetter;
|
||||||
@ -71,7 +85,7 @@ export class AvatarView extends BaseUpdateView {
|
|||||||
this._avatarTitleChanged();
|
this._avatarTitleChanged();
|
||||||
this._root = renderStaticAvatar(this.value, this._size);
|
this._root = renderStaticAvatar(this.value, this._size);
|
||||||
const image = this._root.firstChild;
|
const image = this._root.firstChild;
|
||||||
image?.addEventListener("error", () => this.setAvatarError());
|
this._addListenersToAvatar(image);
|
||||||
// takes care of update being called when needed
|
// takes care of update being called when needed
|
||||||
super.mount(options);
|
super.mount(options);
|
||||||
return this._root;
|
return this._root;
|
||||||
|
Loading…
Reference in New Issue
Block a user