Skip to content
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
84 changes: 44 additions & 40 deletions components/CliVotingInstructionsDialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import {
DialogTitle,
Flex,
Heading,
useSnackbar,
} from "@livepeer/design-system";
import copy from "copy-to-clipboard";
import { useEffect, useState } from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";

import Check from "../../public/img/check.svg";
import Copy from "../../public/img/copy.svg";
Expand All @@ -28,7 +27,6 @@ const CliVotingInstructionsDialog = ({
}: Props) => {
const [copied, setCopied] = useState(false);
const [modalOpen, setModalOpen] = useState(false);
const [openSnackbar] = useSnackbar();

useEffect(() => {
if (copied) {
Expand All @@ -39,6 +37,12 @@ const CliVotingInstructionsDialog = ({
}
}, [copied]);

const handleCopy = () => {
if (copy(voteId)) {
setCopied(true);
}
};

return (
<>
<Box
Expand Down Expand Up @@ -100,6 +104,7 @@ const CliVotingInstructionsDialog = ({
<Box
css={{
padding: "$3",
paddingRight: 48,
marginBottom: "$2",
position: "relative",
color: "$primary11",
Expand All @@ -110,45 +115,44 @@ const CliVotingInstructionsDialog = ({
}}
>
{voteId}
<CopyToClipboard
text={voteId}
onCopy={() => {
setCopied(true);
openSnackbar("Copied to clipboard");
<Flex
as="button"
type="button"
aria-label={`Copy ${idLabel}`}
onClick={handleCopy}
css={{
marginLeft: "$2",
marginTop: "3px",
position: "absolute",
right: 12,
top: 10,
cursor: "pointer",
border: "none",
background: "none",
borderRadius: 1000,
padding: 0,
width: 26,
height: 26,
alignItems: "center",
justifyContent: "center",
}}
>
<Flex
css={{
marginLeft: "$2",
marginTop: "3px",
position: "absolute",
right: 12,
top: 10,
cursor: "pointer",
borderRadius: 1000,
width: 26,
height: 26,
alignItems: "center",
justifyContent: "center",
}}
>
{copied ? (
<Check
css={{
width: 12,
height: 12,
}}
/>
) : (
<Copy
css={{
width: 12,
height: 12,
}}
/>
)}
</Flex>
</CopyToClipboard>
{copied ? (
<Check
css={{
width: 12,
height: 12,
}}
/>
) : (
<Copy
css={{
width: 12,
height: 12,
}}
/>
)}
</Flex>
</Box>
</Box>
<Box as="li" css={{ marginBottom: "$4" }}>
Expand Down
17 changes: 13 additions & 4 deletions components/CodeBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ export function CodeBlock({
}, [preRef]);

useEffect(() => {
if (hasCopied && code) copy(code);
setTimeout(() => setHasCopied(false), 1500);
}, [code, hasCopied]);
if (!hasCopied) return;
const timer = setTimeout(() => setHasCopied(false), 1500);
return () => clearTimeout(timer);
}, [hasCopied]);

const handleCopy = () => {
if (!code) return;

if (copy(code)) {
setHasCopied(true);
}
};

return (
<Box
Expand Down Expand Up @@ -84,7 +93,7 @@ export function CodeBlock({
transition: "background-color .3s",
},
}}
onClick={() => setHasCopied(true)}
onClick={handleCopy}
>
{hasCopied ? <CheckIcon /> : <ClipboardIcon />}
</IconButton>
Expand Down
117 changes: 63 additions & 54 deletions components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {
GlobeIcon,
TwitterLogoIcon,
} from "@modulz/radix-icons";
import copy from "copy-to-clipboard";
import { QRCodeCanvas } from "qrcode.react";
import { useEffect, useState } from "react";
import { CopyToClipboard } from "react-copy-to-clipboard";

import EditProfile from "../EditProfile";

Expand All @@ -28,13 +28,19 @@ const Index = ({ account, isMyAccount = false, identity }: Props) => {
const [copied, setCopied] = useState(false);

useEffect(() => {
if (copied) {
setTimeout(() => {
setCopied(false);
}, 2000);
}
if (!copied) return;
const timer = setTimeout(() => {
setCopied(false);
}, 2000);
return () => clearTimeout(timer);
}, [copied]);

const handleCopy = () => {
if (copy(account)) {
setCopied(true);
}
};

return (
<Box css={{ marginBottom: "$3" }}>
<Flex css={{ alignItems: "center" }}>
Expand Down Expand Up @@ -99,56 +105,59 @@ const Index = ({ account, isMyAccount = false, identity }: Props) => {
css={{ height: "100%", marginLeft: "$3" }}
>
<Flex css={{ alignItems: "center" }}>
<CopyToClipboard text={account} onCopy={() => setCopied(true)}>
<Heading
size="2"
css={{
display: "flex",
alignItems: "center",
fontWeight: 700,
}}
<Heading
size="2"
css={{
display: "flex",
alignItems: "center",
fontWeight: 700,
}}
>
{identity?.name ? identity.name : formatAddress(account)}
<ExplorerTooltip
content={`${copied ? "Copied" : "Copy address to clipboard"}`}
>
{identity?.name ? identity.name : formatAddress(account)}
<ExplorerTooltip
content={`${copied ? "Copied" : "Copy address to clipboard"}`}
<Flex
as="button"
type="button"
aria-label="Copy address to clipboard"
onClick={handleCopy}
css={{
marginLeft: "$3",
marginTop: "3px",
cursor: "pointer",
borderRadius: 1000,
backgroundColor: "$neutral3",
border: "1px solid $neutral6",
padding: 0,
width: 28,
height: 28,
alignItems: "center",
justifyContent: "center",
}}
>
<Flex
css={{
marginLeft: "$3",
marginTop: "3px",
cursor: "pointer",
borderRadius: 1000,
backgroundColor: "$neutral3",
border: "1px solid $neutral6",
width: 28,
height: 28,
alignItems: "center",
justifyContent: "center",
}}
>
{copied ? (
<Box
as={CheckIcon}
css={{
width: 14,
height: 14,
color: "$muted",
}}
/>
) : (
<Box
as={CopyIcon}
css={{
width: 14,
height: 14,
color: "$muted",
}}
/>
)}
</Flex>
</ExplorerTooltip>
</Heading>
</CopyToClipboard>
{copied ? (
<Box
as={CheckIcon}
css={{
width: 14,
height: 14,
color: "$muted",
}}
/>
) : (
<Box
as={CopyIcon}
css={{
width: 14,
height: 14,
color: "$muted",
}}
/>
)}
</Flex>
</ExplorerTooltip>
</Heading>
{isMyAccount && <EditProfile />}
</Flex>
<Flex align="center" css={{ flexWrap: "wrap" }}>
Expand Down
Loading
Loading