diff --git a/web/lib/firebase/folds.ts b/web/lib/firebase/folds.ts index ef7090b1..8ff9a385 100644 --- a/web/lib/firebase/folds.ts +++ b/web/lib/firebase/folds.ts @@ -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( + const folds = await getValues( // TODO: split into multiple queries if tags.length > 10. query( foldCollection, where('lowercaseTags', 'array-contains-any', lowercaseTags) ) ) + + return _.sortBy(folds, (fold) => -1 * fold.followCount) }