Skip to content

Commit

Permalink
fix: blur QR code until root is published (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki authored Nov 22, 2024
1 parent f9b0f74 commit 6ae98c9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
1 change: 1 addition & 0 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"labelIndividual": "Share individual files",
"labelAll": "Share all files",
"footNote": "This link changes if you add more files, so be sure to share the latest version.",
"publishing": "Publishing...",
"copy": "Share",
"copied": "Copied!",
"qrLabel": "Or scan to share all files"
Expand Down
11 changes: 9 additions & 2 deletions src/components/file/file.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ export const File = ({ file, isDownload }: { file: FileState, isDownload?: boole
const copyBtnClass = classnames({
'o-50 no-pointer-events': copied,
'o-80 glow pointer': !copied,
'o-50 no-pointer-events bg-gray': disabled
'o-50 no-pointer-events bg-gray w4': disabled
}, ['pa2 w3 flex items-center justify-center br-pill bg-aqua f7 fw5'])

let copyBtnTxt = t('copyLink.copy')
if (disabled) {
copyBtnTxt = t('copyLink.publishing')
} else if (copied) {
copyBtnTxt = t('copyLink.copied')
}

return (
<CopyToClipboard text={url} onCopy={handleOnCopyClick}>
<div className={copyBtnClass}>
{copied ? t('copyLink.copied') : t('copyLink.copy')}
{copyBtnTxt}
</div>
</CopyToClipboard>
)
Expand Down
45 changes: 27 additions & 18 deletions src/components/share-all-files/share-all-files.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classnames from 'classnames'
import { QRCodeSVG } from 'qrcode.react'
import React, { useCallback, useEffect, useMemo, useState } from 'react'
import React, { useCallback, useMemo, useState } from 'react'
import CopyToClipboard from 'react-copy-to-clipboard'
import { useTranslation } from 'react-i18next'
import { useFiles } from '../../hooks/use-files.js'
Expand Down Expand Up @@ -29,12 +29,12 @@ export const ShareAllFiles = ({ withLabel }: { withLabel?: boolean }): React.Rea
const shouldGenerateLink = useMemo(() => Object.keys(files).length > 0, [files])
const allFilesArePublished = useMemo(() => Object.values(files).every((file) => file.published), [files])

useEffect(() => {})
const disabled = !allFilesArePublished || !rootPublished

const copyBtnClass = classnames({
'o-50 no-pointer-events': copied,
'o-80 glow pointer': !copied,
'o-50 no-pointer-events bg-gray': !allFilesArePublished || !rootPublished
'o-50 no-pointer-events bg-gray navy w4': disabled
}, ['pa2 w3 flex items-center justify-center br-pill bg-navy f7 white'])

if (mfs == null || helia == null) {
Expand All @@ -49,6 +49,13 @@ export const ShareAllFiles = ({ withLabel }: { withLabel?: boolean }): React.Rea
return 'Preparing link...'
}

let copyBtnTxt = t('copyLink.copy')
if (disabled) {
copyBtnTxt = t('copyLink.publishing')
} else if (copied) {
copyBtnTxt = t('copyLink.copied')
}

return (
<div>
{ withLabel === true ? <div className='f5 montserrat fw4 charcoal mt4 mb1'>{t('copyLink.labelAll')}</div> : null }
Expand All @@ -61,27 +68,29 @@ export const ShareAllFiles = ({ withLabel }: { withLabel?: boolean }): React.Rea
</div>
<CopyToClipboard text={shareAllLink} onCopy={handleOnCopyClick}>
<div className={copyBtnClass}>
{ copied ? t('copyLink.copied') : t('copyLink.copy') }
{ copyBtnTxt }
</div>
</CopyToClipboard>
</div>
<div className="overflow-hidden">
<div className="flex flex-column items-center mb3 appear-from-below">
<span className="f7 charcoal-muted lh-copy pb2">{t('copyLink.qrLabel')}</span>
<QRCodeSVG
value={shareAllLink}
bgColor={'#ffffff'}
fgColor={'#022E44'}
level={'M'}
imageSettings={{
src: 'favicon-32x32.png',
x: 50,
y: 50,
height: 32,
width: 32,
excavate: true
}}
/>
<span style={ disabled ? { filter: 'blur(2px)' } : {} }>
<QRCodeSVG
value={shareAllLink}
bgColor={'#ffffff'}
fgColor={'#022E44'}
level={'M'}
imageSettings={{
src: 'favicon-32x32.png',
x: 50,
y: 50,
height: 32,
width: 32,
excavate: true
}}
/>
</span>
</div>
</div>
</div>
Expand Down

0 comments on commit 6ae98c9

Please sign in to comment.