Rearranged shop template page to better handle previews & template editor BOD-126

This commit is contained in:
Patrick Fic
2020-09-04 15:03:01 -07:00
parent 051be83303
commit af8e39da75
8 changed files with 129 additions and 88 deletions

View File

@@ -8,7 +8,7 @@ import "codemirror/lib/codemirror.css";
import "codemirror/theme/material.css";
import "codemirror/addon/hint/show-hint";
import React, { useEffect, useRef } from "react";
import React, { useEffect, useRef, useState } from "react";
import { Controlled as CmEditor } from "react-codemirror2";
import EmailEditor from "react-email-editor";
import GqlSchema from "../../graphql/schema";
@@ -32,18 +32,15 @@ export default function ShopTemplateEditorComponent({
editorState,
}) {
const [editorContent, seteditorContent] = editorState;
const [editorLoaded, setEditorLoaded] = useState(false);
const emailEditorRef = useRef(null);
useEffect(() => {
if (
json &&
Object.keys(json).length > 0 &&
emailEditorRef &&
emailEditorRef.current
) {
if (json && Object.keys(json).length > 0 && editorLoaded) {
console.log(emailEditorRef.current, !!emailEditorRef.current.loadDesign);
emailEditorRef.current.loadDesign(json);
}
}, [json, emailEditorRef]);
}, [json, emailEditorRef, editorLoaded]);
useEffect(() => {
seteditorContent((prevstate) => {
@@ -58,9 +55,11 @@ export default function ShopTemplateEditorComponent({
gql={editorContent.gql}
emailEditorRef={emailEditorRef}
/>
<EmailEditor
style={{ width: "100%" }}
ref={emailEditorRef}
minHeight="800px"
onLoad={() => setEditorLoaded(true)}
options={{
// customCSS: [
// window.location.protocol +
@@ -78,6 +77,7 @@ export default function ShopTemplateEditorComponent({
/>
<div style={{ display: "flex" }}>
<CmEditor
style={{ width: "30rem" }}
value={editorContent.gql}
options={{
mode: "graphql",
@@ -93,7 +93,6 @@ export default function ShopTemplateEditorComponent({
seteditorContent({ ...editorContent, gql: value });
}}
/>
)
<ShopTemplateTestRender
query={editorContent.gql}
emailEditorRef={emailEditorRef}