Skip to content

Commit 12ae549

Browse files
Merge pull request #66 from EOS-uiux-Solutions/feat/gallery
Added basic gallery feature
2 parents 92d4d65 + e97069b commit 12ae549

File tree

8 files changed

+56
-26
lines changed

8 files changed

+56
-26
lines changed

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"react-helmet": "^6.1.0",
2222
"react-hook-form": "^6.3.2",
2323
"react-i18next": "^11.5.0",
24+
"react-image-gallery": "^1.2.5",
2425
"react-markdown": "^5.0.2",
2526
"react-markdown-editor-lite": "^1.2.4",
2627
"react-promise-tracker": "^2.1.0",

src/assets/scss/components/comments.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@
2525
font-weight: 100;
2626
}
2727
}
28+
29+
.comment-gallery-container {
30+
height: 20%;
31+
width: 20%;
32+
}
2833
}

src/assets/scss/index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
@import './modules/index';
66
@import './components/index';
77
@import './pages/index';
8+
@import '~react-image-gallery/styles/scss/image-gallery.scss';

src/assets/scss/pages/story.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@
2222
.share-button {
2323
margin-right: 2em;
2424
}
25+
26+
.gallery-container {
27+
height: 34%;
28+
width: 34%;
29+
}

src/components/Comments.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect, useContext, useCallback } from 'react'
22
import { Link } from '@reach/router'
33
import Button from './Button'
4+
import Gallery from './ImageGallery'
45

56
import CommentForm from './CommentForm'
67
import Context from '../modules/Context'
@@ -133,17 +134,13 @@ const Comments = (props) => {
133134
</div>
134135
</div>
135136
<p>{data.Comments}</p>
136-
<div>
137-
{data.attachment &&
138-
data.attachment.map((obj) => (
139-
<img
140-
src={obj.url}
141-
key={obj.id}
142-
alt='attachment'
143-
height='100'
144-
/>
145-
))}
146-
</div>
137+
{data.attachment.length !== 0 ? (
138+
<div className='comment-gallery-container'>
139+
<Gallery imageArray={data.attachment} />
140+
</div>
141+
) : (
142+
''
143+
)}
147144
<div className='reply-action'>
148145
{state.auth && (
149146
<Button
@@ -206,10 +203,13 @@ const Comments = (props) => {
206203
}
207204
</div>
208205
<p>{reply.Comments}</p>
209-
{reply.attachment &&
210-
reply.attachment.map((a) => (
211-
<img src={a.url} key={a.id} alt='' width='100' />
212-
))}
206+
{reply.attachment.length !== 0 ? (
207+
<div className='comment-gallery-container'>
208+
<Gallery imageArray={reply.attachment} />
209+
</div>
210+
) : (
211+
''
212+
)}
213213
</div>
214214
</div>
215215
))}

src/components/ImageGallery.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import ImageGallery from 'react-image-gallery'
3+
4+
const Gallery = ({ imageArray }) => {
5+
const images =
6+
imageArray?.map((attachment) => {
7+
return {
8+
original: attachment.url,
9+
thumbnail: attachment.url
10+
}
11+
}) ?? []
12+
13+
return <ImageGallery items={images} showBullets={true} />
14+
}
15+
16+
export default Gallery

src/pages/Story.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
TwitterIcon,
77
LinkedinIcon
88
} from 'react-share'
9+
import Gallery from '../components/ImageGallery'
910

1011
import { Helmet } from 'react-helmet'
1112

@@ -224,17 +225,13 @@ const Story = (props) => {
224225
/>
225226
)}
226227
</div>
227-
<div>
228-
{story.Attachment &&
229-
story.Attachment.map((obj) => (
230-
<img
231-
key={obj.id}
232-
src={obj.url}
233-
alt='attachment'
234-
height='100'
235-
/>
236-
))}
237-
</div>
228+
{story.Attachment.length !== 0 ? (
229+
<div className='gallery-container'>
230+
<Gallery imageArray={story.Attachment} />
231+
</div>
232+
) : (
233+
''
234+
)}
238235
<Comments storyId={storyId} />
239236
</div>
240237
</div>

0 commit comments

Comments
 (0)