Allow comments to reference answers

This commit is contained in:
Ian Philips 2022-04-29 16:35:35 -06:00
parent 78997c1e45
commit 44c7c3db19
3 changed files with 9 additions and 3 deletions

View File

@ -4,6 +4,7 @@ export type Comment = {
id: string
contractId: string
betId?: string
answerOutcome?: string
userId: string
text: string

View File

@ -223,8 +223,9 @@ export function CommentInput(props: {
contract: Contract
betsByCurrentUser: Bet[]
comments: Comment[]
answerOutcome?: string
}) {
const { contract, betsByCurrentUser, comments } = props
const { contract, betsByCurrentUser, comments, answerOutcome } = props
const user = useUser()
const [comment, setComment] = useState('')
@ -233,7 +234,7 @@ export function CommentInput(props: {
if (!user) {
return await firebaseLogin()
}
await createComment(contract.id, comment, user)
await createComment(contract.id, comment, user, undefined, answerOutcome)
setComment('')
}

View File

@ -21,7 +21,8 @@ export async function createComment(
contractId: string,
text: string,
commenter: User,
betId?: string
betId?: string,
answerOutcome?: string
) {
const ref = betId
? doc(getCommentsCollection(contractId), betId)
@ -39,6 +40,9 @@ export async function createComment(
if (betId) {
comment.betId = betId
}
if (answerOutcome) {
comment.answerOutcome = answerOutcome
}
return await setDoc(ref, comment)
}