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

💄 style: improve images display in chat messages #3475

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
19 changes: 11 additions & 8 deletions src/components/GalleyGrid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,24 @@ const GalleyGrid = memo<GalleyGridProps>(({ items, renderItem: Render }) => {
};
}

const firstCol = items.length % 3 === 0 ? 3 : items.length % 3;
const firstCol = items.length > 4 ? 3 : items.length;

return {
firstRow: items.slice(0, firstCol),
lastRow: items.slice(firstCol, items.length),
};
}, [items]);

const { gap, max } = useMemo(
() => ({
const { gap, max } = useMemo(() => {
let scale = firstRow.length * (firstRow.length / items.length);

scale = scale < 1 ? 1 : scale;

return {
gap: mobile ? 4 : 6,
max: (mobile ? MAX_SIZE_MOBILE : MAX_SIZE_DESKTOP) * firstRow.length,
}),
[mobile],
);
max: (mobile ? MAX_SIZE_MOBILE : MAX_SIZE_DESKTOP) * scale,
};
}, [mobile, items]);

return (
<Flexbox gap={gap}>
Expand All @@ -45,7 +48,7 @@ const GalleyGrid = memo<GalleyGridProps>(({ items, renderItem: Render }) => {
))}
</Grid>
{lastRow.length > 0 && (
<Grid col={lastRow.length > 2 ? 3 : lastRow.length} gap={gap} max={max}>
<Grid col={firstRow.length} gap={gap} max={max}>
{lastRow.map((i, index) => (
<Render {...i} index={index} key={index} />
))}
Expand Down