Skip to content

Commit

Permalink
fix(pages): default buttons reappearing on page change (#2319)
Browse files Browse the repository at this point in the history
* fix(pages): Stop Default Buttons Reappearing On Page Change)

* chore: Update Changelog

* Update CHANGELOG.md

* fix(pages): Account for all combanations of default and custom buttons

* style(pre-commit): auto fixes from pre-commit.com hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Icebluewolf and pre-commit-ci[bot] authored Jan 24, 2024
1 parent 4fc378b commit 2f3084e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2301](https://github.com/Pycord-Development/pycord/pull/2301))
- Fixed `AttributeError` caused by `command.cog` being `MISSING`.
([#2303](https://github.com/Pycord-Development/pycord/issues/2303))
- Fixed `self.use_default_buttons` being assumed truthy by `Paginator.update`.
([#2319](https://github.com/Pycord-Development/pycord/pull/2319))

## [2.4.1] - 2023-03-20

Expand Down
32 changes: 20 additions & 12 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,18 +560,20 @@ async def update(
self.loop_pages = loop_pages if loop_pages is not None else self.loop_pages
self.custom_view: discord.ui.View = None if custom_view is None else custom_view
self.timeout: float = timeout if timeout is not None else self.timeout
self.custom_buttons = (
custom_buttons if custom_buttons is not None else self.custom_buttons
)
self.trigger_on_display = (
trigger_on_display
if trigger_on_display is not None
else self.trigger_on_display
)
if custom_buttons and not self.use_default_buttons:
self.buttons = {}
for button in custom_buttons:
self.add_button(button)
else:
self.buttons = {}
self.buttons = {}
if self.use_default_buttons:
self.add_default_buttons()
elif self.custom_buttons:
for button in self.custom_buttons:
self.add_button(button)

await self.goto_page(self.current_page, interaction=interaction)

Expand Down Expand Up @@ -679,9 +681,12 @@ async def goto_page(
self.update_buttons()
self.current_page = page_number
if self.show_indicator:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
try:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
except KeyError:
pass

page = self.pages[page_number]
page = self.get_page_content(page)
Expand Down Expand Up @@ -843,9 +848,12 @@ def update_buttons(self) -> dict:
button["object"].label = button["label"]
self.clear_items()
if self.show_indicator:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
try:
self.buttons["page_indicator"][
"object"
].label = f"{self.current_page + 1}/{self.page_count + 1}"
except KeyError:
pass
for key, button in self.buttons.items():
if key != "page_indicator":
if button["hidden"]:
Expand Down

0 comments on commit 2f3084e

Please sign in to comment.