flarum / framework

Simple forum software for building great communities.
http://flarum.org/
6.27k stars 826 forks source link

Increasing the number of discussions shown per page #3861

Closed Danter3 closed 10 months ago

Danter3 commented 1 year ago

Current Behavior

Hi, I'm trying to create a super minimal Hacker News theme for Flarum and I'm running into a problem when it comes to extending the number of discussions per page in the index.

Steps to Reproduce

This problem I think should be considered a bug, I think it is a major flaw when creating themes like this or just trying to change the number of discussions, my intention is to show around 50 discussions per page in the index (currently only 20 does not even enable page scrolling and looks very weird), and I can't find a way to do this without using hacky forms with js, the current limit of 20 discussions is hard coded and also linked to the number currently used within the discussions with the posts, which doesn't make sense as it would be advisable to keep different values.

Expected Behavior

I think for something so basic there should be a simple method that allows to change the values of the discussions shown per page and separately also the posts per page within the discussions, definitely with js I have tried it seems to be achievable but I do not feel that it is the right thing to do....

Screenshots

No response

Environment

Output of php flarum info

Output of "php flarum info", run this in terminal in your Flarum directory.

Possible Solution

No response

Additional Context

No response

luceos commented 1 year ago

The max limit is set to 50 by default. But you should be able to override this for the given controller using an extender.

Reference: https://github.com/flarum/framework/blob/2ffbc44b4e8103cf1b0c95c6bbcfd0bcfa8c9197/framework/core/src/Api/Controller/AbstractSerializeController.php#L340-L346

How to extend this max limit:

https://docs.flarum.org/extend/api#extending-api-controllers


This solution solves your issue, if you need further help feel free to post on discuss at https://discuss.flarum.org

SychO9 commented 1 year ago

@luceos it's actually not possible to override the frontend side limit, which is hard coded to 20 per page in the request. As far as I can tell. So the backend one doesn't have an effect as it's just a maximum.

The relevant code is in DiscussionListState and PaginatedListState.

luceos commented 1 year ago

@luceos it's actually not possible to override the frontend side limit, which is hard coded to 20 per page in the request. As far as I can tell. So the backend one doesn't have an effect as it's just a maximum.

The relevant code is in DiscussionListState and PaginatedListState.

It would make more sense then to modify core so that only the backend restrictions apply; like carrying that value from the backend into the frontend for re-use?

Spencer-Robertson-ANU commented 11 months ago

Hi there, this sounds like an issue I can help solve, could I please be assigned? thankyou

Danter3 commented 9 months ago

I didn't see this before, @SychO9 it's great that you've taken on this task. I had created a somewhat convoluted solution and it was causing issues with the no-js view.

If I understand correctly, can this now simply be managed from the extend.php at the root?

SychO9 commented 9 months ago

@Danter3 yes. Using the ApiController::setLimit extender on the appropriate controller.

But this is a 2.0 change (that's the current active branch), so it will be a while before it's available.