Skip to content

Commit

Permalink
Show title when images can't be retrieved
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Mar 23, 2024
1 parent 41eb830 commit 9ca5297
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/app/images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ export interface ImagesProps {
readonly onDataFetched: (dataForAiState: unknown) => void;
}

type ImagesContainerProps = React.PropsWithChildren<{
readonly title: string;
}>;

function ImagesContainer({title, children}: ImagesContainerProps) {
return (
<div className="space-y-3">
<h4 className="text-l font-bold">{title}</h4>
{children}
</div>
);
}

export async function Images({
title,
notFoundMessage,
Expand All @@ -40,15 +53,16 @@ export async function Images({
: result.errorMessage;

return (
<p className="text-sm">
<em>{message}</em>
</p>
<ImagesContainer title={result.title}>
<p className="text-sm">
<em>{message}</em>
</p>
</ImagesContainer>
);
}

return (
<div className="space-y-3">
<h4 className="text-l font-bold">{result.title}</h4>
<ImagesContainer title={result.title}>
{result.images.map(({thumbnailUrl, url, width, height}) => (
<ImageSelector key={thumbnailUrl} url={url}>
<ProgressiveImage
Expand All @@ -60,6 +74,6 @@ export async function Images({
/>
</ImageSelector>
))}
</div>
</ImagesContainer>
);
}

0 comments on commit 9ca5297

Please sign in to comment.