Skip to content

implement useFeed().hasSortType and useFeed().sortTypes #31

@estebanabaroa

Description

@estebanabaroa

this will be useful for when subs use custom sort types. for example:

const userSelectedSortType = 'new'
let feed = useFeed({sortType: userSelectedSortType, subplebbitAddresses})
const firstAvailableSortTypeFeed = !feed.hasSortType && useFeed({sortType: feed.sortTypes[0], subplebbitAddresses})
if (firstAvailableSortTypeFeed) {
  feed = firstAvailableSortTypeFeed
}

This might not work with multiple subplebbits that all have different sort types.

so maybe it would be better to have something like useFeed({fallbackSortTypes: ['best', 'old', 'new', '*']}) or maybe just sortTypes: []

this should also be implemented in useReplies, though I guess the user could just check what sort type exists like

const userSelectedSortType = 'new'
const comment = useComment()
const sortType = (comment.replies?.pages?.[userSelectedSortType] || comment.replies?.pageCids?.[userSelectedSortType])
  ? userSelectedSortType
  : Object.keys(comment.replies?.pages || {})[0] || Object.keys(comment.replies?.pageCids || {})[0]
const {replies} = useReplies({sortType})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions