From 4a617a4c0776d568f609b684a8eda1a1413c0a2a Mon Sep 17 00:00:00 2001 From: James Grugett Date: Mon, 21 Mar 2022 15:23:21 -0500 Subject: [PATCH] Share embed button --- web/components/contract-card.tsx | 12 +++-- web/components/share-embed-button.tsx | 47 +++++++++++++++++++ web/pages/embed/[username]/[contractSlug].tsx | 6 ++- 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 web/components/share-embed-button.tsx diff --git a/web/components/contract-card.tsx b/web/components/contract-card.tsx index a33b65cc..981102cc 100644 --- a/web/components/contract-card.tsx +++ b/web/components/contract-card.tsx @@ -21,6 +21,7 @@ import { Spacer } from './layout/spacer' import { useState } from 'react' import { TweetButton } from './tweet-button' import { getProbability } from '../../common/calculate' +import { ShareEmbedButton } from './share-embed-button' export function ContractCard(props: { contract: Contract @@ -172,9 +173,9 @@ function AbbrContractDetails(props: { export function ContractDetails(props: { contract: Contract isCreator?: boolean - hideTweetBtn?: boolean + hideShareButtons?: boolean }) { - const { contract, isCreator, hideTweetBtn } = props + const { contract, isCreator, hideShareButtons } = props const { closeTime, creatorName, creatorUsername } = contract const { liquidityLabel, createdDate, resolvedDate } = contractMetrics(contract) @@ -234,8 +235,11 @@ export function ContractDetails(props: {
{liquidityLabel}
- {!hideTweetBtn && ( - + {!hideShareButtons && ( + <> + + + )} diff --git a/web/components/share-embed-button.tsx b/web/components/share-embed-button.tsx new file mode 100644 index 00000000..01ccfe00 --- /dev/null +++ b/web/components/share-embed-button.tsx @@ -0,0 +1,47 @@ +import { Fragment } from 'react' +import { CodeIcon } from '@heroicons/react/outline' +import { Menu, Transition } from '@headlessui/react' +import { Contract } from '../../common/contract' +import { contractPath } from '../lib/firebase/contracts' +import { DOMAIN } from '../../common/envs/constants' + +export function ShareEmbedButton(props: { contract: Contract }) { + const { contract } = props + + const copyEmbed = () => { + const title = contract.question + const src = `https://${DOMAIN}/embed${contractPath(contract)}` + + const embedCode = `` + + if (navigator.clipboard) navigator.clipboard.writeText(embedCode) + } + + return ( + + + + + + + +
Embed code copied!
+
+
+
+
+ ) +} diff --git a/web/pages/embed/[username]/[contractSlug].tsx b/web/pages/embed/[username]/[contractSlug].tsx index 8b40b2e7..b5816710 100644 --- a/web/pages/embed/[username]/[contractSlug].tsx +++ b/web/pages/embed/[username]/[contractSlug].tsx @@ -100,7 +100,11 @@ function ContractEmbed(props: { contract: Contract; bets: Bet[] }) { - + {(isBinary || resolution) && (