Add create market to top of fold activity. Auto-adds the primary tag of the fold.
This commit is contained in:
parent
64d46b7cdd
commit
9764a03189
|
@ -12,12 +12,15 @@ export function getNewContract(
|
||||||
description: string,
|
description: string,
|
||||||
initialProb: number,
|
initialProb: number,
|
||||||
ante: number,
|
ante: number,
|
||||||
closeTime: number
|
closeTime: number,
|
||||||
|
extraTags: string[]
|
||||||
) {
|
) {
|
||||||
const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
|
const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
|
||||||
calcStartPool(initialProb, ante)
|
calcStartPool(initialProb, ante)
|
||||||
|
|
||||||
const tags = parseTags(`${question} ${description}`)
|
const tags = parseTags(
|
||||||
|
`${extraTags.map((tag) => `#${tag}`).join(' ')} ${question} ${description}`
|
||||||
|
)
|
||||||
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
||||||
|
|
||||||
const contract: Contract = {
|
const contract: Contract = {
|
||||||
|
|
|
@ -18,6 +18,7 @@ export const createContract = functions
|
||||||
initialProb: number
|
initialProb: number
|
||||||
ante: number
|
ante: number
|
||||||
closeTime: number
|
closeTime: number
|
||||||
|
tags?: string[]
|
||||||
},
|
},
|
||||||
context
|
context
|
||||||
) => {
|
) => {
|
||||||
|
@ -27,7 +28,7 @@ export const createContract = functions
|
||||||
const creator = await getUser(userId)
|
const creator = await getUser(userId)
|
||||||
if (!creator) return { status: 'error', message: 'User not found' }
|
if (!creator) return { status: 'error', message: 'User not found' }
|
||||||
|
|
||||||
const { question, description, initialProb, ante, closeTime } = data
|
const { question, description, initialProb, ante, closeTime, tags } = data
|
||||||
|
|
||||||
if (!question || !initialProb)
|
if (!question || !initialProb)
|
||||||
return { status: 'error', message: 'Missing contract attributes' }
|
return { status: 'error', message: 'Missing contract attributes' }
|
||||||
|
@ -65,7 +66,8 @@ export const createContract = functions
|
||||||
description,
|
description,
|
||||||
initialProb,
|
initialProb,
|
||||||
ante,
|
ante,
|
||||||
closeTime
|
closeTime,
|
||||||
|
tags ?? []
|
||||||
)
|
)
|
||||||
|
|
||||||
if (ante) await chargeUser(creator.id, ante)
|
if (ante) await chargeUser(creator.id, ante)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { ContractsGrid } from './contracts-list'
|
||||||
import { Contract } from '../../common/contract'
|
import { Contract } from '../../common/contract'
|
||||||
import { TagsList } from './tags-list'
|
import { TagsList } from './tags-list'
|
||||||
import { Col } from './layout/col'
|
import { Col } from './layout/col'
|
||||||
|
import clsx from 'clsx'
|
||||||
|
|
||||||
export function FeedPromo(props: { hotContracts: Contract[] }) {
|
export function FeedPromo(props: { hotContracts: Contract[] }) {
|
||||||
const { hotContracts } = props
|
const { hotContracts } = props
|
||||||
|
@ -54,8 +55,12 @@ export function FeedPromo(props: { hotContracts: Contract[] }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FeedCreate(props: { user?: User }) {
|
export default function FeedCreate(props: {
|
||||||
const { user } = props
|
user?: User
|
||||||
|
tag?: string
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const { user, tag, className } = props
|
||||||
const [question, setQuestion] = useState('')
|
const [question, setQuestion] = useState('')
|
||||||
|
|
||||||
const placeholders = [
|
const placeholders = [
|
||||||
|
@ -72,7 +77,7 @@ export default function FeedCreate(props: { user?: User }) {
|
||||||
const placeholder = placeholders[daysSinceEpoch % placeholders.length]
|
const placeholder = placeholders[daysSinceEpoch % placeholders.length]
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full bg-indigo-50 sm:rounded-md p-4">
|
<div className={clsx('w-full bg-indigo-50 sm:rounded-md p-4', className)}>
|
||||||
<div className="relative flex items-start space-x-3">
|
<div className="relative flex items-start space-x-3">
|
||||||
{user?.avatarUrl ? (
|
{user?.avatarUrl ? (
|
||||||
<AvatarWithIcon username={user.username} avatarUrl={user.avatarUrl} />
|
<AvatarWithIcon username={user.username} avatarUrl={user.avatarUrl} />
|
||||||
|
@ -92,13 +97,13 @@ export default function FeedCreate(props: { user?: User }) {
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
onChange={(e) => setQuestion(e.target.value || '')}
|
onChange={(e) => setQuestion(e.target.value || '')}
|
||||||
/>
|
/>
|
||||||
<Spacer h={4} />
|
<Spacer h={2} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Hide component instead of deleting, so edits to NewContract don't get lost */}
|
{/* Hide component instead of deleting, so edits to NewContract don't get lost */}
|
||||||
<div className={question ? '' : 'hidden'}>
|
<div className={question ? '' : 'hidden'}>
|
||||||
<NewContract question={question} />
|
<NewContract question={question} tag={tag} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Show a fake "Create Market" button, which gets replaced with the NewContract one*/}
|
{/* Show a fake "Create Market" button, which gets replaced with the NewContract one*/}
|
||||||
|
|
|
@ -47,8 +47,8 @@ export default function Create() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow user to create a new contract
|
// Allow user to create a new contract
|
||||||
export function NewContract(props: { question: string }) {
|
export function NewContract(props: { question: string; tag?: string }) {
|
||||||
const question = props.question
|
const { question, tag } = props
|
||||||
const creator = useUser()
|
const creator = useUser()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -104,6 +104,7 @@ export function NewContract(props: { question: string }) {
|
||||||
initialProb,
|
initialProb,
|
||||||
ante,
|
ante,
|
||||||
closeTime,
|
closeTime,
|
||||||
|
tags: tag ? [tag] : [],
|
||||||
}).then((r) => r.data || {})
|
}).then((r) => r.data || {})
|
||||||
|
|
||||||
if (result.status !== 'success') {
|
if (result.status !== 'success') {
|
||||||
|
|
|
@ -28,10 +28,11 @@ import { useRouter } from 'next/router'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { scoreCreators, scoreTraders } from '../../../lib/firebase/scoring'
|
import { scoreCreators, scoreTraders } from '../../../lib/firebase/scoring'
|
||||||
import { Leaderboard } from '../../../components/leaderboard'
|
import { Leaderboard } from '../../../components/leaderboard'
|
||||||
import { formatMoney } from '../../../lib/util/format'
|
import { formatMoney, toCamelCase } from '../../../lib/util/format'
|
||||||
import { EditFoldButton } from '../../../components/edit-fold-button'
|
import { EditFoldButton } from '../../../components/edit-fold-button'
|
||||||
import Custom404 from '../../404'
|
import Custom404 from '../../404'
|
||||||
import { FollowFoldButton } from '../../../components/follow-fold-button'
|
import { FollowFoldButton } from '../../../components/follow-fold-button'
|
||||||
|
import FeedCreate from '../../../components/feed-create'
|
||||||
|
|
||||||
export async function getStaticProps(props: { params: { slugs: string[] } }) {
|
export async function getStaticProps(props: { params: { slugs: string[] } }) {
|
||||||
const { slugs } = props.params
|
const { slugs } = props.params
|
||||||
|
@ -213,6 +214,13 @@ export default function FoldPage(props: {
|
||||||
{(page === 'activity' || page === 'markets') && (
|
{(page === 'activity' || page === 'markets') && (
|
||||||
<Row className={clsx(page === 'activity' ? 'gap-16' : 'gap-8')}>
|
<Row className={clsx(page === 'activity' ? 'gap-16' : 'gap-8')}>
|
||||||
<Col className="flex-1">
|
<Col className="flex-1">
|
||||||
|
{user !== null && (
|
||||||
|
<FeedCreate
|
||||||
|
user={user}
|
||||||
|
tag={toCamelCase(fold.name)}
|
||||||
|
className={clsx(page !== 'activity' && 'hidden')}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{page === 'activity' ? (
|
{page === 'activity' ? (
|
||||||
<>
|
<>
|
||||||
<ActivityFeed
|
<ActivityFeed
|
||||||
|
|
Loading…
Reference in New Issue
Block a user