Insert all markets instead of just one
This commit is contained in:
parent
f74be9a491
commit
e2114f4881
|
@ -13,7 +13,7 @@ import { TextEditor, useTextEditor } from 'web/components/editor'
|
|||
import { Button } from '../button'
|
||||
import { Spacer } from '../layout/spacer'
|
||||
import { Editor, Content as ContentType } from '@tiptap/react'
|
||||
import { appendToEditor } from '../editor/utils'
|
||||
import { insertContent } from '../editor/utils'
|
||||
|
||||
export function ContractDescription(props: {
|
||||
contract: Contract
|
||||
|
@ -95,7 +95,7 @@ function RichEditContract(props: { contract: Contract; isAdmin?: boolean }) {
|
|||
size="xs"
|
||||
onClick={() => {
|
||||
setEditing(true)
|
||||
appendToEditor(editor, `<p>${editTimestamp()}</p>`)
|
||||
insertContent(editor, `<p>${editTimestamp()}</p>`)
|
||||
}}
|
||||
>
|
||||
Edit description
|
||||
|
@ -127,7 +127,7 @@ function EditQuestion(props: {
|
|||
|
||||
function joinContent(oldContent: ContentType, newContent: string) {
|
||||
const editor = new Editor({ content: oldContent, extensions: exhibitExts })
|
||||
appendToEditor(editor, newContent)
|
||||
insertContent(editor, newContent)
|
||||
return editor.getJSON()
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ import { Col } from 'web/components/layout/col'
|
|||
import { ContractGroupsList } from 'web/components/groups/contract-groups-list'
|
||||
import { SiteLink } from 'web/components/site-link'
|
||||
import { groupPath } from 'web/lib/firebase/groups'
|
||||
import { appendToEditor } from '../editor/utils'
|
||||
import { insertContent } from '../editor/utils'
|
||||
|
||||
export type ShowTime = 'resolve-date' | 'close-date'
|
||||
|
||||
|
@ -283,7 +283,8 @@ function EditableCloseDate(props: {
|
|||
const formattedCloseDate = dayjs(newCloseTime).format('YYYY-MM-DD h:mm a')
|
||||
|
||||
const editor = new Editor({ content, extensions: exhibitExts })
|
||||
appendToEditor(
|
||||
editor.commands.focus('end')
|
||||
insertContent(
|
||||
editor,
|
||||
`<br><p>Close date updated to ${formattedCloseDate}</p>`
|
||||
)
|
||||
|
|
|
@ -35,6 +35,7 @@ import { Button } from './button'
|
|||
import { Row } from './layout/row'
|
||||
import { Spacer } from './layout/spacer'
|
||||
import { MarketModal } from './editor/market-modal'
|
||||
import { insertContent } from './editor/utils'
|
||||
|
||||
const proseClass = clsx(
|
||||
'prose prose-p:my-0 prose-li:my-0 prose-blockquote:not-italic max-w-none prose-quoteless leading-relaxed',
|
||||
|
@ -105,7 +106,7 @@ export function useTextEditor(props: {
|
|||
// If the pasted content is iframe code, directly inject it
|
||||
const text = event.clipboardData?.getData('text/plain').trim() ?? ''
|
||||
if (isValidIframe(text)) {
|
||||
editor.chain().insertContent(text).run()
|
||||
insertContent(editor, text)
|
||||
return true // Prevent the code from getting pasted as text
|
||||
}
|
||||
|
||||
|
@ -238,7 +239,7 @@ function IframeModal(props: {
|
|||
disabled={!valid}
|
||||
onClick={() => {
|
||||
if (editor && valid) {
|
||||
editor.chain().insertContent(embedCode).run()
|
||||
insertContent(editor, embedCode)
|
||||
setEmbedCode('')
|
||||
setOpen(false)
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import { Modal } from '../layout/modal'
|
|||
import { Row } from '../layout/row'
|
||||
import { LoadingIndicator } from '../loading-indicator'
|
||||
import { embedCode } from '../share-embed-button'
|
||||
import { insertContent } from './utils'
|
||||
|
||||
export function MarketModal(props: {
|
||||
editor: Editor | null
|
||||
|
@ -27,14 +28,7 @@ export function MarketModal(props: {
|
|||
|
||||
async function doneAddingContracts() {
|
||||
setLoading(true)
|
||||
if (editor) {
|
||||
const e = editor.chain()
|
||||
for (const contract of contracts) {
|
||||
console.log('embedding', embedCode(contract))
|
||||
e.insertContent(embedCode(contract))
|
||||
}
|
||||
e.run()
|
||||
}
|
||||
insertContent(editor, ...contracts.map(embedCode))
|
||||
setLoading(false)
|
||||
setOpen(false)
|
||||
setContracts([])
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import { Editor, Content } from '@tiptap/react'
|
||||
|
||||
export function appendToEditor(editor: Editor | null, content: Content) {
|
||||
editor
|
||||
?.chain()
|
||||
.focus('end')
|
||||
.createParagraphNear()
|
||||
.insertContent(content)
|
||||
.run()
|
||||
export function insertContent(editor: Editor | null, ...contents: Content[]) {
|
||||
if (!editor) {
|
||||
return
|
||||
}
|
||||
|
||||
let e = editor.chain()
|
||||
for (const content of contents) {
|
||||
e = e.createParagraphNear().insertContent(content)
|
||||
}
|
||||
e.run()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user