Skip to content

Commit

Permalink
add managed by manifold to sweepstakes (#2893)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSaltyy authored Sep 20, 2024
1 parent b9f567f commit 695b59f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
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 @@ -168,6 +168,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 @@ -420,7 +422,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

0 comments on commit 695b59f

Please sign in to comment.