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 ( - - - - - - - - - +
+ + +
+
+ + + +
+
+ + + +
+
+
); 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 (
- - +
+ + +
+
+ + + +
); } @@ -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 ( - + {/* - + */}