diff --git a/src/components/profile-selector-dialog.tsx b/src/components/profile-selector-dialog.tsx index fd7781a..b05f316 100644 --- a/src/components/profile-selector-dialog.tsx +++ b/src/components/profile-selector-dialog.tsx @@ -2,8 +2,6 @@ import { invoke } from "@tauri-apps/api/core"; import { useCallback, useEffect, useState } from "react"; -import { LuCopy } from "react-icons/lu"; -import { toast } from "sonner"; import { LoadingButton } from "@/components/loading-button"; import { Badge } from "@/components/ui/badge"; import { @@ -31,6 +29,7 @@ import { useProfileEvents } from "@/hooks/use-profile-events"; import { useProxyEvents } from "@/hooks/use-proxy-events"; import { getBrowserDisplayName, getBrowserIcon } from "@/lib/browser-utils"; import type { BrowserProfile } from "@/types"; +import { CopyToClipboard } from "./ui/copy-to-clipboard"; import { RippleButton } from "./ui/ripple"; interface ProfileSelectorDialogProps { @@ -122,18 +121,6 @@ export function ProfileSelectorDialog({ onClose(); }, [onClose]); - const handleCopyUrl = useCallback(async () => { - if (!url) return; - - try { - await navigator.clipboard.writeText(url); - toast.success("URL copied to clipboard!"); - } catch (error) { - console.error("Failed to copy URL:", error); - toast.error("Failed to copy URL to clipboard"); - } - }, [url]); - const selectedProfileData = profiles.find((p) => p.name === selectedProfile); // Check if the selected profile can be used for opening links @@ -186,15 +173,10 @@ export function ProfileSelectorDialog({
Include this token in the Authorization header as "Bearer{" "} diff --git a/src/components/ui/copy-to-clipboard.tsx b/src/components/ui/copy-to-clipboard.tsx new file mode 100644 index 0000000..54f00a4 --- /dev/null +++ b/src/components/ui/copy-to-clipboard.tsx @@ -0,0 +1,65 @@ +"use client"; + +import { useCallback, useState } from "react"; +import { LuCheck, LuCopy } from "react-icons/lu"; +import { Button } from "@/components/ui/button"; +import { showSuccessToast } from "@/lib/toast-utils"; + +interface CopyToClipboardProps { + text: string; + variant?: + | "default" + | "destructive" + | "outline" + | "secondary" + | "ghost" + | "link"; + size?: "default" | "sm" | "lg" | "icon"; + className?: string; + successMessage?: string; +} + +export function CopyToClipboard({ + text, + variant = "outline", + size = "icon", + className, + successMessage = "Copied to clipboard", +}: CopyToClipboardProps) { + const [copied, setCopied] = useState(false); + + const copyToClipboard = useCallback(async () => { + try { + await navigator.clipboard.writeText(text); + setCopied(true); + showSuccessToast(successMessage); + setTimeout(() => { + setCopied(false); + }, 2000); + } catch (error) { + console.error("Failed to copy to clipboard:", error); + } + }, [text, successMessage]); + + return ( + + ); +}