Skip to content

Commit 256011e

Browse files
chore: fold get_footer functionality into update_states
1 parent 691e31b commit 256011e

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

modmail/utils/pagination.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,6 @@ async def interaction_check(self, interaction: Interaction) -> bool:
230230
)
231231
return False
232232

233-
def get_footer(self) -> Optional[str]:
234-
"""Returns the footer text."""
235-
if self.embed is None:
236-
self.content = self._pages[self.index]
237-
return None
238-
self.embed.description = self._pages[self.index]
239-
page_indicator = f"Page {self.index+1}/{len(self._pages)}"
240-
footer_txt = (
241-
f"{self.footer_text} ({page_indicator})" if self.footer_text is not None else page_indicator
242-
)
243-
return footer_txt
244-
245233
def update_states(self) -> None:
246234
"""
247235
Disable specific components depending on paginator page and length.
@@ -251,9 +239,18 @@ def update_states(self) -> None:
251239
if the paginator is on the last page, the jump last/move forward buttons will be disabled.
252240
"""
253241
# update the footer
254-
text = self.get_footer()
255-
if self.embed:
256-
self.embed.set_footer(text=text)
242+
if self.embed is None:
243+
self.content = self._pages[self.index]
244+
else:
245+
self.embed.description = self._pages[self.index]
246+
page_indicator = f"Page {self.index+1}/{len(self._pages)}"
247+
self.embed.set_footer(
248+
text=(
249+
f"{self.footer_text} ({page_indicator})"
250+
if self.footer_text is not None
251+
else page_indicator
252+
)
253+
)
257254

258255
# determine if the jump buttons should be enabled
259256
more_than_two_pages = len(self._pages) > 2
Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import List, Union
2-
31
import pytest
42

53
from modmail.utils.pagination import ButtonPaginator
@@ -11,29 +9,3 @@ async def test_paginator_init() -> None:
119
content = ["content"]
1210
paginator = ButtonPaginator(content, prefix="", suffix="", linesep="")
1311
assert paginator.pages == content
14-
15-
16-
@pytest.mark.asyncio
17-
@pytest.mark.parametrize(
18-
"content, footer_text",
19-
[
20-
(["5"], "Snap, crackle, pop"),
21-
(["Earthly"], "world"),
22-
("There are no plugins installed.", None),
23-
],
24-
)
25-
async def test_paginator_footer(content: Union[str, List[str]], footer_text: str) -> None:
26-
"""Test the paginator footer matches what is passed."""
27-
pag = ButtonPaginator(content, footer_text=footer_text)
28-
print("index:", pag.index)
29-
print("page len: ", len(pag.pages))
30-
assert footer_text == pag.footer_text
31-
if isinstance(content, str):
32-
content = [content]
33-
34-
if footer_text is not None:
35-
assert pag.get_footer().endswith(f"{len(content)})")
36-
assert pag.get_footer().startswith(footer_text)
37-
38-
else:
39-
assert pag.get_footer().endswith(f"{len(content)}")

0 commit comments

Comments
 (0)