"Improve-product-UI-with-individual-bubbles-and-fix-admin-authentication"

This commit is contained in:
sysadmin
2025-08-28 00:22:27 +01:00
parent 5748ed4a09
commit 7e364b2a44
8 changed files with 171 additions and 4 deletions

View File

@@ -219,13 +219,40 @@ namespace TeleBot.Handlers
categoryName = categories.FirstOrDefault(c => c.Id == categoryId)?.Name;
}
// Edit the original message to show category header
var headerText = !string.IsNullOrEmpty(categoryName)
? $"📦 *Products in {categoryName}*\n\nBrowse products below:"
: "📦 *All Products*\n\nBrowse products below:";
await bot.EditMessageTextAsync(
message.Chat.Id,
message.MessageId,
MessageFormatter.FormatProductList(products, categoryName),
headerText,
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.ProductListMenu(products, categoryId, page)
replyMarkup: MenuBuilder.CategoryNavigationMenu(categoryId)
);
// Send individual product bubbles
if (products.Items.Any())
{
foreach (var product in products.Items)
{
await bot.SendTextMessageAsync(
message.Chat.Id,
MessageFormatter.FormatSingleProduct(product),
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
replyMarkup: MenuBuilder.SingleProductMenu(product.Id)
);
}
}
else
{
await bot.SendTextMessageAsync(
message.Chat.Id,
"No products available in this category.",
replyMarkup: MenuBuilder.BackToCategoriesMenu()
);
}
}
private async Task HandleProductDetail(ITelegramBotClient bot, Message message, UserSession session, Guid productId)

View File

@@ -320,5 +320,37 @@ namespace TeleBot.UI
_ => "📋"
};
}
public static InlineKeyboardMarkup SingleProductMenu(Guid productId)
{
return new InlineKeyboardMarkup(new[]
{
new[] {
InlineKeyboardButton.WithCallbackData("🛒 Quick Buy", $"add:{productId}:1"),
InlineKeyboardButton.WithCallbackData("📄 Details", $"product:{productId}")
}
});
}
public static InlineKeyboardMarkup CategoryNavigationMenu(Guid? categoryId)
{
return new InlineKeyboardMarkup(new[]
{
new[] {
InlineKeyboardButton.WithCallbackData("⬅️ Back to Categories", "browse"),
InlineKeyboardButton.WithCallbackData("🏠 Main Menu", "menu")
}
});
}
public static InlineKeyboardMarkup BackToCategoriesMenu()
{
return new InlineKeyboardMarkup(new[]
{
new[] {
InlineKeyboardButton.WithCallbackData("⬅️ Back to Categories", "browse")
}
});
}
}
}

View File

@@ -89,6 +89,25 @@ namespace TeleBot.UI
return sb.ToString();
}
public static string FormatSingleProduct(Product product)
{
var sb = new StringBuilder();
sb.AppendLine($"🛍️ *{product.Name}*");
sb.AppendLine($"💰 £{product.Price:F2}");
if (!string.IsNullOrEmpty(product.Description))
{
// Truncate description for bubble format
var desc = product.Description.Length > 100
? product.Description.Substring(0, 100) + "..."
: product.Description;
sb.AppendLine($"\n_{desc}_");
}
return sb.ToString();
}
public static string FormatProductDetail(Product product)
{
var sb = new StringBuilder();