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

Pagination#canAdvance and Pagination#canBack always true #682

Open
2 of 4 tasks
nicolube opened this issue Oct 17, 2024 · 1 comment
Open
2 of 4 tasks

Pagination#canAdvance and Pagination#canBack always true #682

nicolube opened this issue Oct 17, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@nicolube
Copy link
Contributor

nicolube commented Oct 17, 2024

Is there an existing issue for this?

  • I have searched the existing issues

🐛 Describe the bug

Hello I have an Kotlin extension function looking like this:

    @JvmStatic
    fun RenderContext.pagination(state: State<Pagination>, fallBack: ViewItems = ViewItems.MENU_PLACEHOLDER) {

        "NP".forEach { layoutSlot(it, fallBack.get()) }

        layoutSlot('N', ViewItems.NEXT_PAGE.get()).displayIf { c -> state.get(c).canAdvance() }
            .updateOnStateChange(state)
            .onClick { context ->
                val pagination = state.get(context)
                pagination.advance()
                CustomSounds.MENU_CLICK.playSound(this.player)
            }
        layoutSlot('P').displayIf { c -> state.get(c).canBack() }
            .updateOnStateChange(state)
            .onClick { context ->
                val pagination = state.get(context)
                pagination.back()
                CustomSounds.MENU_CLICK.playSound(this.player)
            }
    }

It adds next and Previous buttons to a layout, my issue is here that they are always added, no matter of there is just 1 or 50 Items in the Pennington.

This Problem only exists with all computedPagintons

✔️ Expected behavior

Well, that the items are not displayed if there is no next or previous site.

👣 Steps to Reproduce

No response

💻 Platform

  • Bukkit
  • Sponge
  • Other

⭐ Server Version

Paper version 1.21.1-122-master@4430e96 (2024-10-12T21:18:42Z) (Implementing API version 1.21.1-R0.1-SNAPSHOT)

📚 Library Version

3.0.11

✍️ Additional context

No response

@nicolube nicolube added the bug Something isn't working label Oct 17, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Inventory Framework Oct 17, 2024
@nicolube nicolube changed the title Pagination#canAdvance and Pagination#canBack allways true Pagination#canAdvance and Pagination#canBack always true Oct 17, 2024
@goncalodelima
Copy link

Do it this way until this is fixed:

render.layoutSlot('<', back)
. updateOnStateChange(paginationState)
.displayIf(() -> pagination.currentPageIndex() != 0)
.onClick(pagination::back);

render.layoutSlot('>', next)
. updateOnStateChange(paginationState)
.displayIf(() -> pagination.currentPageIndex() < pagination.lastPageIndex())
.onClick(pagination::advance);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

2 participants