From 404277521c9ab1d560bd7093dc1e9e27750853fc Mon Sep 17 00:00:00 2001 From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com> Date: Tue, 9 Jan 2024 00:14:29 -0500 Subject: [PATCH 1/3] preview tab --- apps/editor/widget/app.jsx | 70 ++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 21 deletions(-) diff --git a/apps/editor/widget/app.jsx b/apps/editor/widget/app.jsx index f7f0744..ff95c37 100644 --- a/apps/editor/widget/app.jsx +++ b/apps/editor/widget/app.jsx @@ -62,7 +62,7 @@ function PanelHeader({ options, onChange, value }) { }, }, }, - } + }, }) } > @@ -73,6 +73,7 @@ function PanelHeader({ options, onChange, value }) { } const [editorValue, setEditorValue] = useState(""); +const [activeTab, setActiveTab] = useState("editor"); const [editorSrc, setEditorSrc] = useState( "/*__@appAccount__*//widget/markdown.edit" @@ -90,6 +91,10 @@ function handleViewerSrcChange(value) { setViewerSrc(value); } +const handleTabClick = (tab) => { + setActiveTab(tab); +}; + function Editor({ value, setEditorValue }) { return ( - - - - - - - - - + + + + handleTabClick("editor")} + > + Edit + + + + handleTabClick("preview")} + > + Preview + + + + + + + + + + + + + + + + + ); From 0c0278e642e1602c223ddb2dbe68c609ae07acd5 Mon Sep 17 00:00:00 2001 From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com> Date: Tue, 9 Jan 2024 00:59:36 -0500 Subject: [PATCH 2/3] adapter pattern --- apps/editor/widget/adapter/sputnik-dao.jsx | 25 +++++ apps/editor/widget/app.jsx | 122 +++++++++++++-------- 2 files changed, 100 insertions(+), 47 deletions(-) diff --git a/apps/editor/widget/adapter/sputnik-dao.jsx b/apps/editor/widget/adapter/sputnik-dao.jsx index b06534d..39da5bc 100644 --- a/apps/editor/widget/adapter/sputnik-dao.jsx +++ b/apps/editor/widget/adapter/sputnik-dao.jsx @@ -57,4 +57,29 @@ const createFunctionCallProposal = ({ }); }; +const create = (v) => { + createFunctionCallProposal({ + daoId: "build.sputnik-dao.near", + receiver_id: "social.near", + method_name: "set", + args: { + data: { + "build.sputnik-dao.near": { + post: { + main: JSON.stringify(v), + }, + index: { + post: JSON.stringify({ + key: "main", + value: { + type: "md", + }, + }), + }, + }, + }, + }, + }) +}; + return { createFunctionCallProposal }; diff --git a/apps/editor/widget/app.jsx b/apps/editor/widget/app.jsx index ff95c37..c3bb6f2 100644 --- a/apps/editor/widget/app.jsx +++ b/apps/editor/widget/app.jsx @@ -33,41 +33,55 @@ const Option = styled.option``; const Button = styled.button``; -function PanelHeader({ options, onChange, value }) { +const Label = styled.label` + margin-right: 10px; +`; + +const types = [ + { + value: "/*__@appAccount__*//widget/markdown.edit", + label: "Markdown", + }, + { value: "/*__@appAccount__*//widget/code.edit", label: "Code" }, + { value: "/*__@appAccount__*//widget/canvas.edit", label: "Canvas" }, +]; + +const adapters = [ + { + value: null, + label: "Social DB", + }, + { + value: "/*__@appAccount__*//widget/adapter.sputnik-dao", + label: "Sputnik DAO", + }, +]; + +function PanelHeader({ types, handleTypeChange, handleAdapterChange, value }) { return ( - onChange(e.target.value)}> - {options && - options.map((it) => {it.label})} - - - createFunctionCallProposal({ - daoId: "build.sputnik-dao.near", - receiver_id: "social.near", - method_name: "set", - args: { - data: { - "build.sputnik-dao.near": { - post: { - main: JSON.stringify(value), - }, - index: { - post: JSON.stringify({ - key: "main", - value: { - type: "md", - }, - }), - }, - }, - }, - }, - }) - } - > - Publish - + + type: + handleTypeChange(e.target.value)}> + {types && + types.map((it) => {it.label})} + + + + adapter: + handleAdapterChange(e.target.value)}> + {adapters && + adapters.map((it) => {it.label})} + + + adapter.create({ [value]: { post: { main: editorValue } } }) + } + > + Publish + + ); } @@ -81,9 +95,22 @@ const [editorSrc, setEditorSrc] = useState( const [viewerSrc, setViewerSrc] = useState( "/*__@appAccount__*//widget/markdown.view" ); + +const socialDbAdapter = { + get: (path, blockHeight) => { + if (!path) console.log("path not provided") && null; + if (!blockHeight) blockHeight = "final"; + return Social.get(path, blockHeight); + }, + create: (v) => { + return Social.set(v, { force: true }); + }, +}; + const [selectedItem, setSelectedItem] = useState(null); +const [adapter, setAdapter] = useState(socialDbAdapter); -function handleEditorSrcChange(value) { +function handleTypeChange(value) { setEditorSrc(value); } @@ -95,6 +122,11 @@ const handleTabClick = (tab) => { setActiveTab(tab); }; +function handleAdapterChange(value) { + const adapter = value ? VM.require(value) : socialDbAdapter; + setAdapter(adapter); +} + function Editor({ value, setEditorValue }) { return ( - + {/* - + */} - + handleTabClick("editor")} @@ -153,7 +179,7 @@ return ( Edit - + handleTabClick("preview")} @@ -169,6 +195,7 @@ return ( activeTab === "editor" ? "show active" : "" }`} id="editorTab" + key={editorSrc} > @@ -179,6 +206,7 @@ return ( activeTab === "preview" ? "show active" : "" }`} id="previewTab" + key={viewerSrc} > From 188efd2fc2d3fbed64b17d4f5f0d78ef2b980129 Mon Sep 17 00:00:00 2001 From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com> Date: Tue, 9 Jan 2024 01:18:07 -0500 Subject: [PATCH 3/3] adapters --- apps/editor/widget/adapter/sputnik-dao.jsx | 2 +- apps/editor/widget/app.jsx | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/editor/widget/adapter/sputnik-dao.jsx b/apps/editor/widget/adapter/sputnik-dao.jsx index 39da5bc..2008547 100644 --- a/apps/editor/widget/adapter/sputnik-dao.jsx +++ b/apps/editor/widget/adapter/sputnik-dao.jsx @@ -82,4 +82,4 @@ const create = (v) => { }) }; -return { createFunctionCallProposal }; +return { createFunctionCallProposal, create }; diff --git a/apps/editor/widget/app.jsx b/apps/editor/widget/app.jsx index c3bb6f2..9dd9090 100644 --- a/apps/editor/widget/app.jsx +++ b/apps/editor/widget/app.jsx @@ -57,7 +57,13 @@ const adapters = [ }, ]; -function PanelHeader({ types, handleTypeChange, handleAdapterChange, value }) { +function PanelHeader({ + types, + handleTypeChange, + handleAdapterChange, + adapter, + value, +}) { return ( @@ -167,6 +173,7 @@ return ( value={editorValue} types={types} handleTypeChange={handleTypeChange} + handleAdapterChange={handleAdapterChange} adapter={adapter} />