Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Social media share buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
mustofa-id committed Jul 12, 2019
1 parent 8d60d7b commit d351d8e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/components/widget/share-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react'
import IconButton from './icon-button'

const links = {
facebook: 'https://www.facebook.com/sharer/sharer.php?u=',
twitter: 'https://twitter.com/share?url=',
telegram: 'https://telegram.me/share/?url=',
whatsapp: 'https://api.whatsapp.com/send?text=',
pinterest: 'https://pinterest.com/pin/create/button/?url='
}

export const ShareButton = ({ type, url, ...wrapperProps }) => (
<IconButton icon={type} to={links[type] + url} {...wrapperProps} />
)

export const ShareButtons = ({ url, ...wrapperProps }) => (
<>
{Object.keys(links).map((k, i) => (
<ShareButton key={`${k}--${i}`} type={k} url={url} {...wrapperProps} />
))}
</>
)
11 changes: 10 additions & 1 deletion src/templates/blog-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
import { hashCode, queryType } from '../shared/util'
import BottomSheet from '../components/widget/bottom-sheet'
import Toast from '../components/widget/toast'
import { ShareButtons } from '../components/widget/share-button'

const paramType = 'blog'

const BlogPost = ({ data, pageContext }) => {
const BlogPost = ({ data, pageContext, location }) => {
// All fileds post
const { excerpt, frontmatter, html, timeToRead, fields } = data.blog
const { title, date, tags, category, cover } = frontmatter
Expand Down Expand Up @@ -88,6 +89,14 @@ const BlogPost = ({ data, pageContext }) => {
<LoveContext.Provider value={{ state, dispatch }}>
<BottomSheet pageContext={pageContext} title={title} />
</LoveContext.Provider>
{/* Social media share */}
<p className='has-text-centered'>
<ShareButtons
url={location.href}
iconSize='24'
buttonClass='is-white has-text-grey'
/>
</p>
</div>
</div>
</div>
Expand Down
11 changes: 10 additions & 1 deletion src/templates/gallery-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import {
} from '../store/love-reducer'
import { hashCode, queryType } from '../shared/util'
import Toast from '../components/widget/toast'
import { ShareButtons } from '../components/widget/share-button'

const paramType = 'gallery'

const GalleryPost = ({ data, pageContext }) => {
const GalleryPost = ({ data, pageContext, location }) => {
// All fileds post
const { excerpt, frontmatter, html, timeToRead, fields } = data.gallery
const { title, date, tags, category, cover } = frontmatter
Expand Down Expand Up @@ -84,6 +85,14 @@ const GalleryPost = ({ data, pageContext }) => {
<LoveContext.Provider value={{ state, dispatch }}>
<BottomSheet pageContext={pageContext} title={title} />
</LoveContext.Provider>
{/* Social media share */}
<p className='has-text-centered'>
<ShareButtons
url={location.href}
iconSize='24'
buttonClass='is-white has-text-grey'
/>
</p>
</div>
</div>
</div>
Expand Down

0 comments on commit d351d8e

Please sign in to comment.