diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..9d7ef22 --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,10 @@ +export const BLURHASH_DEFAULTS = { + imageField: 'image', + blurhashField: 'blurhash', + componentX: 4, + componentY: 3, +} + +export const APP_ID = { + production: '6EgmuKsOM0M1hPRhd9Zo75' +} \ No newline at end of file diff --git a/src/hooks/useCreateBlurhash.tsx b/src/hooks/useCreateBlurhash.tsx index 7d033df..51035ea 100644 --- a/src/hooks/useCreateBlurhash.tsx +++ b/src/hooks/useCreateBlurhash.tsx @@ -4,6 +4,7 @@ import {PlainClientAPI} from "contentful-management"; import {useMemo, useRef} from "react"; import {useQuery} from "@tanstack/react-query"; import {useInstanceParameters} from "./useInstanceParameters"; +import {BLURHASH_DEFAULTS} from "../constants"; type InputProps = { assetId?: string @@ -20,8 +21,8 @@ type Props = InputProps & Required { const newContentType = await sdk.cma.contentType.createWithId(params, makeContentType(CONTENT_TYPE_NAME)) await sdk.cma.contentType.publish(params, newContentType) console.log({newContentType}) + + const editorInterface = await sdk.cma.editorInterface.get({ + contentTypeId: newContentType.sys.id + }) + + const blurhashFieldControls = { + fieldId: BLURHASH_DEFAULTS.blurhashField, + widgetId: APP_ID.production, + widgetNamespace: "app", + settings: { + sourceImageFieldId: BLURHASH_DEFAULTS.imageField, + componentX: BLURHASH_DEFAULTS.componentX, + componentY: BLURHASH_DEFAULTS.componentY + } + } + + editorInterface.controls = editorInterface.controls?.filter(control => control.fieldId !== BLURHASH_DEFAULTS.blurhashField) || [] + editorInterface.controls.push(blurhashFieldControls) + await sdk.cma.editorInterface.update({contentTypeId: newContentType.sys.id}, editorInterface) } return { diff --git a/src/logic/makeContentType.ts b/src/logic/makeContentType.ts index 9da7801..200fca7 100644 --- a/src/logic/makeContentType.ts +++ b/src/logic/makeContentType.ts @@ -1,4 +1,5 @@ import {CreateContentTypeProps} from "contentful-management/dist/typings/entities/content-type"; +import {BLURHASH_DEFAULTS} from "../constants"; export const makeContentType = (contentTypeName: string): CreateContentTypeProps => ({ name: contentTypeName, @@ -12,7 +13,7 @@ export const makeContentType = (contentTypeName: string): CreateContentTypeProps localized: false, }, { - id: 'image', + id: BLURHASH_DEFAULTS.imageField, name: 'Image', required: true, type: 'Link', @@ -20,7 +21,7 @@ export const makeContentType = (contentTypeName: string): CreateContentTypeProps localized: false, }, { - id: 'blurhash', + id: BLURHASH_DEFAULTS.blurhashField, name: 'Blurhash', required: true, type: 'Symbol',