Show bets where you can add a comment on contract page feed.

This commit is contained in:
James Grugett 2022-03-10 00:29:36 -06:00
parent 404f3a6b0c
commit eaa1a26af4

View File

@ -44,6 +44,10 @@ import { Avatar } from './avatar'
import { useAdmin } from '../hooks/use-admin' import { useAdmin } from '../hooks/use-admin'
import { Answer } from '../../common/answer' import { Answer } from '../../common/answer'
const canAddComment = (createdTime: number, isSelf: boolean) => {
return isSelf && Date.now() - createdTime < 60 * 60 * 1000
}
function FeedComment(props: { function FeedComment(props: {
activityItem: any activityItem: any
moreHref: string moreHref: string
@ -100,7 +104,7 @@ function FeedBet(props: { activityItem: any; feedType: FeedType }) {
const isSelf = user?.id == activityItem.userId const isSelf = user?.id == activityItem.userId
const isCreator = contract.creatorId == activityItem.userId const isCreator = contract.creatorId == activityItem.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
const canComment = isSelf && Date.now() - createdTime < 60 * 60 * 1000 const canComment = canAddComment(createdTime, isSelf)
const [comment, setComment] = useState('') const [comment, setComment] = useState('')
async function submitComment() { async function submitComment() {
@ -132,42 +136,44 @@ function FeedBet(props: { activityItem: any; feedType: FeedType }) {
</div> </div>
)} )}
</div> </div>
<div> <div className={clsx('min-w-0 flex-1 pb-1.5', !answer && 'pt-1.5')}>
<div className={clsx('min-w-0 flex-1 pb-1.5', !answer && 'pt-1.5')}> <div className="text-sm text-gray-500">
<div className="text-sm text-gray-500"> <span>
<span> {isSelf ? 'You' : isCreator ? contract.creatorName : 'A trader'}
{isSelf ? 'You' : isCreator ? contract.creatorName : 'A trader'} </span>{' '}
</span>{' '} {bought} {money}
{bought} {money} <MaybeOutcomeLabel outcome={outcome} feedType={feedType} />
<MaybeOutcomeLabel outcome={outcome} feedType={feedType} /> <Timestamp time={createdTime} />
<Timestamp time={createdTime} /> {answer && (
{canComment && ( <div className="text-neutral mt-1" style={{ fontSize: 15 }}>
// Allow user to comment in an textarea if they are the creator {answer.text}
<div className="mt-2"> </div>
<Textarea )}
value={comment} {canComment && (
onChange={(e) => setComment(e.target.value)} // Allow user to comment in an textarea if they are the creator
className="textarea textarea-bordered w-full" <div className="mt-2">
placeholder="Add a comment..." <Textarea
rows={3} value={comment}
maxLength={MAX_COMMENT_LENGTH} onChange={(e) => setComment(e.target.value)}
onKeyDown={(e) => { className="textarea textarea-bordered w-full"
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) { placeholder="Add a comment..."
submitComment() rows={3}
} maxLength={MAX_COMMENT_LENGTH}
}} onKeyDown={(e) => {
/> if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
<button submitComment()
className="btn btn-outline btn-sm mt-1" }
onClick={submitComment} }}
> />
Comment <button
</button> className="btn btn-outline btn-sm mt-1"
</div> onClick={submitComment}
)} >
</div> Comment
</button>
</div>
)}
</div> </div>
{answer && <div style={{ fontSize: 15 }}>{answer.text}</div>}
</div> </div>
</> </>
) )
@ -815,10 +821,12 @@ export function ContractFeed(props: {
if (feedType === 'multi') { if (feedType === 'multi') {
bets = bets.filter((bet) => bet.outcome === outcome) bets = bets.filter((bet) => bet.outcome === outcome)
} else if (outcomeType === 'FREE_RESPONSE') { } else if (outcomeType === 'FREE_RESPONSE') {
// Keep bets on comments or your own bets. // Keep bets on comments or your bets where you can comment.
const commentBetIds = new Set(comments.map((comment) => comment.betId)) const commentBetIds = new Set(comments.map((comment) => comment.betId))
bets = bets.filter( bets = bets.filter(
(bet) => commentBetIds.has(bet.id) || user?.id === bet.id (bet) =>
commentBetIds.has(bet.id) ||
canAddComment(bet.createdTime, user?.id === bet.userId)
) )
} }