From a2e6e2a0a2e15497f49311bb10121feffb628f80 Mon Sep 17 00:00:00 2001 From: 0xExp-po Date: Fri, 22 Nov 2024 16:15:36 +0900 Subject: [PATCH 01/19] feat: create new proposal page --- dapp/package.json | 1 + .../page/governance/GovernancePageTitle.astro | 11 + .../page/governance/NewProposalPage.astro | 13 + .../governance/NewProposalPageTitle.astro | 9 + .../page/governance/ProposalForm.tsx | 291 ++++++++++++++++++ dapp/src/pages/proposal/new.astro | 23 ++ 6 files changed, 348 insertions(+) create mode 100644 dapp/src/components/page/governance/NewProposalPage.astro create mode 100644 dapp/src/components/page/governance/NewProposalPageTitle.astro create mode 100644 dapp/src/components/page/governance/ProposalForm.tsx create mode 100644 dapp/src/pages/proposal/new.astro diff --git a/dapp/package.json b/dapp/package.json index a324df54..dc6e8b18 100644 --- a/dapp/package.json +++ b/dapp/package.json @@ -5,6 +5,7 @@ "@astrojs/tailwind": "5.1.2", "@creit.tech/sorobandomains-sdk": "^0.1.4", "@creit.tech/stellar-wallets-kit": "^1.2.5", + "@mdxeditor/editor": "^3.19.2", "@nanostores/react": "^0.8.0", "@stellar/stellar-sdk": "^13.0.0", "astro": "4.16.13", diff --git a/dapp/src/components/page/governance/GovernancePageTitle.astro b/dapp/src/components/page/governance/GovernancePageTitle.astro index 85833b88..cfda9728 100644 --- a/dapp/src/components/page/governance/GovernancePageTitle.astro +++ b/dapp/src/components/page/governance/GovernancePageTitle.astro @@ -18,6 +18,7 @@ import Topic from "../../utils/Topic.astro"; diff --git a/dapp/src/components/page/governance/NewProposalPage.astro b/dapp/src/components/page/governance/NewProposalPage.astro new file mode 100644 index 00000000..c8aa7706 --- /dev/null +++ b/dapp/src/components/page/governance/NewProposalPage.astro @@ -0,0 +1,13 @@ +--- +import ProposalForm from "./ProposalForm"; +--- + +
+
+ +
+
diff --git a/dapp/src/components/page/governance/NewProposalPageTitle.astro b/dapp/src/components/page/governance/NewProposalPageTitle.astro new file mode 100644 index 00000000..7ccfaf4c --- /dev/null +++ b/dapp/src/components/page/governance/NewProposalPageTitle.astro @@ -0,0 +1,9 @@ +--- +import Topic from "components/utils/Topic.astro"; +--- + +
+ +
diff --git a/dapp/src/components/page/governance/ProposalForm.tsx b/dapp/src/components/page/governance/ProposalForm.tsx new file mode 100644 index 00000000..06a03f04 --- /dev/null +++ b/dapp/src/components/page/governance/ProposalForm.tsx @@ -0,0 +1,291 @@ +import React from "react"; +import { useState, useEffect } from "react"; +import { + MDXEditor, + headingsPlugin, + listsPlugin, + quotePlugin, + thematicBreakPlugin, + markdownShortcutPlugin, + linkPlugin, + linkDialogPlugin, + imagePlugin, + tablePlugin, + codeBlockPlugin, + codeMirrorPlugin, + diffSourcePlugin, + frontmatterPlugin, + toolbarPlugin, + Separator, + UndoRedo, + BoldItalicUnderlineToggles, + BlockTypeSelect, + CodeToggle, + CreateLink, + DiffSourceToggleWrapper, + InsertAdmonition, + InsertImage, + InsertTable, + InsertFrontmatter, + InsertThematicBreak, + InsertCodeBlock, + ListsToggle, + type CodeBlockEditorDescriptor, + useCodeBlockEditorContext, +} from "@mdxeditor/editor"; +import "@mdxeditor/editor/style.css"; +import { capitalizeFirstLetter } from "utils/utils"; +import type { ProposalOutcome } from "types/proposal"; + +const ProposalForm: React.FC = () => { + const [mdText, setMdText] = useState(""); + const [isClient, setIsClient] = useState(false); + const [approveDescription, setApproveDescription] = useState(""); + const [rejectDescription, setRejectDescription] = useState(""); + const [cancelledDescription, setCancelledDescription] = useState(""); + const [approveXdr, setApproveXdr] = useState(""); + const [rejectXdr, setRejectXdr] = useState(""); + const [cancelledXdr, setCancelledXdr] = useState(""); + const [imageFiles, setImageFiles] = useState< + { localUrl: string; publicUrl: string; source: File }[] + >([]); + + useEffect(() => { + setIsClient(true); + }, []); + + if (!isClient) { + return null; + } + + const imageUploadHandler = async (image: File) => { + const url = URL.createObjectURL(image); + setImageFiles([ + ...imageFiles, + { localUrl: url, publicUrl: image.name, source: image }, + ]); + console.log("imageUrl:", imageFiles); + return url; + }; + + const PlainTextCodeEditorDescriptor: CodeBlockEditorDescriptor = { + match: (language, meta) => true, + priority: 0, + Editor: (props) => { + const cb = useCodeBlockEditorContext(); + return ( +
e.nativeEvent.stopImmediatePropagation()}> +