added resolve schema
This commit is contained in:
@@ -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} />
|
||||
),
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user