Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add managed by manifold to sweepstakes #2893

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 35 additions & 22 deletions web/components/contract/contract-description.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,51 @@ import { JSONContent } from '@tiptap/core'
import { updateMarket } from 'web/lib/api/api'
import { toast } from 'react-hot-toast'

export function ContractDescription(props: { contract: Contract }) {
const { contract } = props
export function ContractDescription(props: {
contract: Contract
description: string | JSONContent
}) {
const { contract, description } = props

const isAdmin = useAdmin()
const user = useUser()
const isCreator = user?.id === contract.creatorId

return (
<div className="mt-2">
{isCreator || isAdmin ? (
<EditableDescription contract={contract} />
) : (
<CollapsibleContent
content={contract.description}
stateKey={`isCollapsed-contract-${contract.id}`}
hideCollapse={!user}
/>
<>
{contract.token === 'CASH' && (
<div className="text-ink-900 font-semibold">
This market is managed and resolved by Manifold.
</div>
)}
</div>
<div className="mt-6">
{isCreator || isAdmin ? (
<EditableDescription contract={contract} description={description} />
) : (
<CollapsibleContent
content={description}
stateKey={`isCollapsed-contract-${contract.id}`}
hideCollapse={!user}
/>
)}
</div>
</>
)
}

function EditableDescription(props: { contract: Contract }) {
const { contract } = props
function EditableDescription(props: {
contract: Contract
description: string | JSONContent
}) {
const { contract, description } = props
const [editing, setEditing] = useState(false)

const editor = useTextEditor({
max: MAX_DESCRIPTION_LENGTH,
defaultValue: contract.description,
defaultValue: description,
})

const emptyDescription = editor?.isEmpty
const isDescriptionEmpty = JSONEmpty(description)
const [saving, setSaving] = useState(false)

async function saveDescription() {
Expand Down Expand Up @@ -80,9 +93,9 @@ function EditableDescription(props: { contract: Contract }) {
</>
) : (
<>
{!emptyDescription && (
{!isDescriptionEmpty && (
<CollapsibleContent
content={contract.description}
content={description}
stateKey={`isCollapsed-contract-${contract.id}`}
/>
)}
Expand All @@ -95,7 +108,7 @@ function EditableDescription(props: { contract: Contract }) {
editor?.commands.focus('end')
}}
>
{emptyDescription ? (
{isDescriptionEmpty ? (
<>
<PlusIcon className="mr-1 inline h-4 w-4" /> Add description
</>
Expand All @@ -113,12 +126,12 @@ function EditableDescription(props: { contract: Contract }) {
export function JSONEmpty(text: string | JSONContent) {
if (!text) return true
if (typeof text === 'string') {
return text === ''
return text.trim() === ''
} else if ('content' in text) {
return !(
!!text.content &&
text.content &&
text.content.length > 0 &&
(!!text.content[0].content || !!text.content[0].attrs)
(text.content[0].content || text.content[0].attrs)
)
}
return true
Expand Down
7 changes: 6 additions & 1 deletion web/components/contract/twomba-contract-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ export function TwombaContractPageContent(props: ContractParams) {
liveContract
const { coverImageUrl } = livePlayContract

const description = livePlayContract.description

const isAdmin = useAdmin()
const isMod = useTrusted()
const isCreator = creatorId === user?.id
Expand Down Expand Up @@ -414,7 +416,10 @@ export function TwombaContractPageContent(props: ContractParams) {
userHasBet={!!contractMetrics}
hasReviewed={!!userHasReviewed}
/>
<ContractDescription contract={livePlayContract} />
<ContractDescription
contract={liveContract}
description={description}
/>
<Row className="items-center gap-2">
<MarketTopics
contract={props.contract}
Expand Down
Loading