-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from j4asper/3-refactor-to-get-rid-of-sendiniti…
…alresponseasync Refactor to get rid of sendinitialresponseasync
- Loading branch information
Showing
2 changed files
with
119 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using DSharpPlus.BetterPagination.Helpers; | ||
using DSharpPlus.Entities; | ||
using DSharpPlus.Interactivity; | ||
|
||
namespace DSharpPlus.BetterPagination.Handlers; | ||
|
||
internal class PaginationHandler | ||
{ | ||
internal DiscordButtonComponent BackButton => ButtonHelpers.CreateBackButton(_backButtonId, _currentPageNumber); | ||
internal DiscordButtonComponent PageLabel => ButtonHelpers.CreatePageLabel(nameof(PageLabel), _currentPageNumber, PageCount); | ||
internal DiscordButtonComponent ForwardButton => ButtonHelpers.CreateForwardButton(_forwardButtonId, _currentPageNumber, PageCount); | ||
|
||
private int PageCount => _pages.Count; | ||
|
||
private int _currentPageNumber = 1; | ||
private readonly IReadOnlyList<Page> _pages; | ||
private readonly string _backButtonId; | ||
private readonly string _forwardButtonId; | ||
|
||
public PaginationHandler(IReadOnlyList<Page> pages) | ||
{ | ||
_pages = pages; | ||
_backButtonId = Guid.NewGuid().ToString(); | ||
_forwardButtonId = Guid.NewGuid().ToString(); | ||
} | ||
|
||
|
||
internal Page GetCurrentPage() => _pages[_currentPageNumber - 1]; | ||
|
||
internal Page GetNextPage() | ||
{ | ||
_currentPageNumber++; | ||
|
||
return GetCurrentPage(); | ||
} | ||
|
||
internal Page GetPreviousPage() | ||
{ | ||
_currentPageNumber--; | ||
|
||
return GetCurrentPage(); | ||
} | ||
|
||
internal IReadOnlyList<DiscordButtonComponent> GetPaginationButtons() => [BackButton, PageLabel, ForwardButton]; | ||
} |