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

View File

@ -168,9 +168,6 @@ export function ContractPageContent(
[bets] [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 tips = useTipTxns({ contractId: contract.id })
const [showConfetti, setShowConfetti] = useState(false) const [showConfetti, setShowConfetti] = useState(false)