2022-08-11 21:32:02 +00:00
|
|
|
import { Editor } from '@tiptap/react'
|
|
|
|
import { Contract } from 'common/contract'
|
2022-09-13 23:16:07 +00:00
|
|
|
import { SelectMarketsModal } from '../contract-select-modal'
|
2022-10-12 12:24:22 +00:00
|
|
|
import { embedContractCode } from '../share-embed-button'
|
2022-08-11 21:32:02 +00:00
|
|
|
import { insertContent } from './utils'
|
|
|
|
|
|
|
|
export function MarketModal(props: {
|
|
|
|
editor: Editor | null
|
|
|
|
open: boolean
|
|
|
|
setOpen: (open: boolean) => void
|
|
|
|
}) {
|
|
|
|
const { editor, open, setOpen } = props
|
|
|
|
|
2022-09-13 23:16:07 +00:00
|
|
|
function onSubmit(contracts: Contract[]) {
|
2022-09-01 16:47:45 +00:00
|
|
|
if (contracts.length == 1) {
|
|
|
|
insertContent(editor, embedContractCode(contracts[0]))
|
|
|
|
} else if (contracts.length > 1) {
|
2022-10-12 12:24:22 +00:00
|
|
|
insertContent(
|
|
|
|
editor,
|
|
|
|
`<grid-cards-component contractIds="${contracts.map((c) => c.id)}" />`
|
|
|
|
)
|
2022-09-01 16:47:45 +00:00
|
|
|
}
|
2022-08-11 21:32:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-09-13 23:16:07 +00:00
|
|
|
<SelectMarketsModal
|
|
|
|
title="Embed markets"
|
|
|
|
open={open}
|
|
|
|
setOpen={setOpen}
|
|
|
|
submitLabel={(len) =>
|
|
|
|
len == 1 ? 'Embed 1 question' : `Embed grid of ${len} questions`
|
|
|
|
}
|
|
|
|
onSubmit={onSubmit}
|
|
|
|
/>
|
2022-08-11 21:32:02 +00:00
|
|
|
)
|
|
|
|
}
|