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