community-platform icon indicating copy to clipboard operation
community-platform copied to clipboard

[QuestionListing] Sorting filter

Open thisislawatts opened this issue 1 year ago • 4 comments

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.

thisislawatts avatar Oct 29 '23 21:10 thisislawatts

Image as reference sorting

davehakkens avatar Nov 05 '23 19:11 davehakkens

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?

mariojsnunes avatar Nov 28 '23 00:11 mariojsnunes

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

davehakkens avatar Nov 28 '23 10:11 davehakkens

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

mariojsnunes avatar Nov 29 '23 21:11 mariojsnunes

: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:

onearmy-bot avatar Mar 27 '24 11:03 onearmy-bot