From 37a1265a76d886fff0c1e18e1d60e56b16826525 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Thu, 21 Apr 2022 10:53:45 -0600 Subject: [PATCH] Minor fixes --- functions/src/emails.ts | 2 +- web/components/feed/feed-items.tsx | 27 +++++++++++++++++---------- web/lib/firebase/comments.ts | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/functions/src/emails.ts b/functions/src/emails.ts index a366f34e..290aaecb 100644 --- a/functions/src/emails.ts +++ b/functions/src/emails.ts @@ -211,7 +211,7 @@ export const sendNewCommentEmail = async ( comment: text, marketUrl, unsubscribeUrl, - betDescription: betDescription, + betDescription, }, { from } ) diff --git a/web/components/feed/feed-items.tsx b/web/components/feed/feed-items.tsx index e9169aaa..a91ed46c 100644 --- a/web/components/feed/feed-items.tsx +++ b/web/components/feed/feed-items.tsx @@ -46,6 +46,7 @@ import { useSaveSeenContract } from '../../hooks/use-seen-contracts' import { User } from '../../../common/user' import { Modal } from '../layout/modal' import { trackClick } from '../../lib/firebase/tracking' +import { firebaseLogin } from '../../lib/firebase/users' export function FeedItems(props: { contract: Contract @@ -191,28 +192,30 @@ export function CommentInput(props: { const user = useUser() const [comment, setComment] = useState('') - if (!user || outcomeType === 'FREE_RESPONSE') { + if (outcomeType === 'FREE_RESPONSE') { return
} let canCommentOnABet = false - bets.forEach((bet) => { + bets.some((bet) => { // make sure there is not already a comment with a matching bet id: const matchingComment = commentsByBetId[bet.id] if (matchingComment) { - return + return false } const { createdTime, userId } = bet - const canComment = CanComment(userId, createdTime, user) - if (canComment) { - canCommentOnABet = true - } + canCommentOnABet = canCommentOnBet(userId, createdTime, user) + return canCommentOnABet }) if (canCommentOnABet) return
async function submitComment() { - if (!user || !comment) return + if (!comment) return + if (!user) { + await firebaseLogin() + return + } await createComment(contract.id, comment, user) setComment('') } @@ -262,7 +265,7 @@ export function FeedBet(props: { const { id, amount, outcome, createdTime, userId } = bet const user = useUser() const isSelf = user?.id === userId - const canComment = CanComment(userId, createdTime, user) + const canComment = canCommentOnBet(userId, createdTime, user) const [comment, setComment] = useState('') async function submitComment() { @@ -447,7 +450,11 @@ export function FeedQuestion(props: { ) } -function CanComment(userId: string, createdTime: number, user?: User | null) { +function canCommentOnBet( + userId: string, + createdTime: number, + user?: User | null +) { const isSelf = user?.id === userId // You can comment if your bet was posted in the last hour return isSelf && Date.now() - createdTime < 60 * 60 * 1000 diff --git a/web/lib/firebase/comments.ts b/web/lib/firebase/comments.ts index edd5b6b7..65c86621 100644 --- a/web/lib/firebase/comments.ts +++ b/web/lib/firebase/comments.ts @@ -26,7 +26,7 @@ export async function createComment( const ref = betId ? doc(getCommentsCollection(contractId), betId) : doc(getCommentsCollection(contractId)) - let comment: Comment = { + const comment: Comment = { id: ref.id, contractId, userId: commenter.id,