Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/frontend/src/api/utils/customDataUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -741,3 +741,17 @@ export const customDataAsCardData: (
return undefined;
}
};

export const validateImageCustomData = (
customData: TRemoteCustomData | undefined
): { imageUrl: string | undefined; imageLink: string | undefined } => {
let imageUrl = customData?.[0]?.image_url;
let imageLink = customData?.[0]?.image_link;
if (typeof imageUrl !== "string") {
imageUrl = undefined;
}
if (typeof imageLink !== "string") {
imageLink = undefined;
}
return { imageUrl, imageLink };
};
3 changes: 3 additions & 0 deletions packages/frontend/src/components/image/ImageModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ImageWidget from "./ImageWidget";

interface IImageModule {
imageUrl: string | undefined;
imageLink?: string;
title: string;
contentHeight?: string;
isLoading: boolean;
Expand All @@ -14,6 +15,7 @@ interface IImageModule {

export const ImageModule: FC<IImageModule> = ({
imageUrl,
imageLink,
title,
contentHeight,
isLoading,
Expand All @@ -36,6 +38,7 @@ export const ImageModule: FC<IImageModule> = ({
>
<ImageWidget
imageUrl={processedImageUrl}
imageLink={imageLink}
title={title}
isLoading={isLoading}
onAspectRatioDetected={onAspectRatioDetected}
Expand Down
15 changes: 14 additions & 1 deletion packages/frontend/src/components/image/ImageWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import globalMessages from "src/globalMessages";
interface IImageWidget {
title: string;
imageUrl: string;
imageLink?: string;
isLoading: boolean;
showImage: boolean;
onAspectRatioDetected?: (aspectRatio: number) => void;
Expand All @@ -13,6 +14,7 @@ interface IImageWidget {
const ImageWidget: FC<IImageWidget> = memo(function ImageWidget({
title,
imageUrl,
imageLink,
isLoading,
showImage,
onAspectRatioDetected,
Expand Down Expand Up @@ -55,7 +57,18 @@ const ImageWidget: FC<IImageWidget> = memo(function ImageWidget({
}

return (
<div className="flex items-center justify-center w-full h-full">
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<div
tabIndex={-1}
className="flex items-center justify-center w-full h-full"
onClick={() => {
if (imageLink) {
window.open(imageLink, "_blank");
}
}}
style={{ cursor: imageLink ? "pointer" : "default" }}
role="banner"
>
{imageLoading && <ModuleLoader $height="500px" />}
<img
src={imageUrl}
Expand Down
17 changes: 5 additions & 12 deletions packages/frontend/src/containers/image/OneColImageContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import { type FC, Suspense, useMemo } from "react";
import { ModuleLoader } from "@alphaday/ui-kit";
import { TRemoteCustomData } from "src/api/services";
import { validateImageCustomData } from "src/api/utils/customDataUtils";
import CONFIG from "src/config";
import type { IModuleContainer } from "src/types";
import { ImageModule } from "../../components/image/ImageModule";

const validateCustomData = (
customData: TRemoteCustomData | undefined
): { imageUrl: string | undefined } => {
let imageUrl = customData?.[0]?.image_url;
if (typeof imageUrl !== "string") {
imageUrl = undefined;
}
return { imageUrl };
};

const OneColImageContainer: FC<IModuleContainer> = ({ moduleData }) => {
const { imageUrl } = validateCustomData(moduleData.widget.custom_data);
const { imageUrl, imageLink } = validateImageCustomData(
moduleData.widget.custom_data
);

const contentHeight = useMemo(() => {
return `${CONFIG.WIDGETS.ONE_COL_IMAGE.WIDGET_HEIGHT || 600}px`;
Expand All @@ -26,6 +18,7 @@ const OneColImageContainer: FC<IModuleContainer> = ({ moduleData }) => {
<Suspense fallback={<ModuleLoader $height={contentHeight} />}>
<ImageModule
imageUrl={imageUrl}
imageLink={imageLink}
title={moduleData.widget.name}
isLoading={!moduleData}
type="one_col_image"
Expand Down
17 changes: 5 additions & 12 deletions packages/frontend/src/containers/image/TwoColImageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@ import {
} from "react";
import { ModuleLoader } from "@alphaday/ui-kit";
import { useTwoColImageWidgetSize } from "src/api/hooks";
import { TRemoteCustomData } from "src/api/services";
import { validateImageCustomData } from "src/api/utils/customDataUtils";
import CONFIG from "src/config";
import type { IModuleContainer } from "src/types";
import { ImageModule } from "../../components/image/ImageModule";

const validateCustomData = (
customData: TRemoteCustomData | undefined
): { imageUrl: string | undefined } => {
let imageUrl = customData?.[0]?.image_url;
if (typeof imageUrl !== "string") {
imageUrl = undefined;
}
return { imageUrl };
};

const TwoColImageContainer: FC<IModuleContainer> = ({
moduleData,
onAspectRatioDetected,
Expand All @@ -32,7 +22,9 @@ const TwoColImageContainer: FC<IModuleContainer> = ({
number | null
>(null);

const { imageUrl } = validateCustomData(moduleData.widget.custom_data);
const { imageUrl, imageLink } = validateImageCustomData(
moduleData.widget.custom_data
);
const previousImageUrl = useRef<string | undefined>(imageUrl);

if (previousImageUrl.current !== imageUrl) {
Expand Down Expand Up @@ -75,6 +67,7 @@ const TwoColImageContainer: FC<IModuleContainer> = ({
<Suspense fallback={<ModuleLoader $height={contentHeight} />}>
<ImageModule
imageUrl={imageUrl}
imageLink={imageLink}
title={moduleData.widget.name}
contentHeight={contentHeight}
isLoading={!moduleData}
Expand Down
Loading