Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display issues for scenes without images #876

Merged
merged 1 commit into from
Dec 29, 2024
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
25 changes: 16 additions & 9 deletions frontend/src/components/fragments/Thumbnail.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import { FC } from "react";
import { faXmark } from "@fortawesome/free-solid-svg-icons";
import Icon from "./Icon";

interface Props {
image: string;
image?: string;
size?: number;
alt?: string | null;
className?: string;
}

export const Thumbnail: FC<Props> = ({ image, size, alt, className }) => (
<img
alt={alt ?? ""}
className={className}
src={image + (size ? `?size=${size}` : "")}
srcSet={size ? `${image}?size=${size * 2} ${size * 2}w` : ""}
/>
);
export const Thumbnail: FC<Props> = ({ image, size, alt, className }) =>
image ? (
<img
alt={alt ?? ""}
className={className}
src={image + (size ? `?size=${size}` : "")}
srcSet={size ? `${image}?size=${size * 2} ${size * 2}w` : ""}
/>
) : (
<div className="Thumbnail-empty" style={{ aspectRatio: "16/9" }}>
<Icon icon={faXmark} />
</div>
);
17 changes: 17 additions & 0 deletions frontend/src/components/fragments/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,20 @@
.Tooltip {
position: absolute !important;
}

.Thumbnail {
&-empty {
display: flex;
width: 100%;
height: 100%;
color: var(--bs-gray-400);
background-color: #394b59;
align-items: center;
justify-content: center;
border-radius: 4px;

.fa-icon {
height: 30px;
}
}
}
13 changes: 6 additions & 7 deletions frontend/src/components/image/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Image = {
};

interface ImageProps {
image: Image;
image?: Image;
emptyMessage?: string;
size?: number | "full";
alt?: string;
Expand All @@ -29,7 +29,7 @@ const ImageComponent: FC<ImageProps> = ({
"loading",
);

if (!image.url)
if (!image?.url)
return (
<div className={`${CLASSNAME}-missing`}>
<Icon icon={faXmark} color="var(--bs-gray-400)" />
Expand Down Expand Up @@ -62,7 +62,7 @@ const ImageComponent: FC<ImageProps> = ({
};

interface ContainerProps {
images: Image[] | Image;
images: Image[] | Image | undefined;
orientation?: "landscape" | "portrait";
emptyMessage?: string;
size?: number | "full";
Expand All @@ -80,11 +80,10 @@ const ImageContainer: FC<ContainerProps> = ({
? sortImageURLs(images, orientation)[0]
: images;

const aspectRatio = image ? `${image.width}/${image.height}` : "16/6";

return (
<div
className={cx(CLASSNAME, className)}
style={{ aspectRatio: `${image.width}/${image.height}` }}
>
<div className={cx(CLASSNAME, className)} style={{ aspectRatio }}>
<ImageComponent {...props} image={image} />
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const getImage = (
orientation: "portrait" | "landscape",
) => {
const images = sortImageURLs(urls, orientation);
return images?.[0]?.url ?? "";
return images?.[0]?.url;
};

export const imageType = (image?: Image) => {
Expand Down
Loading