From ad9684e0c750579d35a5b868343bcd4e2e240a5c Mon Sep 17 00:00:00 2001 From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com> Date: Thu, 9 Nov 2023 14:51:04 +0000 Subject: [PATCH] feat: canvas core --- apps/canvas/widget/canvas/core.jsx | 23 +++++++- apps/canvas/widget/canvas/view.jsx | 47 ++++++++------- functions/[[accountId]]/widget/[[index]].js | 2 +- public/index.html | 6 +- public/manifest.json | 4 +- public/site.webmanifest | 4 +- src/components/custom/Canvas.js | 63 ++++----------------- 7 files changed, 66 insertions(+), 83 deletions(-) diff --git a/apps/canvas/widget/canvas/core.jsx b/apps/canvas/widget/canvas/core.jsx index 8ad9b860..c1402072 100644 --- a/apps/canvas/widget/canvas/core.jsx +++ b/apps/canvas/widget/canvas/core.jsx @@ -2,9 +2,28 @@ const { initialShapes, hideUi } = props; const [hide, setHide] = useState(false); +const [trigger, setTrigger] = useState(false); +const [canvasData, setCanvasData] = useState(null); + +const getDataFromChild = () => { + setTrigger(true); // Triggers the effect in the child +}; + +const handleGetData = (data) => { + setCanvasData(data); + setTrigger(false); // Reset the trigger +}; + return ( <> - - + + {canvasData &&
Data from child: {canvasData}
} + > ); diff --git a/apps/canvas/widget/canvas/view.jsx b/apps/canvas/widget/canvas/view.jsx index be0ad806..6ae3ef7f 100644 --- a/apps/canvas/widget/canvas/view.jsx +++ b/apps/canvas/widget/canvas/view.jsx @@ -1,37 +1,42 @@ const { value } = props; -const indices = Social.index( - "post", - { - // thing - type: "thing", - path: "efiz.near/thing/draw", // this is the page?? - }, - { - order: "desc", - limit: 100, // this needs to adjust based on slider - // accountId: props.accounts, // undefined - } -); +const indices = Social.index("post", "main", { + order: "desc", + limit: 100, // this needs to adjust based on slider + // accountId: props.accounts, // undefined +}); if (!indices) { returnLoading...
; } -const drawings = indices - .map((it) => { - const path = `${it.accountId}/post/main`; - const blockHeight = it.blockHeight; +const offsetX = 100; // Horizontal offset for each text shape +const offsetY = 100; // Vertical offset for each text shape +let x = 0; // Initial X position +let y = 0; // Initial Y position + +const drawings = indices.map((it, index) => { + const path = `${it.accountId}/post/main`; + const blockHeight = it.blockHeight; + + x += offsetX; + y += offsetY; - const val = JSON.parse(Social.get(path, blockHeight) || "null"); - return val.content.shapes ? val.content.shapes : []; - }) - .flat(); + const val = JSON.parse(Social.get(path, blockHeight) || "null"); + return { + id: `shape:${path}${blockHeight}`, + type: "text", + x, + y, + props: { text: val.text, align: "start", size: "s" }, + }; +}); if (drawings.length === 0) { returnNo drawings yet!
; } +// return{JSON.stringify(drawings)}
return (