mirror of
https://github.com/kremalicious/blog.git
synced 2024-11-22 18:00:06 +01:00
post actions refactor
This commit is contained in:
parent
2a31adc585
commit
ba75eca2e6
10
package.json
10
package.json
@ -35,18 +35,18 @@
|
|||||||
"dms2dec": "^1.1.0",
|
"dms2dec": "^1.1.0",
|
||||||
"fast-exif": "^1.0.1",
|
"fast-exif": "^1.0.1",
|
||||||
"fraction.js": "^4.0.12",
|
"fraction.js": "^4.0.12",
|
||||||
"gatsby": "^2.17.5",
|
"gatsby": "^2.17.6",
|
||||||
"gatsby-image": "^2.2.30",
|
"gatsby-image": "^2.2.30",
|
||||||
"gatsby-plugin-catch-links": "^2.1.15",
|
"gatsby-plugin-catch-links": "^2.1.15",
|
||||||
"gatsby-plugin-feed": "^2.3.19",
|
"gatsby-plugin-feed": "^2.3.19",
|
||||||
"gatsby-plugin-lunr": "^1.5.2",
|
"gatsby-plugin-lunr": "^1.5.2",
|
||||||
"gatsby-plugin-manifest": "^2.2.24",
|
"gatsby-plugin-manifest": "^2.2.25",
|
||||||
"gatsby-plugin-matomo": "^0.7.2",
|
"gatsby-plugin-matomo": "^0.7.2",
|
||||||
"gatsby-plugin-meta-redirect": "^1.1.1",
|
"gatsby-plugin-meta-redirect": "^1.1.1",
|
||||||
"gatsby-plugin-offline": "^3.0.17",
|
"gatsby-plugin-offline": "^3.0.17",
|
||||||
"gatsby-plugin-react-helmet": "^3.1.13",
|
"gatsby-plugin-react-helmet": "^3.1.13",
|
||||||
"gatsby-plugin-sass": "^2.1.20",
|
"gatsby-plugin-sass": "^2.1.20",
|
||||||
"gatsby-plugin-sharp": "^2.2.33",
|
"gatsby-plugin-sharp": "^2.2.34",
|
||||||
"gatsby-plugin-sitemap": "^2.2.19",
|
"gatsby-plugin-sitemap": "^2.2.19",
|
||||||
"gatsby-plugin-svgr": "^2.0.2",
|
"gatsby-plugin-svgr": "^2.0.2",
|
||||||
"gatsby-plugin-typescript": "^2.1.15",
|
"gatsby-plugin-typescript": "^2.1.15",
|
||||||
@ -58,9 +58,9 @@
|
|||||||
"gatsby-remark-images": "^3.1.28",
|
"gatsby-remark-images": "^3.1.28",
|
||||||
"gatsby-remark-smartypants": "^2.1.14",
|
"gatsby-remark-smartypants": "^2.1.14",
|
||||||
"gatsby-remark-vscode": "^1.2.0",
|
"gatsby-remark-vscode": "^1.2.0",
|
||||||
"gatsby-source-filesystem": "^2.1.34",
|
"gatsby-source-filesystem": "^2.1.35",
|
||||||
"gatsby-source-graphql": "^2.1.21",
|
"gatsby-source-graphql": "^2.1.21",
|
||||||
"gatsby-transformer-remark": "^2.6.31",
|
"gatsby-transformer-remark": "^2.6.32",
|
||||||
"gatsby-transformer-sharp": "^2.3.1",
|
"gatsby-transformer-sharp": "^2.3.1",
|
||||||
"graphql": "^14.5.8",
|
"graphql": "^14.5.8",
|
||||||
"intersection-observer": "^0.7.0",
|
"intersection-observer": "^0.7.0",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import ExifMap from './ExifMap'
|
import ExifMap from './ExifMap'
|
||||||
import styles from './Exif.module.scss'
|
import styles from './Exif.module.scss'
|
||||||
import { Exif as ExifMeta } from '../../@types/Post'
|
import { Exif as ExifMeta } from '../../@types/Image'
|
||||||
|
|
||||||
export default function Exif({ exif }: { exif: ExifMeta }) {
|
export default function Exif({ exif }: { exif: ExifMeta }) {
|
||||||
const { iso, model, fstop, shutterspeed, focalLength, exposure, gps } = exif
|
const { iso, model, fstop, shutterspeed, focalLength, exposure, gps } = exif
|
||||||
|
@ -16,44 +16,34 @@ export const alertMessages = (
|
|||||||
success: 'Confirmed. You are awesome, thanks!'
|
success: 'Confirmed. You are awesome, thanks!'
|
||||||
})
|
})
|
||||||
|
|
||||||
export default function Alerts({
|
interface AlertProps {
|
||||||
transactionHash,
|
transactionHash: string
|
||||||
message
|
message?: { text?: string; status?: string }
|
||||||
}: {
|
}
|
||||||
transactionHash: string | null
|
|
||||||
message: { text?: string; status?: string } | null
|
|
||||||
}) {
|
|
||||||
const constructMessage = () => {
|
|
||||||
let messageOutput
|
|
||||||
|
|
||||||
if (transactionHash) {
|
const constructMessage = (
|
||||||
messageOutput =
|
transactionHash: string,
|
||||||
message &&
|
message?: { text?: string }
|
||||||
message.text +
|
) =>
|
||||||
'<br />' +
|
transactionHash
|
||||||
alertMessages(null, transactionHash).transaction
|
? message &&
|
||||||
} else {
|
message.text + '<br />' + alertMessages(null, transactionHash).transaction
|
||||||
messageOutput = message && message.text
|
: message && message.text
|
||||||
}
|
|
||||||
|
|
||||||
return messageOutput
|
const classes = (status: string) =>
|
||||||
}
|
status === 'success'
|
||||||
|
? styles.success
|
||||||
const classes = () => {
|
: status === 'error'
|
||||||
const { status } = message
|
? styles.error
|
||||||
|
: styles.alert
|
||||||
if (status === 'success') {
|
|
||||||
return styles.success
|
|
||||||
} else if (status === 'error') {
|
|
||||||
return styles.error
|
|
||||||
}
|
|
||||||
return styles.alert
|
|
||||||
}
|
|
||||||
|
|
||||||
|
export default function Alerts({ transactionHash, message }: AlertProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={classes()}
|
className={classes(message.status)}
|
||||||
dangerouslySetInnerHTML={{ __html: `${constructMessage()}` }}
|
dangerouslySetInnerHTML={{
|
||||||
|
__html: `${constructMessage(transactionHash, message)}`
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,11 @@ import React, { lazy, Suspense } from 'react'
|
|||||||
import shortid from 'shortid'
|
import shortid from 'shortid'
|
||||||
import { Author } from '../../@types/Site'
|
import { Author } from '../../@types/Site'
|
||||||
import { useSiteMetadata } from '../../hooks/use-site-metadata'
|
import { useSiteMetadata } from '../../hooks/use-site-metadata'
|
||||||
|
import Qr from '../atoms/Qr'
|
||||||
import Modal from '../atoms/Modal'
|
import Modal from '../atoms/Modal'
|
||||||
import styles from './ModalThanks.module.scss'
|
import styles from './ModalThanks.module.scss'
|
||||||
|
|
||||||
const Web3Donation = lazy(() => import('../molecules/Web3Donation'))
|
const Web3Donation = lazy(() => import('../molecules/Web3Donation'))
|
||||||
const Qr = lazy(() => import('../atoms/Qr'))
|
|
||||||
|
|
||||||
const Coin = ({ address, author }: { address: string; author: Author }) => (
|
const Coin = ({ address, author }: { address: string; author: Author }) => (
|
||||||
<div className={styles.coin}>
|
<div className={styles.coin}>
|
||||||
|
@ -9,32 +9,16 @@
|
|||||||
padding-top: $spacer;
|
padding-top: $spacer;
|
||||||
padding-bottom: $spacer;
|
padding-bottom: $spacer;
|
||||||
border-radius: $border-radius;
|
border-radius: $border-radius;
|
||||||
display: flex;
|
display: grid;
|
||||||
flex-wrap: wrap;
|
gap: $spacer / 2;
|
||||||
justify-content: space-between;
|
|
||||||
|
@media (min-width: $screen-sm) {
|
||||||
|
grid-template-columns: repeat(3, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
:global(.dark) & {
|
:global(.dark) & {
|
||||||
background: darken($body-background-color--dark, 2%);
|
background: darken($body-background-color--dark, 2%);
|
||||||
}
|
}
|
||||||
|
|
||||||
> div {
|
|
||||||
flex: 1 1 100%;
|
|
||||||
border-bottom: 1px dashed rgba($brand-grey-light, 0.3);
|
|
||||||
|
|
||||||
&:last-child {
|
|
||||||
border-bottom: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (min-width: $screen-sm) {
|
|
||||||
flex: 0 0 33%;
|
|
||||||
border-bottom: 0;
|
|
||||||
border-left: 1px dashed rgba($brand-grey-light, 0.3);
|
|
||||||
|
|
||||||
&:first-child {
|
|
||||||
border-left: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.link {
|
.link {
|
||||||
@ -66,9 +50,25 @@
|
|||||||
padding-right: $spacer;
|
padding-right: $spacer;
|
||||||
position: relative;
|
position: relative;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
border-bottom: 1px dashed rgba($brand-grey-light, 0.3);
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: $screen-sm) {
|
||||||
|
border-bottom: 0;
|
||||||
|
border-left: 1px dashed rgba($brand-grey-light, 0.3);
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
border-left: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&:hover,
|
&:hover,
|
||||||
&:focus {
|
&:focus {
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
.link,
|
.link,
|
||||||
.actionTitle,
|
.actionTitle,
|
||||||
.actionText {
|
.actionText {
|
||||||
|
@ -7,47 +7,32 @@ import { ReactComponent as Bitcoin } from '../../images/bitcoin.svg'
|
|||||||
import { ReactComponent as GitHub } from '../../images/github.svg'
|
import { ReactComponent as GitHub } from '../../images/github.svg'
|
||||||
import { useSiteMetadata } from '../../hooks/use-site-metadata'
|
import { useSiteMetadata } from '../../hooks/use-site-metadata'
|
||||||
|
|
||||||
const ActionContent = ({ title, text }: { title: string; text: string }) => (
|
interface ActionProps {
|
||||||
<>
|
title: string
|
||||||
<h1 className={styles.actionTitle}>{title}</h1>
|
text: string
|
||||||
<p className={styles.actionText}>{text}</p>
|
url?: string
|
||||||
</>
|
onClick?(): void
|
||||||
)
|
}
|
||||||
|
|
||||||
const ActionTwitter = ({ slug }: { slug: string }) => {
|
const Icon = ({ text }: { text: string }) =>
|
||||||
const { siteUrl } = useSiteMetadata()
|
text.includes('GitHub') ? (
|
||||||
|
<GitHub />
|
||||||
|
) : text.includes('Bitcoin') ? (
|
||||||
|
<Bitcoin />
|
||||||
|
) : (
|
||||||
|
<Twitter />
|
||||||
|
)
|
||||||
|
|
||||||
|
const Action = ({ title, text, url, onClick }: ActionProps) => {
|
||||||
return (
|
return (
|
||||||
<a
|
<a className={styles.action} href={url} onClick={onClick}>
|
||||||
className={styles.action}
|
<Icon text={text} />
|
||||||
href={`https://twitter.com/intent/tweet?text=@kremalicious&url=${siteUrl}${slug}`}
|
<h1 className={styles.actionTitle}>{title}</h1>
|
||||||
>
|
<p className={styles.actionText}>{text}</p>
|
||||||
<Twitter />
|
|
||||||
<ActionContent title="Have a comment?" text="Hit me up @kremalicious" />
|
|
||||||
</a>
|
</a>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const ActionCrypto = ({ toggleModal }: { toggleModal(): void }) => (
|
|
||||||
<button className={styles.action} onClick={toggleModal}>
|
|
||||||
<Bitcoin />
|
|
||||||
<ActionContent
|
|
||||||
title="Found something useful?"
|
|
||||||
text="Say thanks with Bitcoins or Ether"
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
|
|
||||||
const ActionGitHub = ({ githubLink }: { githubLink: string }) => (
|
|
||||||
<a className={styles.action} href={githubLink}>
|
|
||||||
<GitHub />
|
|
||||||
<ActionContent
|
|
||||||
title="Edit on GitHub"
|
|
||||||
text="Contribute to this post on GitHub"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
)
|
|
||||||
|
|
||||||
export default function PostActions({
|
export default function PostActions({
|
||||||
slug,
|
slug,
|
||||||
githubLink
|
githubLink
|
||||||
@ -55,7 +40,9 @@ export default function PostActions({
|
|||||||
slug: string
|
slug: string
|
||||||
githubLink: string
|
githubLink: string
|
||||||
}) {
|
}) {
|
||||||
|
const { siteUrl } = useSiteMetadata()
|
||||||
const [showModal, setShowModal] = useState(false)
|
const [showModal, setShowModal] = useState(false)
|
||||||
|
const urlTwitter = `https://twitter.com/intent/tweet?text=@kremalicious&url=${siteUrl}${slug}`
|
||||||
|
|
||||||
const toggleModal = () => {
|
const toggleModal = () => {
|
||||||
setShowModal(!showModal)
|
setShowModal(!showModal)
|
||||||
@ -63,17 +50,21 @@ export default function PostActions({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className={styles.actions}>
|
<aside className={styles.actions}>
|
||||||
<div>
|
<Action
|
||||||
<ActionTwitter slug={slug} />
|
title="Have a comment?"
|
||||||
</div>
|
text="Hit me up @kremalicious"
|
||||||
|
url={urlTwitter}
|
||||||
<div>
|
/>
|
||||||
<ActionCrypto toggleModal={toggleModal} />
|
<Action
|
||||||
</div>
|
title="Found something useful?"
|
||||||
|
text="Say thanks with Bitcoins or Ether"
|
||||||
<div>
|
onClick={toggleModal}
|
||||||
<ActionGitHub githubLink={githubLink} />
|
/>
|
||||||
</div>
|
<Action
|
||||||
|
title="Edit on GitHub"
|
||||||
|
text="Contribute to this post on GitHub"
|
||||||
|
url={githubLink}
|
||||||
|
/>
|
||||||
|
|
||||||
{showModal && (
|
{showModal && (
|
||||||
<ModalThanks isOpen={showModal} handleCloseModal={toggleModal} />
|
<ModalThanks isOpen={showModal} handleCloseModal={toggleModal} />
|
||||||
|
Loading…
Reference in New Issue
Block a user