Skip to content

Commit

Permalink
copy renamed to handleCopy
Browse files Browse the repository at this point in the history
  • Loading branch information
ncomerci committed Jun 28, 2023
1 parent f1789aa commit 1bf56b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/components/Error/ErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from 'react'
import React, { useState } from 'react'

import classNames from 'classnames'
import Markdown from 'decentraland-gatsby/dist/components/Text/Markdown'
Expand All @@ -19,17 +19,13 @@ interface Props {

export default function ErrorMessage({ label, errorMessage }: Props) {
const t = useFormatMessage()
const { copiedValue, copy } = useClipboardCopy(Time.Second)
const { copiedValue, handleCopy } = useClipboardCopy(Time.Second)
const [open, setOpen] = useState(false)

const toggleHandler = () => {
setOpen(!open)
}

const handleCopy = useCallback(() => {
copy(errorMessage)
}, [errorMessage, copy])

return (
<div className="ErrorMessage__Container">
<div className="ErrorMessage__Header">
Expand All @@ -42,7 +38,12 @@ export default function ErrorMessage({ label, errorMessage }: Props) {
<div className={classNames('ErrorMessage__Content', open && 'ErrorMessage__Content--open')}>
<div className="ErrorMessage__Message">
<pre>{errorMessage}</pre>
<Button className={classNames('Button', 'ErrorMessage__Copy')} primary size="small" onClick={handleCopy}>
<Button
className={classNames('Button', 'ErrorMessage__Copy')}
primary
size="small"
onClick={() => handleCopy(errorMessage)}
>
<span>{copiedValue ? t('error.message.copied') : t('error.message.copy')}</span>
</Button>
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Modal/SuccessModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export function SuccessModal({
...props
}: SuccessModalProps) {
const t = useFormatMessage()
const { copiedValue, copy } = useClipboardCopy(Time.Second)
const handleCopy = useCallback(() => {
const { copiedValue, handleCopy } = useClipboardCopy(Time.Second)
const handleCopyClick = useCallback(() => {
if (linkToCopy) {
copy(linkToCopy)
handleCopy(linkToCopy)
}
}, [linkToCopy, copy])
}, [linkToCopy, handleCopy])

return (
<Modal
Expand Down Expand Up @@ -104,7 +104,7 @@ export function SuccessModal({
</div>
<Button
className={classNames('Button', 'CopyLink')}
onClick={handleCopy}
onClick={handleCopyClick}
loading={loading}
primary
size="small"
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useClipboardCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import clipboardCopy from 'clipboard-copy'
export default function useClipboardCopy(timeout?: number) {
const [copiedValue, setCopiedValue] = useState<string | null>(null)

const copy = useCallback((value: unknown) => {
const handleCopy = useCallback((value: unknown) => {
const copiedValue = String(value ?? '')
clipboardCopy(copiedValue)
setCopiedValue(copiedValue)
Expand All @@ -28,7 +28,7 @@ export default function useClipboardCopy(timeout?: number) {

return {
copiedValue,
copy,
handleCopy,
clear,
}
}
6 changes: 3 additions & 3 deletions src/hooks/useForumConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function useForumConnect() {
const [user, userState] = useAuthContext()
const track = useTrackContext()
const [sign, signState] = useSign(user, userState.provider)
const { copy } = useClipboardCopy(Time.Second)
const { handleCopy } = useClipboardCopy(Time.Second)
const [signatureResolution, setSignatureResolution] = useState<{
resolve: (value: unknown) => void
reject: (reason?: unknown) => void
Expand Down Expand Up @@ -80,9 +80,9 @@ export default function useForumConnect() {
const copyMessageToClipboard = useCallback(() => {
const { message, signature } = sign
if (message && signature) {
copy(`${message}\nSignature: ${signature}`)
handleCopy(`${message}\nSignature: ${signature}`)
}
}, [copy, sign])
}, [handleCopy, sign])

const openThread = () => {
openUrl(THREAD_URL)
Expand Down

0 comments on commit 1bf56b6

Please sign in to comment.