diff --git a/src/components/sections/imageSection/ImageSectionComponentPreview.tsx b/src/components/sections/imageSection/ImageSectionComponentPreview.tsx index d2aa97c14..6d9d34af7 100644 --- a/src/components/sections/imageSection/ImageSectionComponentPreview.tsx +++ b/src/components/sections/imageSection/ImageSectionComponentPreview.tsx @@ -18,7 +18,7 @@ export default function ImageSectionComponentPreview({ { initial: initialData }, ); - const testimonialsSection = newData + const imageSection = newData ? (newData.sections.find( (section, index) => section._type === "imageSection" && index === sectionIndex, @@ -30,7 +30,7 @@ export default function ImageSectionComponentPreview({ return ( - + ); } diff --git a/studio/lib/queries/pages.ts b/studio/lib/queries/pages.ts index 69766a785..ea376df46 100644 --- a/studio/lib/queries/pages.ts +++ b/studio/lib/queries/pages.ts @@ -3,6 +3,14 @@ import { groq } from "next-sanity"; import { LANGUAGE_FIELD_FRAGMENT, TRANSLATED_LINK_FRAGMENT } from "./i18n"; import { translatedFieldFragment } from "./utils/i18n"; +const INTERNATIONALIZED_IMAGE_FRAGMENT = groq` + asset, + "metadata": asset -> metadata { + lqip + }, + "alt": ${translatedFieldFragment("alt")} +`; + const SECTIONS_FRAGMENT = groq` sections[]{ ..., @@ -36,6 +44,10 @@ const SECTIONS_FRAGMENT = groq` ..., ${TRANSLATED_LINK_FRAGMENT} } + }, + _type == "imageSection" => { + ..., + "image": image {${INTERNATIONALIZED_IMAGE_FRAGMENT}}, }, _type == "ctaSection" => { ..., diff --git a/studio/schemas/documents/pageBuilder.ts b/studio/schemas/documents/pageBuilder.ts index 85d459f6c..76ebecc45 100644 --- a/studio/schemas/documents/pageBuilder.ts +++ b/studio/schemas/documents/pageBuilder.ts @@ -8,7 +8,6 @@ import contactBox from "studio/schemas/objects/sections/contact-box"; import { customerCasesEntry } from "studio/schemas/objects/sections/customerCasesEntry"; import { employeeHighlightSection } from "studio/schemas/objects/sections/employeeHighlight"; import { employees } from "studio/schemas/objects/sections/employees"; -import grid from "studio/schemas/objects/sections/grid"; import hero from "studio/schemas/objects/sections/hero"; import imageSection from "studio/schemas/objects/sections/image"; import imageSplitSection from "studio/schemas/objects/sections/imagesplit"; @@ -51,7 +50,7 @@ const pageBuilder = defineType({ // testimonals, imageSplitSection, imageSection, - grid, + // grid, employees, customerCasesEntry, contactBox, diff --git a/studio/schemas/objects/sections/hero.ts b/studio/schemas/objects/sections/hero.ts index 696437ced..6bf5cd4e2 100644 --- a/studio/schemas/objects/sections/hero.ts +++ b/studio/schemas/objects/sections/hero.ts @@ -1,6 +1,6 @@ import { defineField } from "sanity"; -import { allTranslation } from "studio/utils/i18n"; +import { allTranslations } from "studio/utils/i18n"; export const heroID = "hero"; @@ -75,7 +75,7 @@ export const hero = defineField({ prepare(selection) { const { title } = selection; return { - title: allTranslation(title) ?? undefined, + title: allTranslations(title) ?? undefined, subtitle: "Hero Section", }; }, diff --git a/studio/schemas/objects/sections/image.ts b/studio/schemas/objects/sections/image.ts index 8b9b60f22..978039a2e 100644 --- a/studio/schemas/objects/sections/image.ts +++ b/studio/schemas/objects/sections/image.ts @@ -1,7 +1,8 @@ import { defineField } from "sanity"; -import image from "studio/schemas/fields/media"; -import { title } from "studio/schemas/fields/text"; +import { isInternationalizedString } from "studio/lib/interfaces/global"; +import { internationalizedImage } from "studio/schemas/fields/media"; +import { allTranslations } from "studio/utils/i18n"; export const imageID = "imageSection"; @@ -10,22 +11,31 @@ export const imageSection = defineField({ title: "Image", type: "object", fields: [ - title, defineField({ - ...image, + ...internationalizedImage, description: "Upload a featured image for the section.", validation: (rule) => rule.required(), }), ], preview: { select: { - title: "basicTitle", + image: "image", + fullWidth: "fullWidth", }, - prepare(selection) { - const { title } = selection; + prepare: ({ image, fullWidth }) => { + const imageAlt = image.alt; + if (!isInternationalizedString(imageAlt)) { + throw new TypeError( + `Expected image 'alt' to be InternationalizedString, was ${typeof image.alt}`, + ); + } return { - title: title, - subtitle: "Image", + title: + imageAlt !== undefined + ? (allTranslations(imageAlt) ?? undefined) + : undefined, + subtitle: fullWidth ? "Full Width" : undefined, + media: image, }; }, }, diff --git a/studio/utils/i18n.ts b/studio/utils/i18n.ts index ca202ab3b..726a7f79f 100644 --- a/studio/utils/i18n.ts +++ b/studio/utils/i18n.ts @@ -9,7 +9,7 @@ export function firstTranslation( return internationalizedValue[0].value; } -export function allTranslation( +export function allTranslations( internationalizedValue: InternationalizedValue, ): string | null { if (internationalizedValue.length === 0) { diff --git a/studioShared/schemas/fields/customerCaseProjectInfo.ts b/studioShared/schemas/fields/customerCaseProjectInfo.ts index 83d806058..512c380fd 100644 --- a/studioShared/schemas/fields/customerCaseProjectInfo.ts +++ b/studioShared/schemas/fields/customerCaseProjectInfo.ts @@ -2,7 +2,7 @@ import { UlistIcon } from "@sanity/icons"; import { defineField } from "sanity"; import { isInternationalizedString } from "studio/lib/interfaces/global"; -import { allTranslation } from "studio/utils/i18n"; +import { allTranslations } from "studio/utils/i18n"; export const customerCaseProjectInfo = defineField({ name: "projectInfo", @@ -45,7 +45,7 @@ export const customerCaseProjectInfo = defineField({ ); } return { - title: allTranslation(customerSector) ?? undefined, + title: allTranslations(customerSector) ?? undefined, }; }, }, @@ -127,7 +127,8 @@ export const customerCaseProjectInfo = defineField({ ); } return { - title: allTranslation(design) ?? "No translation available", + title: + allTranslations(design) ?? "No translation available", }; }, }, @@ -160,7 +161,8 @@ export const customerCaseProjectInfo = defineField({ } return { title: - allTranslation(development) ?? "No translation available", + allTranslations(development) ?? + "No translation available", }; }, }, @@ -193,7 +195,7 @@ export const customerCaseProjectInfo = defineField({ } return { title: - allTranslation(projectManagement) ?? + allTranslations(projectManagement) ?? "No translation available", }; },