You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clear and concise generalistic APIs to paginate data within Discord. More specifically:
select menu element, which can currently only hold 25 elements, this would have 2 strategies tied to it:
[⬅️] [Select menu containing the options] [➡️] - buttons here become disabled depending on the current page (e.g. last page can't go right)
[Single select menu] - if the page is 0, show 24 options and then page front. if page is pageCount - 1, show page back and 24 elements, otherwise show page back, 23 elements and page front
Goal
Clear and concise generalistic APIs to paginate data within Discord. More specifically:
pageCount - 1
, show page back and 24 elements, otherwise show page back, 23 elements and page frontCurrent proposed API
Enum
PaginationStrategy
Buttons
SelectMenuOptions
Interface
SelectMenuPaginatorState
readonly page: number
, current pageInterface
SelectMenuPaginatorData<Strategy extends PaginationStrategy>
extendsSelectMenuPaginatorState
pageLeftButton?: Strategy extends PaginationStrategy.Buttons ? APIButton : undefined
pageRightButton?: Strategy extends PaginationStrategy.Buttons ? APIButton : undefined
selectMenu: APISelectMenu
Interface
IStore
- simple KV,Map
-like storageSelectMenuPaginatorState
readonly size: number
, some sort of getter of how many states are being keptget(key: string) -> MaybePromise<SelectMenuPaginatorState>
setPage(key: string, state: number) -> MaybePromise<void>
has(key: string) -> MaybePromise<boolean>
delete(key: string) -> MaybePromise<boolean>
, boolean value indicating if the value existed to begin withClass
SelectMenuPaginator<Strategy extends PaginationStrategy>
, whereConstructor -
new (options: SelectMenuPaginatorOptions) => SelectMenuPaginator
, whereSelectMenuPaginatorOptions
would hold the following fields:data: unknown[]
- the data one desires to paginate - this will leave on the class as an immutable property and cannot be changed for its lifetimekey: string
maxElementsPerPage?: number
- defaults to 25, cannot be lower than 1, cannot be higher than 25store: IStore
Methods
nextPage() -> Promise<SelectMenuPaginatorData>
, should throw if we're at the last pagepreviousPage() -> Promise<SelectMenuPaginatorData>
, should throw if we're at the first pagesetPage(page: number) -> Promise<SelectMenuPaginatorData>
, should throw if page is out of boundsgetData() -> Promise<SelectMenuPaginatorData>
, get current state without any mutationsdestroy() -> Promise<void>
clean-up own state fromthis.store
Closing thoughts
This will become a library under the
@chatsift
namespace if it turns out well.The text was updated successfully, but these errors were encountered: