refactor: extract further UI components into views

This commit is contained in:
syntaxbullet
2025-12-24 11:44:43 +01:00
parent 5c36b9be25
commit f75cc217e9
3 changed files with 33 additions and 33 deletions

View File

@@ -14,6 +14,7 @@ import { UserError } from "@/lib/errors";
import { items } from "@/db/schema";
import { ilike, isNotNull, and } from "drizzle-orm";
import { DrizzleClient } from "@/lib/DrizzleClient";
import { getShopListingMessage } from "@/modules/economy/shop.view";
export const listing = createCommand({
data: new SlashCommandBuilder()
@@ -53,22 +54,14 @@ export const listing = createCommand({
return;
}
const embed = createBaseEmbed(`Shop: ${item.name}`, item.description || "No description available.", "Green")
.addFields({ name: "Price", value: `${item.price} 🪙`, inline: true })
.setThumbnail(item.iconUrl || null)
.setImage(item.imageUrl || null)
.setFooter({ text: "Click the button below to purchase instantly." });
const buyButton = new ButtonBuilder()
.setCustomId(`shop_buy_${item.id}`)
.setLabel(`Buy for ${item.price} 🪙`)
.setStyle(ButtonStyle.Success)
.setEmoji("🛒");
const actionRow = new ActionRowBuilder<ButtonBuilder>().addComponents(buyButton);
const listingMessage = getShopListingMessage({
...item,
formattedPrice: `${item.price} 🪙`,
price: item.price
});
try {
await targetChannel.send({ embeds: [embed], components: [actionRow] });
await targetChannel.send(listingMessage);
await interaction.editReply({ content: `✅ Listing for **${item.name}** posted in ${targetChannel}.` });
} catch (error: any) {
if (error instanceof UserError) {