|
@@ -2,6 +2,7 @@ import { decompress } from "compress-json";
|
|
|
import dynamic from "next/dynamic";
|
|
|
import { useRouter } from "next/router";
|
|
|
import React from "react";
|
|
|
+import { defaultJson } from "src/constants/data";
|
|
|
import { isValidJson } from "src/utils/isValidJson";
|
|
|
import styled from "styled-components";
|
|
|
|
|
@@ -36,19 +37,22 @@ const Widget = () => {
|
|
|
const [json, setJson] = React.useState("");
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
- const isJsonValid =
|
|
|
- typeof query.json === "string" &&
|
|
|
- isValidJson(decodeURIComponent(query.json));
|
|
|
+ if (!query.json) {
|
|
|
+ setJson(JSON.stringify(defaultJson));
|
|
|
+ } else {
|
|
|
+ const jsonURI = decodeURIComponent(query.json as string);
|
|
|
+ const isJsonValid = isValidJson(jsonURI);
|
|
|
|
|
|
- if (isJsonValid) {
|
|
|
- const jsonDecoded = decompress(JSON.parse(isJsonValid));
|
|
|
- const jsonString = JSON.stringify(jsonDecoded);
|
|
|
+ if (isJsonValid) {
|
|
|
+ const jsonDecoded = decompress(JSON.parse(isJsonValid));
|
|
|
+ const jsonString = JSON.stringify(jsonDecoded);
|
|
|
|
|
|
- setJson(jsonString);
|
|
|
+ setJson(jsonString);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- // if (!inIframe()) push("/");
|
|
|
- }, [query.json]);
|
|
|
+ if (!inIframe()) push("/");
|
|
|
+ }, [query?.json]);
|
|
|
|
|
|
return (
|
|
|
<div>
|