Skip to content

Commit

Permalink
refactor: remove useMessage hooks (#125)
Browse files Browse the repository at this point in the history
This update corresponds with the removal of useMessage hook exports in
VE-Lib. See this [PR](yext/visual-editor#13) for
more details.

---------

Co-authored-by: tsaikatie <ktsai@yext.com>
Co-authored-by: ehallerYext <ehaller@yext.com>
Co-authored-by: Alexis Sanehisa <106991746+asanehisa@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 8, 2024
1 parent 1ad283e commit 2adb01b
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/templates/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import {
Editor,
useReceiveMessage,
TARGET_ORIGINS,
TemplateMetadata,
useDocumentProvider,
} from "@yext/visual-editor";
import {useState} from "react";
import {Config} from "@measured/puck";
import {puckConfigs} from "../puck/puck.config";
import {GetPath, TemplateProps, TemplateConfig} from "@yext/pages";
import {DocumentProvider} from "@yext/pages/util";
Expand All @@ -22,30 +18,13 @@ export const config: TemplateConfig = {

// Render the editor
const Edit: () => JSX.Element = () => {
const [puckConfig, setPuckConfig] = useState<Config>();
const [entityDocument, setEntityDocument] = useState<any>(); // json data
const [templateMetadata, setTemplateMetadata] = useState<TemplateMetadata>();

useReceiveMessage("getEntityDocument", TARGET_ORIGINS, (send, payload) => {
setEntityDocument(payload);
send({
status: "success",
payload: { message: "getEntityDocument received" },
});
});

useReceiveMessage("getTemplateMetadata", TARGET_ORIGINS, (send, payload) => {
const puckConfig = puckConfigs.get(payload.templateId);
setPuckConfig(puckConfig);
setTemplateMetadata(payload as TemplateMetadata);
send({ status: "success", payload: { message: "payload received" } });
});
const entityDocument = useDocumentProvider();

return (
<DocumentProvider value={entityDocument}>
<Editor document={entityDocument} puckConfig={puckConfig!} templateMetadata={templateMetadata!}/>
<Editor document={entityDocument} puckConfigs={puckConfigs} />
</DocumentProvider>
);
};

export default Edit;
export default Edit;

0 comments on commit 2adb01b

Please sign in to comment.