Sort folds by followers in fold tag list

This commit is contained in:
James Grugett 2022-02-01 12:47:31 -06:00
parent 7c50b55331
commit 7e15c2870b

View File

@ -7,6 +7,7 @@ import {
updateDoc, updateDoc,
where, where,
} from 'firebase/firestore' } from 'firebase/firestore'
import _ from 'lodash'
import { Fold } from '../../../common/fold' import { Fold } from '../../../common/fold'
import { Contract, contractCollection } from './contracts' import { Contract, contractCollection } from './contracts'
import { db } from './init' 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 [] if (tags.length === 0) return []
const lowercaseTags = tags.map((tag) => tag.toLowerCase()) const lowercaseTags = tags.map((tag) => tag.toLowerCase())
return getValues<Fold>( const folds = await getValues<Fold>(
// TODO: split into multiple queries if tags.length > 10. // TODO: split into multiple queries if tags.length > 10.
query( query(
foldCollection, foldCollection,
where('lowercaseTags', 'array-contains-any', lowercaseTags) where('lowercaseTags', 'array-contains-any', lowercaseTags)
) )
) )
return _.sortBy(folds, (fold) => -1 * fold.followCount)
} }