Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File info modal CID and Key copy arrangements #1773

Merged
merged 4 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CustomButton from "../../Elements/CustomButton"
import { Trans } from "@lingui/macro"
import { FileFullInfo } from "../../../Contexts/FilesContext"
import {
Button,
CopyIcon,
formatBytes,
Grid,
Loading,
Expand Down Expand Up @@ -44,7 +44,6 @@ const useStyles = makeStyles(
},
closeButton: {
flex: 1,
marginLeft: constants.generalUnit * 2,
[breakpoints.down("md")]: {
position: "fixed",
bottom: 0,
Expand All @@ -61,13 +60,6 @@ const useStyles = makeStyles(
textAlign: "center"
}
},
heading: {
fontWeight: typography.fontWeight.semibold,
textAlign: "left",
[breakpoints.down("md")]: {
textAlign: "center"
}
},
infoHeading: {
fontWeight: typography.fontWeight.semibold,
textAlign: "left"
Expand All @@ -89,7 +81,8 @@ const useStyles = makeStyles(
color: palette.additional["gray"][8],
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
textOverflow: "ellipsis",
marginRight: constants.generalUnit * 2
},
technicalContainer: {
paddingTop: constants.generalUnit,
Expand All @@ -114,7 +107,7 @@ const useStyles = makeStyles(
alignItems: "center",
justifyContent: "center",
left: "50%",
bottom: "calc(100% + 5px)",
bottom: "calc(100% + 8px)",
position: "absolute",
transform: "translate(-50%, 0%)",
zIndex: zIndex?.layer1,
Expand Down Expand Up @@ -143,17 +136,20 @@ const useStyles = makeStyles(
visibility: "visible"
}
},
copyButton: {
width: "100%"
},
copyContainer: {
position: "relative",
flexBasis: "75%",
color: palette.additional["gray"][9],
position: "relative"
},
copyIcon: {
fontSize: "16px",
fill: palette.additional["gray"][9],
[breakpoints.down("md")]: {
flexBasis: "100%",
margin: `${constants.generalUnit * 2}px`
fontSize: "18px",
fill: palette.additional["gray"][9]
}
},
copyRow: {
display: "flex",
cursor: "pointer"
}
})
}
Expand Down Expand Up @@ -186,15 +182,27 @@ const FileInfoModal = ({ filePath, close }: IFileInfoModuleProps) => {
}
, [bucket, filePath, filesApiClient])

const [copied, setCopied] = useState(false)
const debouncedSwitchCopied = debounce(() => setCopied(false), 3000)
const [copiedCID, setCopiedCID] = useState(false)
const [copiedKey, setCopiedKey] = useState(false)
const debouncedSwitchCopiedCID = debounce(() => setCopiedCID(false), 3000)
const debouncedSwitchCopiedKey = debounce(() => setCopiedKey(false), 3000)

const onCopyCID = () => {
if (fullFileInfo?.content?.cid) {
navigator.clipboard.writeText(fullFileInfo?.content?.cid)
navigator.clipboard.writeText(fullFileInfo.content.cid)
.then(() => {
setCopiedCID(true)
debouncedSwitchCopiedCID()
}).catch(console.error)
}
}

const onCopyKey = () => {
if (bucket?.encryptionKey) {
navigator.clipboard.writeText(bucket.encryptionKey)
.then(() => {
setCopied(true)
debouncedSwitchCopied()
setCopiedKey(true)
debouncedSwitchCopiedKey()
}).catch(console.error)
}
}
Expand Down Expand Up @@ -360,13 +368,27 @@ const FileInfoModal = ({ filePath, close }: IFileInfoModuleProps) => {
<Trans>CID (Content Identifier)</Trans>
</Typography>
</Grid>
<Typography
className={classes.subSubtitle}
variant="body2"
component="p"
<div onClick={onCopyCID}
className={classes.copyRow}
>
{fullFileInfo.content?.cid}
</Typography>
<Typography
className={classes.subSubtitle}
variant="body2"
component="p"
>
{fullFileInfo.content?.cid}
</Typography>
<div className={classes.copyContainer}>
<CopyIcon className={classes.copyIcon} />
<div className={clsx(classes.copiedFlag, { "active": copiedCID })}>
<span>
<Trans>
Copied!
</Trans>
</span>
</div>
</div>
</div>
</div>
<div className={classes.subInfoBox}>
<Grid
Expand All @@ -380,15 +402,29 @@ const FileInfoModal = ({ filePath, close }: IFileInfoModuleProps) => {
<Trans>Decryption key</Trans>
</Typography>
</Grid>
<Typography
className={classes.subSubtitle}
variant="body2"
component="p"
<div onClick={onCopyKey}
className={classes.copyRow}
>
<ToggleHiddenText hiddenLength={14}>
<span>{bucket?.encryptionKey}</span>
</ToggleHiddenText>
</Typography>
<Typography
className={classes.subSubtitle}
variant="body2"
component="p"
>
<ToggleHiddenText hiddenLength={14}>
<span>{bucket?.encryptionKey}</span>
</ToggleHiddenText>
</Typography>
<div className={classes.copyContainer}>
<CopyIcon className={classes.copyIcon} />
<div className={clsx(classes.copiedFlag, { "active": copiedKey })}>
<span>
<Trans>
Copied!
</Trans>
</span>
</div>
</div>
</div>
</div>
</div>
</div>
Expand All @@ -398,24 +434,6 @@ const FileInfoModal = ({ filePath, close }: IFileInfoModuleProps) => {
flexDirection="row"
className={classes.buttonsContainer}
>
<div className={classes.copyContainer}>
<Button
type="submit"
size="large"
variant="primary"
className={classes.copyButton}
onClick={onCopyCID}
>
<Trans>Copy CID</Trans>
</Button>
<div className={clsx(classes.copiedFlag, { "active": copied })}>
<span>
<Trans>
Copied!
</Trans>
</span>
</div>
</div>
<CustomButton
onClick={() => close()}
size="large"
Expand Down
3 changes: 0 additions & 3 deletions packages/files-ui/src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ msgstr "Weiter mit Web3 Wallet"
msgid "Copied!"
msgstr "Kopiert!"

msgid "Copy CID"
msgstr "IID kopieren"

msgid "Copy file"
msgstr ""

Expand Down
3 changes: 0 additions & 3 deletions packages/files-ui/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ msgstr "Continue with Web3 Wallet"
msgid "Copied!"
msgstr "Copied!"

msgid "Copy CID"
msgstr "Copy CID"

msgid "Copy file"
msgstr "Copy file"

Expand Down
3 changes: 0 additions & 3 deletions packages/files-ui/src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ msgstr "Continuar con Monedero Web3 "
msgid "Copied!"
msgstr "Copiado!"

msgid "Copy CID"
msgstr "Copiar CID"

msgid "Copy file"
msgstr ""

Expand Down
3 changes: 0 additions & 3 deletions packages/files-ui/src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ msgstr "Continuer avec un wallet Web3"
msgid "Copied!"
msgstr "Copié !"

msgid "Copy CID"
msgstr "Copier le CID"

msgid "Copy file"
msgstr "Copier le fichier"

Expand Down
3 changes: 0 additions & 3 deletions packages/files-ui/src/locales/no/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ msgstr "Fortsett med Web3-lommebok"
msgid "Copied!"
msgstr "Kopiert!"

msgid "Copy CID"
msgstr "Kopier CID"

msgid "Copy file"
msgstr ""

Expand Down