Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Pagination of data within Discord #3

Closed
didinele opened this issue Jun 5, 2022 · 0 comments · Fixed by #4
Closed

RFC: Pagination of data within Discord #3

didinele opened this issue Jun 5, 2022 · 0 comments · Fixed by #4

Comments

@didinele
Copy link
Member

didinele commented Jun 5, 2022

Goal

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:
    1. [⬅️] [Select menu containing the options] [➡️] - buttons here become disabled depending on the current page (e.g. last page can't go right)
    2. [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

Current proposed API

Enum PaginationStrategy

  • Buttons
  • SelectMenuOptions

Interface SelectMenuPaginatorState

  • readonly page: number, current page

Interface SelectMenuPaginatorData<Strategy extends PaginationStrategy> extends SelectMenuPaginatorState

  • warning: pseudo-code ahead
  • pageLeftButton?: Strategy extends PaginationStrategy.Buttons ? APIButton : undefined
  • pageRightButton?: Strategy extends PaginationStrategy.Buttons ? APIButton : undefined
  • selectMenu: APISelectMenu

Interface IStore - simple KV, Map-like storage

  • keys will be the message ID the paginator is bound to
  • values will be SelectMenuPaginatorState
  • readonly size: number, some sort of getter of how many states are being kept
  • get(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 with

Class SelectMenuPaginator<Strategy extends PaginationStrategy>, where

Constructor - new (options: SelectMenuPaginatorOptions) => SelectMenuPaginator, where SelectMenuPaginatorOptions 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 lifetime
  • key: string
  • maxElementsPerPage?: number - defaults to 25, cannot be lower than 1, cannot be higher than 25
  • store: IStore

Methods

  • nextPage() -> Promise<SelectMenuPaginatorData>, should throw if we're at the last page
  • previousPage() -> Promise<SelectMenuPaginatorData>, should throw if we're at the first page
  • setPage(page: number) -> Promise<SelectMenuPaginatorData>, should throw if page is out of bounds
  • getData() -> Promise<SelectMenuPaginatorData>, get current state without any mutations
  • destroy() -> Promise<void> clean-up own state from this.store

Closing thoughts

This will become a library under the @chatsift namespace if it turns out well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants