Skip to content

Commit

Permalink
feat(SanityImage): alternatives to useNextSanityGlobalImage
Browse files Browse the repository at this point in the history
If the project is known, the image url should be used directly without the existence check
  • Loading branch information
mathiazom committed Oct 17, 2024
1 parent 20106a7 commit b907256
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/components/image/SanityImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ const useNextSanityGlobalImage = (
return globalImage;
};

const SanityAssetImage = ({ image }: { image: IImage }) => {
const imageProps = useNextSanityGlobalImage(image);
const SanityAssetImage = ({
image,
imageProps,
}: {
image: IImage;
imageProps?: UseNextSanityImageProps;
}) => {
const objectPosition = image.hotspot
? `${image.hotspot.x * 100}% ${image.hotspot.y * 100}%`
: "50% 50%"; // Default to center if no hotspot is defined
Expand All @@ -62,6 +67,23 @@ const SanityAssetImage = ({ image }: { image: IImage }) => {
);
};

export function SanityStudioImage({ image }: { image: IImage }) {
const imageProps = useNextSanityImage(client, image);
return <SanityAssetImage image={image} imageProps={imageProps} />;
}

export function SanitySharedImage({ image }: { image: IImage }) {
const imageProps = useNextSanityImage(sharedClient, image);
return <SanityAssetImage image={image} imageProps={imageProps} />;
}

function SanityGlobalImage({ image }: { image: IImage }) {
const imageProps = useNextSanityGlobalImage(image);
return (
<SanityAssetImage image={image} imageProps={imageProps ?? undefined} />
);
}

export function SanityImage({ image }: { image: IImage }) {
if (image?.src) {
return (
Expand All @@ -74,5 +96,5 @@ export function SanityImage({ image }: { image: IImage }) {
/>
);
}
return <SanityAssetImage image={image} />;
return <SanityGlobalImage image={image} />;
}

0 comments on commit b907256

Please sign in to comment.