community-platform
community-platform copied to clipboard
[QuestionListing] Sorting filter
It should be possible for someone to order the Question listings for items which based on various attributes.
Look at the implementation for the how to listing for reference.
Image as reference
Hi, I've been looking into this. Sorting needs a firestore index. Is that possible? Which fields should allow sorting?
I have already done some draft code: https://github.com/ONEARMY/community-platform/commit/526a2dfa33cf12bf79f5b072bb9edcfcb0344034
Or is it indexed somewhere else?
cool! It would have these 5 options:
- Newest (default)
- Most useful
- Most comments
- Least comments (To bring unanswered to the top)
- Latest comment (Bonus: Only if possible since it will be linked with this new PR https://github.com/ONEARMY/community-platform/pull/3007)
You can see how it works in our how-to and research modules. They already use this sorting
I'd like to propose a different approach from the research module:
- Create the fields we want to sort on the question document (usefulCount, commentCount)
- Populate them with the onWrite trigger in a function https://stackoverflow.com/a/59839989
- Create the index so we can sort/paginate directly with a firebase query
Pros:
- This will ensure the scalability as we could paginate the results.
- Would be ready for the fullstack framework migration
- Easier to sort even if we get all the items (if we really wanted to query all and filter/sort on the frontend for caching)
- Easier to understand code (the current caching and state-management mechanism isn't trivial)
Cons:
- No frontend caching, but we still could do it
:tada: This issue has been resolved in version 1.165.0 :tada:
The release is available on GitHub release
Your semantic-release bot :package::rocket: