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 id: string
contractId: string contractId: string
betId?: string betId?: string
answerOutcome?: string
userId: string userId: string
text: string text: string

View File

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

View File

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