-
-
Notifications
You must be signed in to change notification settings - Fork 49
Add a way to fallback to a different image for avatars and image attachments #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For starters this is the proper code for Lit element. I strongly recommend you use a proper editor when writing code such as VSCode because there were TypeScript errors in your code before.
As for testing it with React and other frameworks, that's on you as the contributor to do really. You can leverage https://github.com/skyra-project/discord-components-implementations with Yarn Linking to do so. If anything you could at least provide sample React code that I can use for testing since this requires the error case to be triggered and I do not know what edge case you're facing that does so. That said, I suspect it won't work and this has to be followed instead: https://lit.dev/docs/components/lifecycle/#errors-in-the-update-cycle
@property({ attribute: false }) | ||
public onAvatarError?: (imgEl: HTMLImageElement) => void; | ||
|
||
private handleAvatarError(event: Event): void { | ||
if (!this.onAvatarError) return; | ||
const img = event.currentTarget as HTMLImageElement; | ||
this.onAvatarError(img); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@property({ attribute: false }) | |
public onAvatarError?: (imgEl: HTMLImageElement) => void; | |
private handleAvatarError(event: Event): void { | |
if (!this.onAvatarError) return; | |
const img = event.currentTarget as HTMLImageElement; | |
this.onAvatarError(img); | |
} | |
@property({ attribute: false }) | |
public accessor onAvatarError: (imgEl: HTMLImageElement) => void; | |
private handleAvatarError(event: Event): void { | |
this.onAvatarError?.(event.currentTarget as HTMLImageElement); | |
} |
@property({ attribute: false }) | ||
public onImageError?: (imgEl: HTMLImageElement) => void; | ||
|
||
private handleImageError(event: Event): void { | ||
if (!this.onImageError) return; | ||
const img = event.currentTarget as HTMLImageElement; | ||
this.onImageError(img); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@property({ attribute: false }) | |
public onImageError?: (imgEl: HTMLImageElement) => void; | |
private handleImageError(event: Event): void { | |
if (!this.onImageError) return; | |
const img = event.currentTarget as HTMLImageElement; | |
this.onImageError(img); | |
} | |
@property({ attribute: false }) | |
public accessor onImageError: (imgEl: HTMLImageElement) => void; | |
private handleImageError(event: Event): void { | |
this.onImageError?.(event.currentTarget as HTMLImageElement); | |
} |
@property({ attribute: false }) | ||
public onAvatarError?: (imgEl: HTMLImageElement) => void; | ||
|
||
private handleAvatarError(event: Event): void { | ||
if (!this.onAvatarError) return; | ||
const img = event.currentTarget as HTMLImageElement; | ||
this.onAvatarError(img); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@property({ attribute: false }) | |
public onAvatarError?: (imgEl: HTMLImageElement) => void; | |
private handleAvatarError(event: Event): void { | |
if (!this.onAvatarError) return; | |
const img = event.currentTarget as HTMLImageElement; | |
this.onAvatarError(img); | |
} | |
@property({ attribute: false }) | |
public accessor onAvatarError: (imgEl: HTMLImageElement) => void; | |
private handleAvatarError(event: Event): void { | |
this.onAvatarError?.(event.currentTarget as HTMLImageElement); | |
} |
@property({ attribute: false }) | ||
public onAvatarError?: (imgEl: HTMLImageElement) => void; | ||
|
||
private handleAvatarError(event: Event): void { | ||
if (!this.onAvatarError) return; | ||
const img = event.currentTarget as HTMLImageElement; | ||
this.onAvatarError(img); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@property({ attribute: false }) | |
public onAvatarError?: (imgEl: HTMLImageElement) => void; | |
private handleAvatarError(event: Event): void { | |
if (!this.onAvatarError) return; | |
const img = event.currentTarget as HTMLImageElement; | |
this.onAvatarError(img); | |
} | |
@property({ attribute: false }) | |
public accessor onAvatarError: (imgEl: HTMLImageElement) => void; | |
private handleAvatarError(event: Event): void { | |
this.onAvatarError?.(event.currentTarget as HTMLImageElement); | |
} |
this.compactMode, | ||
() => html`<div class="discord-reply-badge">${CommandIcon()}</div>`, | ||
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" />` | ||
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />` | |
() => | |
html`<img | |
class="discord-replied-message-avatar" | |
src="${ifDefined(profile.avatar)}" | |
alt="${ifDefined(profile.author)}" | |
@error=${this.handleAvatarError} | |
/>` |
() => | ||
html`<div class="discord-author-avatar"> | ||
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" /> | ||
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} /> | |
<img src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} /> |
this.compactMode || this.deleted, | ||
() => html`<div class="discord-reply-badge">${ReplyIcon()}</div>`, | ||
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" />` | ||
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
() => html`<img class="discord-replied-message-avatar" src="${ifDefined(profile.avatar)}" alt="${ifDefined(profile.author)}" @error=${this.handleAvatarError} />` | |
() => | |
html`<img | |
class="discord-replied-message-avatar" | |
src="${ifDefined(profile.avatar)}" | |
alt="${ifDefined(profile.author)}" | |
@error=${this.handleAvatarError} | |
/>` |
Please check if I've done this correctly and if it will work properly for react and other frameworks.