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

Add button to copy flip info to clipboard #411

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 32 additions & 11 deletions pages/flips/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ import {useEpoch} from '../../shared/providers/epoch-context'
import {BadFlipDialog} from '../../screens/validation/components'
import {InfoIcon, RefreshIcon} from '../../shared/components/icons'
import {useTrackTx} from '../../screens/ads/hooks'
import {useFailToast} from '../../shared/hooks/use-toast'
import {useFailToast, useSuccessToast} from '../../shared/hooks/use-toast'
import {eitherState} from '../../shared/utils/utils'
import {writeTextToClipboard} from '../../shared/utils/clipboard'

export default function EditFlipPage() {
const {t, i18n} = useTranslation()
Expand All @@ -69,6 +70,7 @@ export default function EditFlipPage() {
const [, {waitFlipsUpdate}] = useIdentity()

const failToast = useFailToast()
const successToast = useSuccessToast()

const [didShowShuffleAdversarial, setDidShowShuffleAdversarial] = useState(
false
Expand Down Expand Up @@ -435,16 +437,35 @@ export default function EditFlipPage() {
</PrimaryButton>
)}
{is('submit') && (
<PrimaryButton
isDisabled={is('submit.submitting')}
isLoading={is('submit.submitting')}
loadingText={t('Publishing')}
onClick={() => {
publishDrawerDisclosure.onOpen()
}}
>
{t('Submit')}
</PrimaryButton>
<>
<SecondaryButton
onClick={async () =>
(await writeTextToClipboard(
JSON.stringify({
originalOrder,
order,
images: protectedImages,
})
))
? successToast({
title: t('Copied'),
})
: failToast('Failed to copy')
}
>
{t('Copy to clipboard')}
</SecondaryButton>
<PrimaryButton
isDisabled={is('submit.submitting')}
isLoading={is('submit.submitting')}
loadingText={t('Publishing')}
onClick={() => {
publishDrawerDisclosure.onOpen()
}}
>
{t('Submit')}
</PrimaryButton>
</>
)}
</FlipMasterFooter>

Expand Down
43 changes: 32 additions & 11 deletions pages/flips/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ import {useEpoch} from '../../shared/providers/epoch-context'
import {BadFlipDialog} from '../../screens/validation/components'
import {InfoIcon, RefreshIcon} from '../../shared/components/icons'
import {useTrackTx} from '../../screens/ads/hooks'
import {useFailToast} from '../../shared/hooks/use-toast'
import {useFailToast, useSuccessToast} from '../../shared/hooks/use-toast'
import {eitherState} from '../../shared/utils/utils'
import {writeTextToClipboard} from '../../shared/utils/clipboard'

export default function NewFlipPage() {
const {t, i18n} = useTranslation()
Expand All @@ -67,6 +68,7 @@ export default function NewFlipPage() {
const [, {waitFlipsUpdate}] = useIdentity()

const failToast = useFailToast()
const successToast = useSuccessToast()

const [didShowShuffleAdversarial, setDidShowShuffleAdversarial] = useState(
false
Expand Down Expand Up @@ -444,16 +446,35 @@ export default function NewFlipPage() {
</PrimaryButton>
)}
{is('submit') && (
<PrimaryButton
isDisabled={is('submit.submitting')}
isLoading={is('submit.submitting')}
loadingText={t('Publishing')}
onClick={() => {
publishDrawerDisclosure.onOpen()
}}
>
{t('Submit')}
</PrimaryButton>
<>
<SecondaryButton
onClick={async () =>
(await writeTextToClipboard(
JSON.stringify({
originalOrder,
order,
images: protectedImages,
})
))
? successToast({
title: t('Copied'),
})
: failToast('Failed to copy')
}
>
{t('Copy to clipboard')}
</SecondaryButton>
<PrimaryButton
isDisabled={is('submit.submitting')}
isLoading={is('submit.submitting')}
loadingText={t('Publishing')}
onClick={() => {
publishDrawerDisclosure.onOpen()
}}
>
{t('Submit')}
</PrimaryButton>
</>
)}
</FlipMasterFooter>

Expand Down
10 changes: 10 additions & 0 deletions shared/utils/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,13 @@ export async function writeImageURLToClipboard(url) {
const data = [new ClipboardItem({[blob.type]: blob})]
return navigator.clipboard.write(data)
}

export async function writeTextToClipboard(text) {
try {
await navigator.clipboard.writeText(text)
return true
} catch (err) {
console.error('Failed to copy: ', err)
return false
}
}