feat: pagination hints
This commit is contained in:
@@ -141,6 +141,8 @@ def render_products(
|
||||
columns: int = 2,
|
||||
is_admin: bool = False,
|
||||
cat_id: int | None = None,
|
||||
page: int = 0,
|
||||
total_pages: int | None = None,
|
||||
) -> InlineKeyboardMarkup:
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
@@ -166,7 +168,10 @@ def render_products(
|
||||
nav_buttons = []
|
||||
if prev_cb:
|
||||
nav_buttons.append(InlineKeyboardButton(text="◀️", callback_data=prev_cb))
|
||||
nav_buttons.append(InlineKeyboardButton(text="🔍", callback_data="find"))
|
||||
page_text = (
|
||||
f"{page + 1}/{total_pages}" if total_pages is not None else f"{page + 1}"
|
||||
)
|
||||
nav_buttons.append(InlineKeyboardButton(text=page_text, callback_data="..."))
|
||||
if next_cb:
|
||||
nav_buttons.append(InlineKeyboardButton(text="▶️", callback_data=next_cb))
|
||||
|
||||
@@ -187,6 +192,7 @@ def render_catalogue(view: CatalogueView, *, is_admin: bool):
|
||||
cat_id=view.category,
|
||||
)
|
||||
if view.view_type == CatalogueType.PRODUCTS:
|
||||
total_pages = (view.total + PAGE_SIZE - 1) // PAGE_SIZE if view.total else None
|
||||
return render_products(
|
||||
products=view.products[:PAGE_SIZE], # type: ignore
|
||||
product_cb_factory=lambda p: f"product:{p.id}",
|
||||
@@ -195,6 +201,8 @@ def render_catalogue(view: CatalogueView, *, is_admin: bool):
|
||||
next_cb=(f"products:{view.category}:{view.page + 1}" if view.has_next else None),
|
||||
is_admin=is_admin,
|
||||
cat_id=view.category,
|
||||
page=view.page,
|
||||
total_pages=total_pages,
|
||||
)
|
||||
|
||||
return get_back_to_catalogue(
|
||||
|
||||
Reference in New Issue
Block a user