EdJoPaTo / grammy-inline-menu

Inline Menus for Telegram made simple. Successor of telegraf-inline-menu.
MIT License
354 stars 46 forks source link

pagination buttons hide #90

Closed asvaata closed 4 years ago

asvaata commented 4 years ago

telegraf-inline-menu version = 4.0.1 telegraf version = 3.37.0

Hi, I'm trying to hide the select menu. For some reason, when you hide the pagination buttons do not hide.

editMenu.selectSubmenu('users', async (ctx) => await get_users(ctx), anotherMenu, {
    textFunc: userMenuText,
    columns: 1,
    maxRows: 2,
    hide: (ctx) => ctx.session.admin_module_hide,
    getCurrentPage: ctx => ctx.session.page,
    setPage: (ctx, page) => {
        ctx.session.page = page
    }
})

Can you help me, again? :D

EdJoPaTo commented 4 years ago

I just checked... yes, its a bug of version 4. Version 5 Beta 1 does not have this bug.

As select and selectMenu have different hide functions and the pagination hide does not have a key to offer, the fix would need to change the hide function which is a breaking change.

I think I will not fix this in version 4.

While staying with version 4 you can do the pagination manually:

async function usersOfPage(ctx) {
  // inspired by https://github.com/EdJoPaTo/telegraf-inline-menu/blob/58da393a817d2fb7fb0f8e0d32eaee45e28407cb/source/buttons/align.ts#L9-L16
  const allUsers = await […]
  const page = ctx.session.page - 1 // pagination is page 1, page 2, page 3, ... But programmers start at 0 for the slice later
  const buttonsPerPage = columns * maxRows
  const onlyThisPage = allUsers.slice(page * buttonsPerPage, (page + 1) * buttonsPerPage)
  return onlyThisPage
}

editMenu.selectSubmenu('users', usersOfPage, anotherMenu, {
  textFunc: userMenuText,
  columns: 1,
  maxRows: 2,
  hide: ctx => ctx.session.admin_module_hide
})

editMenu.pagination('userpages', {
  hide: ctx => ctx.session.admin_module_hide,
  setPage: (ctx, page) => {
    ctx.session.page = page
  },
  getCurrentPage: ctx => ctx.session.page,
  getTotalPages: ctx => allUsers.length / (columns * maxRows)
})
asvaata commented 4 years ago

oh thx, it's working for me