update options

This commit is contained in:
Rami Bitar
2026-05-09 15:36:10 -04:00
parent 572de32e1a
commit 3a3d0a6ac8
4 changed files with 15 additions and 39 deletions

View File

@@ -1,5 +1,5 @@
import { useCallback, useMemo, useRef, useState } from "react";
import { App as ReactEditorApp, createUseEditor } from "@reacteditor/core";
import { App as ReactEditorApp } from "@reacteditor/core";
import "@reacteditor/core/react-editor.css";
import createTailwindCdnPlugin from "@reacteditor/plugin-tailwind-cdn";
import { mediaPlugin } from "@reacteditor/plugin-media";
@@ -9,15 +9,12 @@ import "@reacteditor/plugin-ai/styles.css";
import { createConfig } from "@/react-editor.config";
import { ShopifyProvider } from "@/contexts/shopify-context";
import { frontendAiMediaAdapter } from "@/services/media-adapter";
import { Loader } from "@/components/ui/loader";
import schemaJson from "../app.schema.json";
const AI_API_KEY = (import.meta.env.VITE_API_KEY as string | undefined) ?? "";
type Pages = Record<string, { root: any; content: any[] }>;
const useEditor = createUseEditor();
const SHOPIFY_DOMAIN =
(import.meta.env.VITE_SHOPIFY_DOMAIN as string | undefined) ?? "mock.shop";
const STOREFRONT_TOKEN =
@@ -34,7 +31,6 @@ function readPathname() {
export default function App() {
const pages = schemaJson as Pages;
const [currentPath, setCurrentPath] = useState<string>(readPathname);
const [isPublishing, setIsPublishing] = useState(false);
const latestDataRef = useRef<any>(null);
const handleChange = useCallback((data: any) => {
@@ -50,17 +46,15 @@ export default function App() {
[],
);
const handlePublish = useCallback((data: any, route?: string) => {
console.log(data);
setIsPublishing(true);
if (typeof window !== "undefined" && window.parent !== window) {
window.parent.postMessage(
{ type: "PUBLISH", data: { data, route } },
"*",
);
const handlePublish = async (data: any, route?: { key: string }) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
if (typeof window !== "undefined" && window.parent !== window) {
window.parent.postMessage(
{ type: "PUBLISH", data: { data, route: route?.key } },
"*",
);
}
}
setTimeout(() => setIsPublishing(false), 1000);
}, []);
const plugins = useMemo(
() => [createTailwindCdnPlugin()],
@@ -81,24 +75,6 @@ export default function App() {
}}
onPublish={handlePublish}
onChange={handleChange}
overrides={{
headerActions: () => {
const appState = useEditor((s: any) => s.appState);
return (
<button
type="button"
disabled={isPublishing}
onClick={() => {
handlePublish(appState.data, currentPath);
}}
className="inline-flex items-center justify-center gap-2 rounded-md bg-black px-4 py-1.5 text-sm font-medium text-white hover:bg-gray-800 disabled:cursor-not-allowed disabled:opacity-60"
>
{isPublishing && <Loader size={14} />}
{isPublishing ? "Saving..." : "Save"}
</button>
);
},
}}
/>
</ShopifyProvider>
</div>