From 7788505a756efcaeaa885915a729c09dac7e67aa Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sun, 22 Oct 2023 15:22:43 +0800 Subject: [PATCH] Frontend added table shortener copy button with transition --- react-frontend/src/App.tsx | 68 +++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 16 deletions(-) diff --git a/react-frontend/src/App.tsx b/react-frontend/src/App.tsx index f082ce1..e486d0a 100644 --- a/react-frontend/src/App.tsx +++ b/react-frontend/src/App.tsx @@ -33,7 +33,14 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Toaster } from '@/components/ui/toaster' import { useToast } from '@/components/ui/use-toast' -import { Copy, Loader2, MoreHorizontal, Settings, User } from 'lucide-react' +import { + Check, + Copy, + Loader2, + MoreHorizontal, + Settings, + User, +} from 'lucide-react' import { useEffect, useState } from 'react' import { useNavigate } from 'react-router-dom' @@ -191,15 +198,8 @@ const ShortenerTable = ({ isLoading: boolean getShorteners: () => Promise }) => { - const { toast } = useToast() - const copyLinkToClipboard = async (code: string) => { - await navigator.clipboard.writeText(backend_url + '/' + code) - toast({ - title: 'Link Copied', - description: `Copied ${backend_url + '/' + code} To Clipboard`, - }) - } const navigate = useNavigate() + return ( @@ -233,15 +233,13 @@ const ShortenerTable = ({ shorteners.map((shortener) => ( {shortener.link} - - copyLinkToClipboard(shortener.code) - }> -
+ +
{shortener.code} -
+
{shortener.visitor_count} @@ -287,3 +285,41 @@ const ShortenerTable = ({ ) } + +const ShortenerCopyButton = ({ code }: { code: string }) => { + const { toast } = useToast() + const copyLinkToClipboard = async (code: string) => { + await navigator.clipboard.writeText(backend_url + '/' + code) + toast({ + title: 'Link Copied', + description: `Copied ${backend_url + '/' + code} To Clipboard`, + }) + } + const [isCopy, setIsCopy] = useState(false) + const onClick = () => { + setIsCopy(true) + copyLinkToClipboard(code) + setTimeout(() => setIsCopy(false), 2000) + } + return ( + + ) +}