Category rendering, DB columns refined.
This commit is contained in:
@@ -1,20 +1,58 @@
|
||||
from typing import Optional
|
||||
|
||||
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from dto.categories import CategoryDTO
|
||||
|
||||
async def cart_btn(user_id: int) -> InlineKeyboardButton:
|
||||
|
||||
def cart_btn(user_id: int) -> InlineKeyboardButton:
|
||||
return InlineKeyboardButton(
|
||||
text="🛒 Корзина ()", callback_data="cart"
|
||||
) # TODO: Database integration, get cart items count
|
||||
|
||||
|
||||
def get_back_btn(
|
||||
data: str = "menu:main", text: Optional[str] = "⬅️ Назад"
|
||||
) -> InlineKeyboardButton:
|
||||
return InlineKeyboardButton(text=text, callback_data=data)
|
||||
|
||||
|
||||
async def main_menu_kb(user_id: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(text="📦 Каталог", callback_data="catalogue"),
|
||||
InlineKeyboardButton(text="📦 Каталог", callback_data="cat:root"),
|
||||
InlineKeyboardButton(text="🔍", callback_data="find"),
|
||||
],
|
||||
[await cart_btn(user_id)],
|
||||
[cart_btn(user_id)],
|
||||
]
|
||||
).as_markup()
|
||||
|
||||
|
||||
async def render_category(
|
||||
children: list[CategoryDTO],
|
||||
parent_id: Optional[int] = None,
|
||||
show_menu: bool = False,
|
||||
) -> InlineKeyboardMarkup:
|
||||
btns = [
|
||||
InlineKeyboardButton(
|
||||
text=category.name,
|
||||
callback_data=f"cat:{category.id}",
|
||||
)
|
||||
for category in children
|
||||
]
|
||||
|
||||
nav = []
|
||||
|
||||
if parent_id is not None:
|
||||
nav.append(
|
||||
InlineKeyboardButton(text="⬅️ Назад", callback_data=f"cat:{parent_id}")
|
||||
)
|
||||
|
||||
if show_menu:
|
||||
nav.append(InlineKeyboardButton(text="⬅️ Назад", callback_data="menu:main"))
|
||||
|
||||
return InlineKeyboardBuilder(
|
||||
[btns[i : i + 2] for i in range(0, len(children), 2)] + [nav],
|
||||
).as_markup()
|
||||
|
||||
Reference in New Issue
Block a user