Skip to content

Commit bdfa799

Browse files
Merge pull request #152 from codeforpdx/141/enhancement-optimize-volunteer-images-for-smaller-screens
141/enhancement optimize volunteer images for smaller screens
2 parents 24cb18f + 4fb0af4 commit bdfa799

File tree

1 file changed

+55
-33
lines changed

1 file changed

+55
-33
lines changed

src/components/home/about/ImageSection.jsx

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,65 @@
22
import Box from '@mui/material/Box';
33
import Grid from '@mui/material/Grid';
44
import Stack from '@mui/material/Stack';
5+
import { useMediaQuery } from '@mui/material';
6+
import { useTheme } from '@emotion/react';
57
// Component Imports
68
import { imageList } from './imageList';
79

8-
const TopImages = () => (
9-
<Grid
10-
container
11-
spacing={4}
12-
sx={{ justifyContent: 'center', alignItems: 'flex-end', paddingBottom: '10px' }}
13-
>
14-
{imageList.slice(0, 2).map(({ image, alt }) => (
15-
<Grid item key={alt}>
16-
<Box
17-
component="img"
18-
src={image}
19-
alt={alt}
20-
style={{ width: '200px', height: 'auto', borderRadius: '10px' }}
21-
/>
22-
</Grid>
23-
))}
24-
</Grid>
25-
);
10+
const TopImages = () => {
11+
const theme = useTheme();
2612

27-
const BottomImages = () => {
28-
// Shuffle array
29-
const shuffled = imageList.slice(2).sort(() => 0.5 - Math.random());
13+
const isMediumScreen = useMediaQuery(theme.breakpoints.down('md'));
3014

31-
// Get sub-array of first 3 elements after shuffled
32-
let selected = shuffled.slice(0, 3);
15+
return (
16+
<Grid
17+
container
18+
spacing={4}
19+
sx={{
20+
justifyContent: 'center',
21+
alignItems: 'flex-end',
22+
paddingBottom: '10px'
23+
}}
24+
>
25+
{imageList.slice(0, 2).map(({ image, alt }) => (
26+
<Grid item key={alt}>
27+
<Box
28+
component="img"
29+
src={image}
30+
alt={alt}
31+
style={{
32+
width: isMediumScreen ? '125px' : '200px',
33+
height: isMediumScreen ? '125px' : 'auto',
34+
borderRadius: '10px'
35+
}}
36+
/>
37+
</Grid>
38+
))}
39+
</Grid>
40+
);
41+
};
42+
43+
const BottomImages = ({ shuffledImages }) => {
44+
const theme = useTheme();
45+
46+
const isMediumScreen = useMediaQuery(theme.breakpoints.down('md'));
3347

3448
const heights = ['206px', '274px', '206px'];
3549
return (
36-
<Grid container spacing={4} sx={{ justifyContent: 'center', paddingTop: '20px' }}>
37-
{selected.map(({ image, alt }, index) => (
50+
<Grid
51+
container
52+
spacing={4}
53+
sx={{ justifyContent: 'center', paddingTop: '20px' }}
54+
>
55+
{shuffledImages.slice(0, 3).map(({ image, alt }, index) => (
3856
<Grid item key={alt}>
3957
<Box
4058
component="img"
4159
src={image}
4260
alt={alt}
4361
style={{
44-
width: '200px',
45-
height: heights[index],
62+
width: isMediumScreen ? '125px' : '200px',
63+
height: isMediumScreen ? '125px' : heights[index],
4664
borderRadius: '10px',
4765
objectFit: 'cover',
4866
objectPosition: 'top'
@@ -54,11 +72,15 @@ const BottomImages = () => {
5472
);
5573
};
5674

57-
const ImageSection = () => (
58-
<Stack>
59-
<TopImages />
60-
<BottomImages />
61-
</Stack>
62-
);
75+
const ImageSection = () => {
76+
// Shuffle array, first two images will be shown in TopImages
77+
const shuffledImages = imageList.slice(2).sort(() => 0.5 - Math.random());
78+
return (
79+
<Stack>
80+
<TopImages />
81+
<BottomImages shuffledImages={shuffledImages} />
82+
</Stack>
83+
)
84+
};
6385

6486
export default ImageSection;

0 commit comments

Comments
 (0)