"Complete-product-UX-improvements-with-navigation-and-category-enhancements"
This commit is contained in:
parent
7e364b2a44
commit
9714e9d37b
Binary file not shown.
@ -194,13 +194,47 @@ namespace TeleBot.Handlers
|
|||||||
var category = categories.FirstOrDefault(c => c.Id == categoryId);
|
var category = categories.FirstOrDefault(c => c.Id == categoryId);
|
||||||
var products = await _shopService.GetProductsAsync(categoryId, 1);
|
var products = await _shopService.GetProductsAsync(categoryId, 1);
|
||||||
|
|
||||||
|
// Edit the original message to show category header (bigger, more prominent)
|
||||||
|
var headerText = $"🛍️ **{category?.Name ?? "Unknown Category"} PRODUCTS**\n\n📋 Browse individual products below:";
|
||||||
|
|
||||||
await bot.EditMessageTextAsync(
|
await bot.EditMessageTextAsync(
|
||||||
message.Chat.Id,
|
message.Chat.Id,
|
||||||
message.MessageId,
|
message.MessageId,
|
||||||
MessageFormatter.FormatProductList(products, category?.Name),
|
headerText,
|
||||||
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
|
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
|
||||||
replyMarkup: MenuBuilder.ProductListMenu(products, categoryId, 1)
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send navigation message after all products
|
||||||
|
await bot.SendTextMessageAsync(
|
||||||
|
message.Chat.Id,
|
||||||
|
"🔽 *Navigation*",
|
||||||
|
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
|
||||||
|
replyMarkup: MenuBuilder.ProductNavigationMenu(categoryId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await bot.SendTextMessageAsync(
|
||||||
|
message.Chat.Id,
|
||||||
|
"No products available in this category.",
|
||||||
|
replyMarkup: MenuBuilder.BackToCategoriesMenu()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
session.State = SessionState.ViewingProducts;
|
session.State = SessionState.ViewingProducts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,6 +278,14 @@ namespace TeleBot.Handlers
|
|||||||
replyMarkup: MenuBuilder.SingleProductMenu(product.Id)
|
replyMarkup: MenuBuilder.SingleProductMenu(product.Id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Send navigation message after all products
|
||||||
|
await bot.SendTextMessageAsync(
|
||||||
|
message.Chat.Id,
|
||||||
|
"🔽 *Navigation*",
|
||||||
|
parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
|
||||||
|
replyMarkup: MenuBuilder.ProductNavigationMenu(categoryId)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,9 +28,11 @@ namespace TeleBot.UI
|
|||||||
|
|
||||||
foreach (var category in categories)
|
foreach (var category in categories)
|
||||||
{
|
{
|
||||||
|
// Add description to category button text
|
||||||
|
var categoryText = GetCategoryDisplayText(category.Name, category.Description);
|
||||||
buttons.Add(new[] {
|
buttons.Add(new[] {
|
||||||
InlineKeyboardButton.WithCallbackData(
|
InlineKeyboardButton.WithCallbackData(
|
||||||
$"📁 {category.Name}",
|
categoryText,
|
||||||
$"category:{category.Id}"
|
$"category:{category.Id}"
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@ -352,5 +354,45 @@ namespace TeleBot.UI
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InlineKeyboardMarkup ProductNavigationMenu(Guid? categoryId)
|
||||||
|
{
|
||||||
|
return new InlineKeyboardMarkup(new[]
|
||||||
|
{
|
||||||
|
new[] {
|
||||||
|
InlineKeyboardButton.WithCallbackData("⬅️ Back to Categories", "browse"),
|
||||||
|
InlineKeyboardButton.WithCallbackData("🛒 View Cart", "cart")
|
||||||
|
},
|
||||||
|
new[] {
|
||||||
|
InlineKeyboardButton.WithCallbackData("🏠 Main Menu", "menu")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetCategoryDisplayText(string categoryName, string? description)
|
||||||
|
{
|
||||||
|
var emoji = categoryName.ToLower() switch
|
||||||
|
{
|
||||||
|
var name when name.Contains("electronics") => "📱",
|
||||||
|
var name when name.Contains("clothing") || name.Contains("fashion") => "👕",
|
||||||
|
var name when name.Contains("books") || name.Contains("book") => "📚",
|
||||||
|
var name when name.Contains("home") || name.Contains("house") => "🏠",
|
||||||
|
var name when name.Contains("sports") || name.Contains("fitness") => "⚽",
|
||||||
|
var name when name.Contains("beauty") || name.Contains("cosmetics") => "💄",
|
||||||
|
var name when name.Contains("food") || name.Contains("grocery") => "🍎",
|
||||||
|
_ => "📦"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(description))
|
||||||
|
{
|
||||||
|
// Truncate description for button
|
||||||
|
var shortDesc = description.Length > 40
|
||||||
|
? description.Substring(0, 37) + "..."
|
||||||
|
: description;
|
||||||
|
return $"{emoji} {categoryName}\n{shortDesc}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"{emoji} {categoryName}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,18 +30,8 @@ namespace TeleBot.UI
|
|||||||
public static string FormatCategories(List<Category> categories)
|
public static string FormatCategories(List<Category> categories)
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.AppendLine("📁 *Product Categories*\n");
|
sb.AppendLine("🛍️ **PRODUCT CATEGORIES**\n");
|
||||||
|
sb.AppendLine("🔽 Choose a category to start shopping:");
|
||||||
foreach (var category in categories)
|
|
||||||
{
|
|
||||||
sb.AppendLine($"• *{category.Name}*");
|
|
||||||
if (!string.IsNullOrEmpty(category.Description))
|
|
||||||
{
|
|
||||||
sb.AppendLine($" _{category.Description}_");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.AppendLine("\nSelect a category to browse products:");
|
|
||||||
|
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user