From 6ae98c99a1955ef2a20f387005d1661575e77b70 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:11:03 -0600 Subject: [PATCH] fix: blur QR code until root is published (#144) --- public/locales/en/translation.json | 1 + src/components/file/file.tsx | 11 ++++- .../share-all-files/share-all-files.tsx | 45 +++++++++++-------- 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 3a51827..93ac3c5 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -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" diff --git a/src/components/file/file.tsx b/src/components/file/file.tsx index 255574e..2724655 100644 --- a/src/components/file/file.tsx +++ b/src/components/file/file.tsx @@ -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 (
- {copied ? t('copyLink.copied') : t('copyLink.copy')} + {copyBtnTxt}
) diff --git a/src/components/share-all-files/share-all-files.tsx b/src/components/share-all-files/share-all-files.tsx index 36a9094..84457c2 100644 --- a/src/components/share-all-files/share-all-files.tsx +++ b/src/components/share-all-files/share-all-files.tsx @@ -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' @@ -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) { @@ -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 (
{ withLabel === true ?
{t('copyLink.labelAll')}
: null } @@ -61,27 +68,29 @@ export const ShareAllFiles = ({ withLabel }: { withLabel?: boolean }): React.Rea
- { copied ? t('copyLink.copied') : t('copyLink.copy') } + { copyBtnTxt }
{t('copyLink.qrLabel')} - + + +