generated from nhcarrigan/template
fix: fallback empty arrays in view embed (#4)
### Explanation The view embed was sending empty fields if the `tags` or `assignees` arrays were empty. Adding a fallback value provides a better UX. ### Issue _No response_ ### Attestations - [x] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [x] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [x] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [ ] I have pinned the dependencies to a specific patch version. ### Style - [x] I have run the linter and resolved any errors. - [x] My pull request uses an appropriate title, matching the conventional commit standards. - [x] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [x] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [x] All new and existing tests pass locally with my changes. - [x] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning Patch - My pull request introduces bug fixes ONLY. Reviewed-on: https://codeberg.org/nhcarrigan/rig-task-bot/pulls/4 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit is contained in:
+55
-22
@@ -20,6 +20,7 @@ export const view: Command = {
|
||||
setMinValue(1).
|
||||
setRequired(true);
|
||||
}),
|
||||
// eslint-disable-next-line max-lines-per-function
|
||||
run: async(bot, interaction) => {
|
||||
try {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
@@ -28,34 +29,66 @@ export const view: Command = {
|
||||
where: { numericalId },
|
||||
});
|
||||
if (!task) {
|
||||
await interaction.editReply({ content: `Task ${String(numericalId)} not found.` });
|
||||
await interaction.editReply({
|
||||
content: `Task ${String(numericalId)} not found.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (task.deleted) {
|
||||
await interaction.editReply({ content: `Task ${String(numericalId)} has been deleted.` });
|
||||
await interaction.editReply({
|
||||
content: `Task ${String(numericalId)} has been deleted.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
await interaction.editReply({ embeds: [
|
||||
{
|
||||
description: task.description,
|
||||
fields: [
|
||||
{ inline: true, name: "Priority", value: task.priority },
|
||||
{ inline: true, name: "Completed", value: task.completed
|
||||
? "Yes"
|
||||
: "No" },
|
||||
{ name: "Tag", value: task.tags.join(", ") },
|
||||
{ name: "Assignee", value: task.assignees.map((id) => {
|
||||
return `<@${id}>`;
|
||||
}).join(", ") },
|
||||
|
||||
],
|
||||
title: `Task ${String(task.numericalId)}`,
|
||||
},
|
||||
] });
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
{
|
||||
description: task.description,
|
||||
fields: [
|
||||
{ inline: true, name: "Priority", value: task.priority },
|
||||
{
|
||||
inline: true,
|
||||
name: "Completed",
|
||||
value: task.completed
|
||||
? "Yes"
|
||||
: "No",
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "Due Date",
|
||||
value: task.dueAt.toLocaleDateString("en-US"),
|
||||
},
|
||||
{
|
||||
name: "Tag",
|
||||
value: task.tags.length > 0
|
||||
? task.tags.join(", ")
|
||||
: "No tags.",
|
||||
},
|
||||
{
|
||||
name: "Assignee",
|
||||
value:
|
||||
task.assignees.length > 0
|
||||
? task.assignees.
|
||||
map((id) => {
|
||||
return `<@${id}>`;
|
||||
}).
|
||||
join(", ")
|
||||
: "No assignees.",
|
||||
},
|
||||
],
|
||||
title: `Task ${String(task.numericalId)}`,
|
||||
},
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
await errorHandler(bot, "view command", error, interaction.replied
|
||||
? interaction.editReply.bind(interaction)
|
||||
: interaction.reply.bind(interaction));
|
||||
await errorHandler(
|
||||
bot,
|
||||
"view command",
|
||||
error,
|
||||
interaction.replied
|
||||
? interaction.editReply.bind(interaction)
|
||||
: interaction.reply.bind(interaction),
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user