MediaAttachmentGrid: improve layout as length % 2

This commit is contained in:
thislight 2024-10-08 17:43:33 +08:00
parent b853b01304
commit 050dc1c2a3

View file

@ -51,9 +51,19 @@ const MediaAttachmentGrid: Component<{
setViewerIndex(index);
};
const columnCount = () => {
if (props.attachments.length === 1) {
return 1;
} else if (props.attachments.length % 2 === 0) {
return 2;
} else {
return 3;
}
};
css`
.attachments {
column-count: ${(props.attachments.length === 1 ? 1 : 3).toString()};
column-count: ${columnCount.toString()};
}
`;
return (
@ -104,17 +114,17 @@ const MediaAttachmentGrid: Component<{
/>
);
case "gifv": // Later we can handle the preview
return (
<video
src={item.url || undefined}
style={style()}
onLoadedMetadata={[setLoaded, true]}
autoplay={false}
controls
playsinline /* or safari on iOS will play in full-screen */
loop
/>
);
return (
<video
src={item.url || undefined}
style={style()}
onLoadedMetadata={[setLoaded, true]}
autoplay={false}
controls
playsinline /* or safari on iOS will play in full-screen */
loop
/>
);
case "audio":
case "unknown":