Skip to content

fix: added the possibility of skipping lines for discord-embed titles #426

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

Merged
merged 6 commits into from
Jul 26, 2024

Conversation

favna
Copy link
Member

@favna favna commented Jul 26, 2024

Adding the possibility of skipping lines if you use a textarea to insert text and problems of not giving more than one space

eumarciel404 and others added 6 commits July 26, 2024 19:20
Adding the possibility of skipping lines if you use a textarea to insert text and problems of not giving more than one space
This property was making the content of the message go beyond the body of the embed
Copy link
Member Author

@favna favna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few pointers @eumarciel404, in case you make future contributions

Overall please make sure to follow the contribution guidelines: https://github.com/skyra-project/discord-components/blob/main/.github/CONTRIBUTING.md. I had to run the linter over the code which revealed some issues such as w which is too short for a variable identifier and formatting was off.

@@ -388,18 +398,35 @@ export class DiscordEmbed extends LitElement implements DiscordEmbedProps, Light
private parseTitle(title?: string) {
if (!title) return null;

const words = title.split(' ');
const el: (TemplateResult<1> | string)[] = [];
Copy link
Member Author

@favna favna Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't strongly typed, hiding a bug at the end of the function (see below)

Comment on lines +424 to 430
return el.map((wordOrHtmlTemplate) => {
if (typeof wordOrHtmlTemplate === 'string') {
return html`<span>${wordOrHtmlTemplate}</span>`;
}

return el;
return wordOrHtmlTemplate;
});
Copy link
Member Author

@favna favna Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your code you typed word (now wordOrHtmlTemplate) as string, I assume this was because it was typed as any above. This hid a bug however, because in one of the code branches, it is not a string but an HTML TemplateResult with discord-custom-emoji and in that case, it should not be wrapped with another TemplateResult holding a span. By strictly typing el this is revealed more clearly and you can add a typeof check to ensure that only raw strings get wrapped with a span.

Comment on lines +340 to +344
class="discord-embed-author-block"
>
<span class="discord-embed-author-block">${emojiParsedAuthorName}</span>
</a>`,
() => html`${emojiParsedAuthorName}`
() => html`<span class="discord-embed-author-block">${emojiParsedAuthorName}</span>`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added inline styles here. That makes it harder for end-user customizability and we try to avoid them unless strictly necessary. I moved the styles to a class.

@favna favna merged commit bc62ed5 into main Jul 26, 2024
6 checks passed
@favna favna deleted the fix/embed-title-skipping-lines branch July 26, 2024 23:33
@eumarciel404
Copy link
Contributor

Ok, sorry, I'll follow the guide next time and I really forgot some details, I'll be on the lookout for future commits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants