Add create market to top of fold activity. Auto-adds the primary tag of the fold.

This commit is contained in:
jahooma 2022-01-27 12:45:35 -06:00
parent 64d46b7cdd
commit 9764a03189
5 changed files with 31 additions and 12 deletions

View File

@ -12,12 +12,15 @@ export function getNewContract(
description: string,
initialProb: number,
ante: number,
closeTime: number
closeTime: number,
extraTags: string[]
) {
const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
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 contract: Contract = {

View File

@ -18,6 +18,7 @@ export const createContract = functions
initialProb: number
ante: number
closeTime: number
tags?: string[]
},
context
) => {
@ -27,7 +28,7 @@ export const createContract = functions
const creator = await getUser(userId)
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)
return { status: 'error', message: 'Missing contract attributes' }
@ -65,7 +66,8 @@ export const createContract = functions
description,
initialProb,
ante,
closeTime
closeTime,
tags ?? []
)
if (ante) await chargeUser(creator.id, ante)

View File

@ -9,6 +9,7 @@ import { ContractsGrid } from './contracts-list'
import { Contract } from '../../common/contract'
import { TagsList } from './tags-list'
import { Col } from './layout/col'
import clsx from 'clsx'
export function FeedPromo(props: { hotContracts: Contract[] }) {
const { hotContracts } = props
@ -54,8 +55,12 @@ export function FeedPromo(props: { hotContracts: Contract[] }) {
)
}
export default function FeedCreate(props: { user?: User }) {
const { user } = props
export default function FeedCreate(props: {
user?: User
tag?: string
className?: string
}) {
const { user, tag, className } = props
const [question, setQuestion] = useState('')
const placeholders = [
@ -72,7 +77,7 @@ export default function FeedCreate(props: { user?: User }) {
const placeholder = placeholders[daysSinceEpoch % placeholders.length]
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">
{user?.avatarUrl ? (
<AvatarWithIcon username={user.username} avatarUrl={user.avatarUrl} />
@ -92,13 +97,13 @@ export default function FeedCreate(props: { user?: User }) {
onClick={(e) => e.stopPropagation()}
onChange={(e) => setQuestion(e.target.value || '')}
/>
<Spacer h={4} />
<Spacer h={2} />
</div>
</div>
{/* Hide component instead of deleting, so edits to NewContract don't get lost */}
<div className={question ? '' : 'hidden'}>
<NewContract question={question} />
<NewContract question={question} tag={tag} />
</div>
{/* Show a fake "Create Market" button, which gets replaced with the NewContract one*/}

View File

@ -47,8 +47,8 @@ export default function Create() {
}
// Allow user to create a new contract
export function NewContract(props: { question: string }) {
const question = props.question
export function NewContract(props: { question: string; tag?: string }) {
const { question, tag } = props
const creator = useUser()
useEffect(() => {
@ -104,6 +104,7 @@ export function NewContract(props: { question: string }) {
initialProb,
ante,
closeTime,
tags: tag ? [tag] : [],
}).then((r) => r.data || {})
if (result.status !== 'success') {

View File

@ -28,10 +28,11 @@ import { useRouter } from 'next/router'
import clsx from 'clsx'
import { scoreCreators, scoreTraders } from '../../../lib/firebase/scoring'
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 Custom404 from '../../404'
import { FollowFoldButton } from '../../../components/follow-fold-button'
import FeedCreate from '../../../components/feed-create'
export async function getStaticProps(props: { params: { slugs: string[] } }) {
const { slugs } = props.params
@ -213,6 +214,13 @@ export default function FoldPage(props: {
{(page === 'activity' || page === 'markets') && (
<Row className={clsx(page === 'activity' ? 'gap-16' : 'gap-8')}>
<Col className="flex-1">
{user !== null && (
<FeedCreate
user={user}
tag={toCamelCase(fold.name)}
className={clsx(page !== 'activity' && 'hidden')}
/>
)}
{page === 'activity' ? (
<>
<ActivityFeed