Fixed type hints, added cart item counter on main
This commit is contained in:
@@ -7,10 +7,10 @@ from db.models import Category
|
||||
from db.models.products import Product
|
||||
|
||||
|
||||
def cart_btn(user_id: int) -> InlineKeyboardButton:
|
||||
def cart_btn(cart_items: int) -> InlineKeyboardButton:
|
||||
return InlineKeyboardButton(
|
||||
text="🛒 Корзина ()", callback_data="cart"
|
||||
) # TODO: Database integration, get cart items count
|
||||
text=f"🛒 Корзина ({cart_items})", callback_data="cart"
|
||||
)
|
||||
|
||||
|
||||
def get_back_to_catalogue(
|
||||
@@ -21,14 +21,14 @@ def get_back_to_catalogue(
|
||||
).as_markup()
|
||||
|
||||
|
||||
def main_menu_kb(user_id: int) -> InlineKeyboardMarkup:
|
||||
def main_menu_kb(cart_items: int) -> InlineKeyboardMarkup:
|
||||
return InlineKeyboardBuilder(
|
||||
[
|
||||
[
|
||||
InlineKeyboardButton(text="📦 Каталог", callback_data="cat:root"),
|
||||
InlineKeyboardButton(text="🔍", callback_data="find"),
|
||||
],
|
||||
[cart_btn(user_id)],
|
||||
[cart_btn(cart_items)],
|
||||
]
|
||||
).as_markup()
|
||||
|
||||
@@ -71,7 +71,7 @@ def render_products(
|
||||
show_next: Optional[bool] = False,
|
||||
) -> InlineKeyboardMarkup:
|
||||
btns = [
|
||||
[InlineKeyboardButton(text=product.name, callback_data=f"product:{product.id}")]
|
||||
InlineKeyboardButton(text=product.name, callback_data=f"product:{product.id}")
|
||||
for product in products
|
||||
]
|
||||
|
||||
@@ -102,7 +102,7 @@ def render_products(
|
||||
)
|
||||
]
|
||||
]
|
||||
+ btns
|
||||
+ [btns[i : i + 2] for i in range(0, len(products), 2)]
|
||||
+ [nav]
|
||||
).as_markup()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user