added resolve schema

This commit is contained in:
Rami Bitar
2026-05-02 10:01:13 -04:00
parent 82809b17b4
commit a78249846a
7 changed files with 166 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ import "@/editor/vendor/plugin-ai.css";
import { createConfig } from "@/editor/config";
import { ShopifyProvider } from "@/editor/contexts/shopify-context";
import { Button } from "@/editor/components/ui/button";
import { resolveSchemaEntry, templateKeyForRoute } from "@/lib/schema-resolver";
type Schema = Record<string, { root: any; content: any[] }>;
@@ -61,8 +62,17 @@ export default function EditorClient({
const [schema, setSchema] = useState<Schema>(initialSchema);
const [currentPath, setCurrentPath] = useState<string>(initialPath);
const editKey = useMemo(
() => templateKeyForRoute(currentPath) ?? currentPath,
[currentPath],
);
const data = useMemo(
() => schema[currentPath] ?? { root: { props: {} }, content: [] },
() =>
resolveSchemaEntry(schema, currentPath)?.data ?? {
root: { props: {} },
content: [],
},
[schema, currentPath],
);
@@ -125,12 +135,12 @@ export default function EditorClient({
router.push(`/edit${next === "/" ? "" : next}`);
}}
onPublish={async (next) => {
await persist(currentPath, next);
await persist(editKey, next);
}}
iframe={{ enabled: true }}
overrides={{
headerActions: () => (
<SaveButton currentPath={currentPath} onSave={persist} />
<SaveButton currentPath={editKey} onSave={persist} />
),
}}
/>