Sort folds by followers in fold tag list
This commit is contained in:
parent
7c50b55331
commit
7e15c2870b
|
@ -7,6 +7,7 @@ import {
|
|||
updateDoc,
|
||||
where,
|
||||
} from 'firebase/firestore'
|
||||
import _ from 'lodash'
|
||||
import { Fold } from '../../../common/fold'
|
||||
import { Contract, contractCollection } from './contracts'
|
||||
import { db } from './init'
|
||||
|
@ -132,15 +133,17 @@ export function listenForFollow(
|
|||
})
|
||||
}
|
||||
|
||||
export function getFoldsByTags(tags: string[]) {
|
||||
export async function getFoldsByTags(tags: string[]) {
|
||||
if (tags.length === 0) return []
|
||||
|
||||
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
||||
return getValues<Fold>(
|
||||
const folds = await getValues<Fold>(
|
||||
// TODO: split into multiple queries if tags.length > 10.
|
||||
query(
|
||||
foldCollection,
|
||||
where('lowercaseTags', 'array-contains-any', lowercaseTags)
|
||||
)
|
||||
)
|
||||
|
||||
return _.sortBy(folds, (fold) => -1 * fold.followCount)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user