From 562e7aa1aab96e4292675ce7a1f345ecfc59eb54 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Fri, 29 Jul 2022 10:25:00 -0700 Subject: [PATCH] Embed markets using the "add markets" template --- web/components/editor.tsx | 33 +++++++-- web/components/editor/market-modal.tsx | 93 ++++++++++++++++++++++++++ web/components/share-embed-button.tsx | 8 +-- 3 files changed, 123 insertions(+), 11 deletions(-) create mode 100644 web/components/editor/market-modal.tsx diff --git a/web/components/editor.tsx b/web/components/editor.tsx index 963cea7e..bea98b36 100644 --- a/web/components/editor.tsx +++ b/web/components/editor.tsx @@ -24,12 +24,17 @@ import { useUsers } from 'web/hooks/use-users' import { mentionSuggestion } from './editor/mention-suggestion' import { DisplayMention } from './editor/mention' import Iframe from 'common/util/tiptap-iframe' -import { CodeIcon, PhotographIcon } from '@heroicons/react/solid' +import { + CodeIcon, + PhotographIcon, + PresentationChartLineIcon, +} from '@heroicons/react/solid' import { Modal } from './layout/modal' import { Col } from './layout/col' import { Button } from './button' import { Row } from './layout/row' import { Spacer } from './layout/spacer' +import { MarketModal } from './editor/market-modal' const proseClass = clsx( 'prose prose-p:my-0 prose-li:my-0 prose-blockquote:not-italic max-w-none prose-quoteless leading-relaxed', @@ -123,6 +128,7 @@ export function TextEditor(props: { }) { const { editor, upload } = props const [iframeOpen, setIframeOpen] = useState(false) + const [marketOpen, setMarketOpen] = useState(false) return ( <> @@ -157,16 +163,15 @@ export function TextEditor(props: { {/* Toolbar, with buttons for image and embeds */}
-
+
-
+
+
+
+
@@ -269,7 +290,7 @@ const useUploadMutation = (editor: Editor | null) => } ) -function RichContent(props: { content: JSONContent | string }) { +export function RichContent(props: { content: JSONContent | string }) { const { content } = props const editor = useEditor({ editorProps: { attributes: { class: proseClass } }, diff --git a/web/components/editor/market-modal.tsx b/web/components/editor/market-modal.tsx new file mode 100644 index 00000000..598e112d --- /dev/null +++ b/web/components/editor/market-modal.tsx @@ -0,0 +1,93 @@ +import { Editor } from '@tiptap/react' +import { Contract } from 'common/contract' +import { useState } from 'react' +import { Button } from '../button' +import { ContractSearch } from '../contract-search' +import { Col } from '../layout/col' +import { Modal } from '../layout/modal' +import { Row } from '../layout/row' +import { LoadingIndicator } from '../loading-indicator' +import { embedCode } from '../share-embed-button' + +export function MarketModal(props: { + editor: Editor | null + open: boolean + setOpen: (open: boolean) => void +}) { + const { editor, open, setOpen } = props + + const [contracts, setContracts] = useState([]) + const [loading, setLoading] = useState(false) + + async function addContract(contract: Contract) { + if (contracts.map((c) => c.id).includes(contract.id)) { + setContracts(contracts.filter((c) => c.id !== contract.id)) + } else setContracts([...contracts, contract]) + } + + 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() + } + setLoading(false) + setOpen(false) + setContracts([]) + } + + return ( + + + +
Embed a market
+ + + {!loading ? ( + + {contracts.length > 0 && ( + + )} + + + ) : ( + + + + )} + + + +
+ c.id), + highlightClassName: '!bg-indigo-100 border-indigo-100 border-2', + }} + /> +
+ +
+ ) +} diff --git a/web/components/share-embed-button.tsx b/web/components/share-embed-button.tsx index 1b24c689..8678299b 100644 --- a/web/components/share-embed-button.tsx +++ b/web/components/share-embed-button.tsx @@ -9,13 +9,11 @@ import { copyToClipboard } from 'web/lib/util/copy' import { ToastClipboard } from 'web/components/toast-clipboard' import { track } from 'web/lib/service/analytics' -function copyEmbedCode(contract: Contract) { +export function embedCode(contract: Contract) { const title = contract.question const src = `https://${DOMAIN}/embed${contractPath(contract)}` - const embedCode = `` - - copyToClipboard(embedCode) + return `` } export function ShareEmbedButton(props: { @@ -29,7 +27,7 @@ export function ShareEmbedButton(props: { as="div" className="relative z-10 flex-shrink-0" onMouseUp={() => { - copyEmbedCode(contract) + copyToClipboard(embedCode(contract)) track('copy embed code') }} >