From 7e15c2870b58254da0f73b79735243fc50168ff2 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Tue, 1 Feb 2022 12:47:31 -0600 Subject: [PATCH] Sort folds by followers in fold tag list --- web/lib/firebase/folds.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) }