From 44c7c3db19c732c0df3e78e1366b6c9133c6b4bc Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Fri, 29 Apr 2022 16:35:35 -0600 Subject: [PATCH] Allow comments to reference answers --- common/comment.ts | 1 + web/components/feed/feed-items.tsx | 5 +++-- web/lib/firebase/comments.ts | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/common/comment.ts b/common/comment.ts index 5daeb37e..15cfbcb5 100644 --- a/common/comment.ts +++ b/common/comment.ts @@ -4,6 +4,7 @@ export type Comment = { id: string contractId: string betId?: string + answerOutcome?: string userId: string text: string diff --git a/web/components/feed/feed-items.tsx b/web/components/feed/feed-items.tsx index 584907d9..402bdf6e 100644 --- a/web/components/feed/feed-items.tsx +++ b/web/components/feed/feed-items.tsx @@ -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('') } diff --git a/web/lib/firebase/comments.ts b/web/lib/firebase/comments.ts index 65c86621..381269d2 100644 --- a/web/lib/firebase/comments.ts +++ b/web/lib/firebase/comments.ts @@ -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) }