Order comments in Firestore instead of on client

This commit is contained in:
Marshall Polaris 2022-08-30 15:01:03 -07:00
parent 5b6db12720
commit 708ea9555c
2 changed files with 13 additions and 20 deletions

View File

@ -92,17 +92,15 @@ function getCommentsOnGroupCollection(groupId: string) {
}
export async function listAllComments(contractId: string) {
const comments = await getValues<Comment>(getCommentsCollection(contractId))
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
return comments
return await getValues<Comment>(
query(getCommentsCollection(contractId), orderBy('createdTime', 'desc'))
)
}
export async function listAllCommentsOnGroup(groupId: string) {
const comments = await getValues<GroupComment>(
getCommentsOnGroupCollection(groupId)
return await getValues<GroupComment>(
query(getCommentsOnGroupCollection(groupId), orderBy('createdTime', 'desc'))
)
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
return comments
}
export function listenForCommentsOnContract(
@ -110,23 +108,21 @@ export function listenForCommentsOnContract(
setComments: (comments: ContractComment[]) => void
) {
return listenForValues<ContractComment>(
getCommentsCollection(contractId),
(comments) => {
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
setComments(comments)
}
query(getCommentsCollection(contractId), orderBy('createdTime', 'desc')),
setComments
)
}
export function listenForCommentsOnGroup(
groupId: string,
setComments: (comments: GroupComment[]) => void
) {
return listenForValues<GroupComment>(
query(
getCommentsOnGroupCollection(groupId),
(comments) => {
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
setComments(comments)
}
orderBy('createdTime', 'desc')
),
setComments
)
}

View File

@ -168,9 +168,6 @@ export function ContractPageContent(
[bets]
)
// Sort for now to see if bug is fixed.
comments.sort((c1, c2) => c1.createdTime - c2.createdTime)
const tips = useTipTxns({ contractId: contract.id })
const [showConfetti, setShowConfetti] = useState(false)