function Gallery(props) {
let urls = randomImageByTopicsMap.get(props.id).map(obj => obj.img_url);
let captions = randomImageByTopicsMap.get(props.id).map(obj => obj.captions);
const columns = 2;
const [rows, setRows] = useState(1);
const images = urls.map((url, index) => ({
url,
caption: captions[index],
}));
useEffect(() => {
const totalImages = images.length;
const newRows = Math.ceil(totalImages / columns);
setRows(newRows);
}, [columns, images]);
const imageElements = images.map((image, index) => {
return React.createElement('div', {
key: index,
style: {
display: 'inline-block',
marginRight: '10px',
position: 'relative',
width: '200px',
height: '200px',
overflow: 'hidden',
},
}, [
React.createElement('img', {
key: 'img',
src: image.url,
style: {
width: '100%',
height: '100%',
objectFit: 'cover',
},
}),
React.createElement('div', {
key: 'caption',
style: {
position: 'absolute',
bottom: '0',
left: '0',
right: '0',
padding: '0px',
color: 'white',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
maxHeight: '50px',
overflowY: 'scroll',
whiteSpace: 'nowrap',
zIndex: 1,
},
}, image.caption),
]);
});
return React.createElement('div', {}, [
React.createElement('div', {
key: 'title',
style: {
fontSize: '18px',
fontWeight: 'bold',
marginBottom: '10px',
textAlign: "center",
},
}, `Image topic: #${props.id}`),
React.createElement('div', {
key: 'gallery',
style: {
width: '600px',
height: '220px',
overflowX: 'auto',
whiteSpace: 'nowrap',
},
}, imageElements),
]);
}