Show the market creator's bets in feed
This commit is contained in:
parent
b0e4f6d27a
commit
9fbed63eaf
|
@ -93,10 +93,12 @@ function Timestamp(props: { time: number }) {
|
||||||
|
|
||||||
function FeedBet(props: { activityItem: any; feedType: FeedType }) {
|
function FeedBet(props: { activityItem: any; feedType: FeedType }) {
|
||||||
const { activityItem, feedType } = props
|
const { activityItem, feedType } = props
|
||||||
const { id, contractId, amount, outcome, createdTime } = activityItem
|
const { id, contractId, amount, outcome, createdTime, contract } =
|
||||||
|
activityItem
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const isSelf = user?.id == activityItem.userId
|
const isSelf = user?.id == activityItem.userId
|
||||||
// The creator can comment if the bet was posted in the last hour
|
const isCreator = contract.creatorId == activityItem.userId
|
||||||
|
// You can comment if your bet was posted in the last hour
|
||||||
const canComment = isSelf && Date.now() - createdTime < 60 * 60 * 1000
|
const canComment = isSelf && Date.now() - createdTime < 60 * 60 * 1000
|
||||||
|
|
||||||
const [comment, setComment] = useState('')
|
const [comment, setComment] = useState('')
|
||||||
|
@ -113,6 +115,8 @@ function FeedBet(props: { activityItem: any; feedType: FeedType }) {
|
||||||
<div>
|
<div>
|
||||||
{isSelf ? (
|
{isSelf ? (
|
||||||
<Avatar avatarUrl={user?.avatarUrl} />
|
<Avatar avatarUrl={user?.avatarUrl} />
|
||||||
|
) : isCreator ? (
|
||||||
|
<Avatar avatarUrl={contract.creatorAvatarUrl} />
|
||||||
) : (
|
) : (
|
||||||
<div className="relative px-1">
|
<div className="relative px-1">
|
||||||
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
||||||
|
@ -123,7 +127,10 @@ function FeedBet(props: { activityItem: any; feedType: FeedType }) {
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0 flex-1 py-1.5">
|
<div className="min-w-0 flex-1 py-1.5">
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500">
|
||||||
<span>{isSelf ? 'You' : 'A trader'}</span> {bought} {money}
|
<span>
|
||||||
|
{isSelf ? 'You' : isCreator ? contract.creatorName : 'A trader'}
|
||||||
|
</span>{' '}
|
||||||
|
{bought} {money}
|
||||||
<MaybeOutcomeLabel outcome={outcome} feedType={feedType} />
|
<MaybeOutcomeLabel outcome={outcome} feedType={feedType} />
|
||||||
<Timestamp time={createdTime} />
|
<Timestamp time={createdTime} />
|
||||||
{canComment && (
|
{canComment && (
|
||||||
|
@ -354,9 +361,9 @@ function FeedQuestion(props: {
|
||||||
{!showDescription && (
|
{!showDescription && (
|
||||||
<SiteLink
|
<SiteLink
|
||||||
href={contractPath(contract)}
|
href={contractPath(contract)}
|
||||||
className="self-end sm:self-start text-sm relative top-4"
|
className="relative top-4 self-end text-sm sm:self-start"
|
||||||
>
|
>
|
||||||
<div className="text-gray-500 pb-1.5">See more...</div>
|
<div className="pb-1.5 text-gray-500">See more...</div>
|
||||||
</SiteLink>
|
</SiteLink>
|
||||||
)}
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
|
@ -494,7 +501,7 @@ function FeedClose(props: { contract: Contract }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function toFeedBet(bet: Bet) {
|
function toFeedBet(bet: Bet, contract: Contract) {
|
||||||
return {
|
return {
|
||||||
id: bet.id,
|
id: bet.id,
|
||||||
contractId: bet.contractId,
|
contractId: bet.contractId,
|
||||||
|
@ -504,6 +511,7 @@ function toFeedBet(bet: Bet) {
|
||||||
outcome: bet.outcome,
|
outcome: bet.outcome,
|
||||||
createdTime: bet.createdTime,
|
createdTime: bet.createdTime,
|
||||||
date: fromNow(bet.createdTime),
|
date: fromNow(bet.createdTime),
|
||||||
|
contract,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,12 +541,13 @@ const DAY_IN_MS = 24 * 60 * 60 * 1000
|
||||||
// Group together bets that are:
|
// Group together bets that are:
|
||||||
// - Within `windowMs` of the first in the group
|
// - Within `windowMs` of the first in the group
|
||||||
// - Do not have a comment
|
// - Do not have a comment
|
||||||
// - Were not created by this user
|
// - Were not created by this user or the contract creator
|
||||||
// Return a list of ActivityItems
|
// Return a list of ActivityItems
|
||||||
function groupBets(
|
function groupBets(
|
||||||
bets: Bet[],
|
bets: Bet[],
|
||||||
comments: Comment[],
|
comments: Comment[],
|
||||||
windowMs: number,
|
windowMs: number,
|
||||||
|
contract: Contract,
|
||||||
userId?: string
|
userId?: string
|
||||||
) {
|
) {
|
||||||
const commentsMap = mapCommentsByBetId(comments)
|
const commentsMap = mapCommentsByBetId(comments)
|
||||||
|
@ -548,25 +557,25 @@ function groupBets(
|
||||||
// Turn the current group into an ActivityItem
|
// Turn the current group into an ActivityItem
|
||||||
function pushGroup() {
|
function pushGroup() {
|
||||||
if (group.length == 1) {
|
if (group.length == 1) {
|
||||||
items.push(toActivityItem(group[0]))
|
items.push(toActivityItem(group[0], false))
|
||||||
} else if (group.length > 1) {
|
} else if (group.length > 1) {
|
||||||
items.push({ type: 'betgroup', bets: [...group], id: group[0].id })
|
items.push({ type: 'betgroup', bets: [...group], id: group[0].id })
|
||||||
}
|
}
|
||||||
group = []
|
group = []
|
||||||
}
|
}
|
||||||
|
|
||||||
function toActivityItem(bet: Bet) {
|
function toActivityItem(bet: Bet, isPublic: boolean) {
|
||||||
const comment = commentsMap[bet.id]
|
const comment = commentsMap[bet.id]
|
||||||
return comment ? toFeedComment(bet, comment) : toFeedBet(bet)
|
return comment ? toFeedComment(bet, comment) : toFeedBet(bet, contract)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const bet of bets) {
|
for (const bet of bets) {
|
||||||
const isCreator = userId === bet.userId
|
const isCreator = userId === bet.userId || contract.creatorId === bet.userId
|
||||||
|
|
||||||
if (commentsMap[bet.id] || isCreator) {
|
if (commentsMap[bet.id] || isCreator) {
|
||||||
pushGroup()
|
pushGroup()
|
||||||
// Create a single item for this
|
// Create a single item for this
|
||||||
items.push(toActivityItem(bet))
|
items.push(toActivityItem(bet, true))
|
||||||
} else {
|
} else {
|
||||||
if (
|
if (
|
||||||
group.length > 0 &&
|
group.length > 0 &&
|
||||||
|
@ -801,7 +810,7 @@ export function ContractFeed(props: {
|
||||||
|
|
||||||
const allItems: ActivityItem[] = [
|
const allItems: ActivityItem[] = [
|
||||||
{ type: 'start', id: '0' },
|
{ type: 'start', id: '0' },
|
||||||
...groupBets(bets, comments, groupWindow, user?.id),
|
...groupBets(bets, comments, groupWindow, contract, user?.id),
|
||||||
]
|
]
|
||||||
if (contract.closeTime && contract.closeTime <= Date.now()) {
|
if (contract.closeTime && contract.closeTime <= Date.now()) {
|
||||||
allItems.push({ type: 'close', id: `${contract.closeTime}` })
|
allItems.push({ type: 'close', id: `${contract.closeTime}` })
|
||||||
|
@ -851,7 +860,7 @@ export function ContractActivityFeed(props: {
|
||||||
|
|
||||||
const allItems: ActivityItem[] = [
|
const allItems: ActivityItem[] = [
|
||||||
{ type: 'start', id: '0' },
|
{ type: 'start', id: '0' },
|
||||||
...groupBets(bets, comments, DAY_IN_MS, user?.id),
|
...groupBets(bets, comments, DAY_IN_MS, contract, user?.id),
|
||||||
]
|
]
|
||||||
if (contract.closeTime && contract.closeTime <= Date.now()) {
|
if (contract.closeTime && contract.closeTime <= Date.now()) {
|
||||||
allItems.push({ type: 'close', id: `${contract.closeTime}` })
|
allItems.push({ type: 'close', id: `${contract.closeTime}` })
|
||||||
|
|
Loading…
Reference in New Issue
Block a user