From 3ca08bd4f61ff6d981a6e7142dca8809fa4d7fdf Mon Sep 17 00:00:00 2001 From: Abhinav Date: Fri, 21 Jan 2022 12:29:32 +0530 Subject: [PATCH] add copy to clipboard option --- src/components/CollectionShare.tsx | 58 ++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/src/components/CollectionShare.tsx b/src/components/CollectionShare.tsx index ce74525e3..969481e48 100644 --- a/src/components/CollectionShare.tsx +++ b/src/components/CollectionShare.tsx @@ -4,7 +4,14 @@ import { Formik, FormikHelpers } from 'formik'; import * as Yup from 'yup'; import Form from 'react-bootstrap/Form'; import FormControl from 'react-bootstrap/FormControl'; -import { Button, Col, Row, Table } from 'react-bootstrap'; +import { + Button, + Col, + OverlayTrigger, + Row, + Table, + Tooltip, +} from 'react-bootstrap'; import { DeadCenter, GalleryContext } from 'pages/gallery'; import { User } from 'types/user'; import { @@ -20,6 +27,7 @@ import { Collection } from 'types/collection'; import { transformShareURLForHost } from 'utils/collection'; import CopyIcon from './icons/CopyIcon'; import { IconButton, Value } from './Container'; +import TickIcon from './icons/TickIcon'; interface Props { show: boolean; @@ -37,8 +45,9 @@ interface ShareeProps { function CollectionShare(props: Props) { const [loading, setLoading] = useState(false); - const galleryContext = useContext(GalleryContext); + const [copied, setCopied] = useState(false); + const collectionShare = async ( { email }: formValues, { resetForm, setFieldError }: FormikHelpers @@ -114,6 +123,12 @@ function CollectionShare(props: Props) { } }; + const copyToClipboardHelper = () => { + navigator.clipboard.writeText(props.collection.publicURLs[0].url); + setCopied(true); + setTimeout(() => setCopied(false), 1000); + }; + const ShareeRow = ({ sharee, collectionUnshare }: ShareeProps) => ( {sharee.email} @@ -134,12 +149,25 @@ function CollectionShare(props: Props) { ); + + const RenderCopiedMessage = (props) => { + const { style, ...rest } = props; + return ( + + copied + + ); + }; + if (!props.collection) { return <>; } return ( @@ -245,9 +273,27 @@ function CollectionShare(props: Props) { - - - + + + {copied ? ( + + ) : ( + + )} + + ))}