From 70e86155be47d4e1c02837c91108403b96c73430 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Thu, 9 Dec 2021 23:08:28 -0800 Subject: [PATCH] Sort contracts by creation time --- web/lib/firebase/contracts.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index 66ff599f..b82602d2 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -9,6 +9,7 @@ import { query, getDocs, onSnapshot, + orderBy, } from 'firebase/firestore' export type Contract = { @@ -57,7 +58,11 @@ export async function deleteContract(contractId: string) { } export async function listContracts(creatorId: string): Promise { - const q = query(contractCollection, where('creatorId', '==', creatorId)) + const q = query( + contractCollection, + where('creatorId', '==', creatorId), + orderBy('createdTime', 'desc') + ) const snapshot = await getDocs(q) const contracts: Contract[] = [] snapshot.forEach((doc) => contracts.push(doc.data() as Contract))