From 1c6875b85d227d192fa9618ceb186730f935946d Mon Sep 17 00:00:00 2001 From: AykutSarac Date: Tue, 27 Sep 2022 22:05:56 +0300 Subject: [PATCH] update widget structure --- src/containers/Home/index.tsx | 7 ++++--- src/containers/Modals/ShareModal/index.tsx | 22 +++++++++++--------- src/pages/Widget/index.tsx | 24 +++++++++++----------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/containers/Home/index.tsx b/src/containers/Home/index.tsx index ceb7474..04c62df 100644 --- a/src/containers/Home/index.tsx +++ b/src/containers/Home/index.tsx @@ -176,9 +176,10 @@ const EmbedSection = () => ( visitors, blog readers or anybody else! -
- -
+ ); diff --git a/src/containers/Modals/ShareModal/index.tsx b/src/containers/Modals/ShareModal/index.tsx index c256b98..f925f2f 100644 --- a/src/containers/Modals/ShareModal/index.tsx +++ b/src/containers/Modals/ShareModal/index.tsx @@ -47,7 +47,9 @@ export const ShareModal: React.FC = ({ visible, setVisible }) => { const json = useConfig(state => state.json); const [encodedJson, setEncodedJson] = React.useState(""); - const embedText = ``; + const embedText = ``; const shareURL = `${baseURL}/editor?json=${encodedJson}`; React.useEffect(() => { @@ -88,17 +90,17 @@ export const ShareModal: React.FC = ({ visible, setVisible }) => { - - Embed into your website - - - - - )} + + Embed into your website + + + + + diff --git a/src/pages/Widget/index.tsx b/src/pages/Widget/index.tsx index 93eaea9..b958034 100644 --- a/src/pages/Widget/index.tsx +++ b/src/pages/Widget/index.tsx @@ -1,7 +1,6 @@ import React from "react"; import dynamic from "next/dynamic"; import { useRouter } from "next/router"; -import { decompress } from "compress-json"; import { baseURL } from "src/constants/data"; import useGraph from "src/hooks/store/useGraph"; import { isValidJson } from "src/utils/isValidJson"; @@ -38,17 +37,22 @@ function inIframe() { } const WidgetPage = () => { - const { query, push } = useRouter(); + const { push } = useRouter(); + const [json, setJson] = React.useState(null); const setGraphValue = useGraph(state => state.setGraphValue); React.useEffect(() => { - if (query.json) { - const jsonURI = decodeURIComponent(query.json as string); + const dataJson = window.self.frameElement?.getAttribute("data-json"); + if (dataJson) setJson(dataJson); + }, []); + + React.useEffect(() => { + if (json) { + const jsonURI = decodeURIComponent(json); const isJsonValid = isValidJson(jsonURI); if (isJsonValid) { - const jsonDecoded = decompress(JSON.parse(isJsonValid)); - const { nodes, edges } = parser(JSON.stringify(jsonDecoded)); + const { nodes, edges } = parser(jsonURI); setGraphValue("nodes", nodes); setGraphValue("edges", edges); @@ -56,16 +60,12 @@ const WidgetPage = () => { } if (!inIframe()) push("/"); - }, [push, query.json, setGraphValue]); + }, [push, json, setGraphValue]); return ( <> - + jsoncrack.com