Skip to content

Commit

Permalink
Demo: fix footer block preview (#2966)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrgulbis authored Dec 19, 2024
1 parent 61f9032 commit 0293c03
Showing 1 changed file with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"use client";

import { BlockPreviewProvider, IFrameBridgeProvider, useIFrameBridge } from "@comet/cms-site";
import { useBlockPreviewFetch, useIFrameBridge } from "@comet/cms-site";
import { FooterContentBlockData } from "@src/blocks.generated";
import { FooterContentBlock } from "@src/layout/footer/blocks/FooterContentBlock";
import { recursivelyLoadBlockData } from "@src/recursivelyLoadBlockData";
import { createGraphQLFetch } from "@src/util/graphQLClient";
import { withBlockPreview } from "@src/util/blockPreview";
import { useEffect, useState } from "react";

const PreviewPage = () => {
export default withBlockPreview(() => {
const iFrameBridge = useIFrameBridge();

const graphQLFetch = createGraphQLFetch();
const { fetch, graphQLFetch } = useBlockPreviewFetch();

const [blockData, setBlockData] = useState<FooterContentBlockData>();
useEffect(() => {
async function load() {
if (!graphQLFetch) return;
if (!iFrameBridge.block) {
setBlockData(undefined);
return;
Expand All @@ -28,19 +29,7 @@ const PreviewPage = () => {
setBlockData(newData);
}
load();
}, [iFrameBridge.block, graphQLFetch]);
}, [iFrameBridge.block, fetch, graphQLFetch]);

return <div>{blockData && <FooterContentBlock data={blockData} />}</div>;
};

const IFrameBridgePreviewPage = () => {
return (
<IFrameBridgeProvider>
<BlockPreviewProvider>
<PreviewPage />
</BlockPreviewProvider>
</IFrameBridgeProvider>
);
};

export default IFrameBridgePreviewPage;
});

0 comments on commit 0293c03

Please sign in to comment.