Skip to content

Commit d7b2351

Browse files
authored
Merge pull request #26 from EOS-uiux-Solutions/feat/sharable-links
added feature to share/copy story link
2 parents bfd19b8 + 6bc554d commit d7b2351

File tree

6 files changed

+168
-35
lines changed

6 files changed

+168
-35
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@ name: Deploy site
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66

77
jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- name: Checkout repository code
13-
uses: actions/checkout@v2
12+
- name: Checkout repository code
13+
uses: actions/checkout@v2
1414

15-
- name: Cache node_modules
16-
id: cache-node-modules
17-
uses: actions/cache@v2
18-
with:
19-
path: node_modules
20-
key: node_modules-deploy-${{ hashFiles('package-lock.json') }}
15+
- name: Cache node_modules
16+
id: cache-node-modules
17+
uses: actions/cache@v2
18+
with:
19+
path: node_modules
20+
key: node_modules-deploy-${{ hashFiles('package-lock.json') }}
2121

22-
- name: Install node modules
23-
if: steps.cache-node-modules.outputs.cache-hit != 'true'
24-
run: npm install
22+
- name: Install node modules
23+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
24+
run: npm install
2525

26-
- name: Build the site
27-
run: |
28-
echo "$CONFIG_JSON" > src/config.json
29-
npm run build
30-
cp build/index.html build/404.html
31-
env:
32-
CONFIG_JSON: ${{ secrets.CONFIG_JSON }}
26+
- name: Build the site
27+
run: |
28+
echo "$CONFIG_JSON" > src/config.json
29+
npm run build
30+
cp build/index.html build/404.html
31+
env:
32+
CONFIG_JSON: ${{ secrets.CONFIG_JSON }}
3333

34-
- name: Deploy
35-
uses: s0/git-publish-subdir-action@develop
36-
env:
37-
REPO: self
38-
BRANCH: gh-pages
39-
FOLDER: build
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
- name: Deploy
35+
uses: s0/git-publish-subdir-action@develop
36+
env:
37+
REPO: self
38+
BRANCH: gh-pages
39+
FOLDER: build
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/github-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Run Tests
22

3-
on: [ push, pull_request ]
3+
on: [push, pull_request]
44

55
jobs:
66
cache_node_modules:
@@ -16,7 +16,7 @@ jobs:
1616
with:
1717
path: node_modules
1818
key: node_modules-${{ hashFiles('package-lock.json') }}
19-
19+
2020
- name: Install dependencies
2121
if: steps.cache-node-modules.outputs.cache-hit != 'true'
2222
run: npm install

package-lock.json

Lines changed: 37 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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"react-markdown": "^5.0.2",
2525
"react-promise-tracker": "^2.1.0",
2626
"react-router-dom": "^5.2.0",
27-
"react-scripts": "3.4.1"
27+
"react-scripts": "3.4.1",
28+
"react-share": "^4.4.0"
2829
},
2930
"devDependencies": {
3031
"cypress": "^4.12.1",

src/assets/scss/pages/story.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@
1111
padding-right: 6em;
1212
}
1313
}
14+
15+
.share-story {
16+
background-color: transparent;
17+
border: 0;
18+
cursor: pointer;
19+
margin-left: 1em;
20+
}
21+
22+
.share-button {
23+
margin-right: 2em;
24+
}

src/pages/Story.js

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import ClassicEditor from '@ckeditor/ckeditor5-build-classic'
44
import axios from 'axios'
55
import { apiURL } from '../config.json'
66
import { trackPromise, usePromiseTracker } from 'react-promise-tracker'
7+
import {
8+
FacebookShareButton,
9+
TwitterShareButton,
10+
LinkedinShareButton,
11+
WhatsappShareButton,
12+
FacebookIcon,
13+
TwitterIcon,
14+
LinkedinIcon,
15+
WhatsappIcon
16+
} from 'react-share'
717

818
import { Helmet } from 'react-helmet'
919

@@ -14,6 +24,7 @@ import LoadingIndicator from '../modules/LoadingIndicator'
1424
import Navigation from '../components/Navigation'
1525
import { Link, navigate } from '@reach/router'
1626
import Vote from '../components/Vote'
27+
import Modal from '../components/Modal'
1728

1829
const Story = (props) => {
1930
const { storyId } = props
@@ -30,6 +41,12 @@ const Story = (props) => {
3041

3142
const { promiseInProgress } = usePromiseTracker()
3243

44+
const [isOpen, setIsOpen] = useState(false)
45+
46+
const togglePopup = () => {
47+
setIsOpen(!isOpen)
48+
}
49+
3350
useEffect(() => {
3451
const fetchStory = async () => {
3552
const response = await axios.post(
@@ -114,6 +131,20 @@ const Story = (props) => {
114131
return null
115132
}
116133

134+
const copy = () => {
135+
const dummy = document.createElement('input')
136+
const text = window.location.href
137+
138+
document.body.appendChild(dummy)
139+
dummy.value = text
140+
dummy.select()
141+
document.execCommand('copy')
142+
document.body.removeChild(dummy)
143+
}
144+
145+
const hashtagsArray = ['EOS', 'userstory']
146+
const title = 'EOS User Story - POST Stories. GET Features.'
147+
117148
return (
118149
<>
119150
<Helmet>
@@ -184,12 +215,20 @@ const Story = (props) => {
184215
)}
185216
<div className='story-buttons-container'>
186217
{editMode && !editor ? (
187-
<Button
188-
className='btn btn-default'
189-
onClick={() => setEditor(true)}
190-
>
191-
Edit
192-
</Button>
218+
<>
219+
<Button
220+
className='btn btn-default'
221+
onClick={() => setEditor(true)}
222+
>
223+
Edit
224+
</Button>
225+
<Button className='share-story' onClick={togglePopup}>
226+
<i className='eos-icons'> share </i>
227+
</Button>
228+
<Button className='share-story' onClick={copy}>
229+
<i className='eos-icons'>content_copy</i>
230+
</Button>
231+
</>
193232
) : (
194233
''
195234
)}
@@ -210,6 +249,51 @@ const Story = (props) => {
210249
) : (
211250
''
212251
)}
252+
{isOpen && (
253+
<Modal
254+
content={
255+
<>
256+
<h1>Share</h1>
257+
<FacebookShareButton
258+
url={window.location}
259+
className='share-button'
260+
quote={title}
261+
hashtag={'#EOS'}
262+
onShareWindowClose={togglePopup}
263+
>
264+
<FacebookIcon />
265+
</FacebookShareButton>
266+
<TwitterShareButton
267+
url={window.location}
268+
className='share-button'
269+
title={title}
270+
hashtags={hashtagsArray}
271+
onShareWindowClose={togglePopup}
272+
>
273+
<TwitterIcon />
274+
</TwitterShareButton>
275+
<LinkedinShareButton
276+
url={window.location}
277+
className='share-button'
278+
onShareWindowClose={togglePopup}
279+
>
280+
<LinkedinIcon />
281+
</LinkedinShareButton>
282+
<WhatsappShareButton
283+
url={window.location}
284+
className='share-button'
285+
title={title}
286+
separator=' '
287+
onShareWindowClose={togglePopup}
288+
>
289+
<WhatsappIcon />
290+
</WhatsappShareButton>
291+
</>
292+
}
293+
handleClose={togglePopup}
294+
active={isOpen}
295+
/>
296+
)}
213297
</div>
214298
<Comments storyId={storyId} />
215299
</div>

0 commit comments

Comments
 (0)