Minor fixes
This commit is contained in:
parent
ed139b6b2b
commit
37a1265a76
|
@ -211,7 +211,7 @@ export const sendNewCommentEmail = async (
|
||||||
comment: text,
|
comment: text,
|
||||||
marketUrl,
|
marketUrl,
|
||||||
unsubscribeUrl,
|
unsubscribeUrl,
|
||||||
betDescription: betDescription,
|
betDescription,
|
||||||
},
|
},
|
||||||
{ from }
|
{ from }
|
||||||
)
|
)
|
||||||
|
|
|
@ -46,6 +46,7 @@ import { useSaveSeenContract } from '../../hooks/use-seen-contracts'
|
||||||
import { User } from '../../../common/user'
|
import { User } from '../../../common/user'
|
||||||
import { Modal } from '../layout/modal'
|
import { Modal } from '../layout/modal'
|
||||||
import { trackClick } from '../../lib/firebase/tracking'
|
import { trackClick } from '../../lib/firebase/tracking'
|
||||||
|
import { firebaseLogin } from '../../lib/firebase/users'
|
||||||
|
|
||||||
export function FeedItems(props: {
|
export function FeedItems(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -191,28 +192,30 @@ export function CommentInput(props: {
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const [comment, setComment] = useState('')
|
const [comment, setComment] = useState('')
|
||||||
|
|
||||||
if (!user || outcomeType === 'FREE_RESPONSE') {
|
if (outcomeType === 'FREE_RESPONSE') {
|
||||||
return <div />
|
return <div />
|
||||||
}
|
}
|
||||||
|
|
||||||
let canCommentOnABet = false
|
let canCommentOnABet = false
|
||||||
bets.forEach((bet) => {
|
bets.some((bet) => {
|
||||||
// make sure there is not already a comment with a matching bet id:
|
// make sure there is not already a comment with a matching bet id:
|
||||||
const matchingComment = commentsByBetId[bet.id]
|
const matchingComment = commentsByBetId[bet.id]
|
||||||
if (matchingComment) {
|
if (matchingComment) {
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
const { createdTime, userId } = bet
|
const { createdTime, userId } = bet
|
||||||
const canComment = CanComment(userId, createdTime, user)
|
canCommentOnABet = canCommentOnBet(userId, createdTime, user)
|
||||||
if (canComment) {
|
return canCommentOnABet
|
||||||
canCommentOnABet = true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (canCommentOnABet) return <div />
|
if (canCommentOnABet) return <div />
|
||||||
|
|
||||||
async function submitComment() {
|
async function submitComment() {
|
||||||
if (!user || !comment) return
|
if (!comment) return
|
||||||
|
if (!user) {
|
||||||
|
await firebaseLogin()
|
||||||
|
return
|
||||||
|
}
|
||||||
await createComment(contract.id, comment, user)
|
await createComment(contract.id, comment, user)
|
||||||
setComment('')
|
setComment('')
|
||||||
}
|
}
|
||||||
|
@ -262,7 +265,7 @@ export function FeedBet(props: {
|
||||||
const { id, amount, outcome, createdTime, userId } = bet
|
const { id, amount, outcome, createdTime, userId } = bet
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const isSelf = user?.id === userId
|
const isSelf = user?.id === userId
|
||||||
const canComment = CanComment(userId, createdTime, user)
|
const canComment = canCommentOnBet(userId, createdTime, user)
|
||||||
|
|
||||||
const [comment, setComment] = useState('')
|
const [comment, setComment] = useState('')
|
||||||
async function submitComment() {
|
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
|
const isSelf = user?.id === userId
|
||||||
// You can comment if your bet was posted in the last hour
|
// You can comment if your bet was posted in the last hour
|
||||||
return isSelf && Date.now() - createdTime < 60 * 60 * 1000
|
return isSelf && Date.now() - createdTime < 60 * 60 * 1000
|
||||||
|
|
|
@ -26,7 +26,7 @@ export async function createComment(
|
||||||
const ref = betId
|
const ref = betId
|
||||||
? doc(getCommentsCollection(contractId), betId)
|
? doc(getCommentsCollection(contractId), betId)
|
||||||
: doc(getCommentsCollection(contractId))
|
: doc(getCommentsCollection(contractId))
|
||||||
let comment: Comment = {
|
const comment: Comment = {
|
||||||
id: ref.id,
|
id: ref.id,
|
||||||
contractId,
|
contractId,
|
||||||
userId: commenter.id,
|
userId: commenter.id,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user