From 6a696d090e2c5d2cd8f5b5a40c721d9c6932e900 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Fri, 9 Jan 2026 20:40:01 +0100 Subject: [PATCH] refactor: remove copy to clipboard everywhere as it's not possible on http --- app/client/components/ui/code-block.tsx | 16 +-------- .../auth/components/reset-password-dialog.tsx | 13 +------ .../components/backup-codes-dialog.tsx | 25 ++------------ .../components/two-factor-setup-dialog.tsx | 34 ++----------------- app/utils/clipboard.ts | 29 ---------------- 5 files changed, 8 insertions(+), 109 deletions(-) delete mode 100644 app/utils/clipboard.ts diff --git a/app/client/components/ui/code-block.tsx b/app/client/components/ui/code-block.tsx index 1ae2ce56..c8529a0d 100644 --- a/app/client/components/ui/code-block.tsx +++ b/app/client/components/ui/code-block.tsx @@ -1,6 +1,4 @@ import type React from "react"; -import { toast } from "sonner"; -import { copyToClipboard } from "~/utils/clipboard"; interface CodeBlockProps { code: string; @@ -9,11 +7,6 @@ interface CodeBlockProps { } export const CodeBlock: React.FC = ({ code, filename }) => { - const handleCopy = async () => { - await copyToClipboard(code); - toast.success("Code copied to clipboard"); - }; - return (
@@ -23,16 +16,9 @@ export const CodeBlock: React.FC = ({ code, filename }) => { {filename && {filename}}
-
-				{code}
+				{code}
 			
); diff --git a/app/client/modules/auth/components/reset-password-dialog.tsx b/app/client/modules/auth/components/reset-password-dialog.tsx index d110b3b9..af91e7f5 100644 --- a/app/client/modules/auth/components/reset-password-dialog.tsx +++ b/app/client/modules/auth/components/reset-password-dialog.tsx @@ -1,7 +1,4 @@ -import { toast } from "sonner"; -import { Button } from "~/client/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "~/client/components/ui/dialog"; -import { copyToClipboard } from "~/utils/clipboard"; const RESET_PASSWORD_COMMAND = "docker exec -it zerobyte bun run cli reset-password"; @@ -11,11 +8,6 @@ type ResetPasswordDialogProps = { }; export const ResetPasswordDialog = ({ open, onOpenChange }: ResetPasswordDialogProps) => { - const handleCopy = async () => { - await copyToClipboard(RESET_PASSWORD_COMMAND); - toast.success("Command copied to clipboard"); - }; - return ( @@ -26,13 +18,10 @@ export const ResetPasswordDialog = ({ open, onOpenChange }: ResetPasswordDialogP
-
{RESET_PASSWORD_COMMAND}
+
{RESET_PASSWORD_COMMAND}

This command will start an interactive session where you can enter a new password for your account.

-
diff --git a/app/client/modules/settings/components/backup-codes-dialog.tsx b/app/client/modules/settings/components/backup-codes-dialog.tsx index 10b2aa64..6f111332 100644 --- a/app/client/modules/settings/components/backup-codes-dialog.tsx +++ b/app/client/modules/settings/components/backup-codes-dialog.tsx @@ -1,6 +1,6 @@ import { useState } from "react"; import { toast } from "sonner"; -import { Copy, RefreshCw } from "lucide-react"; +import { RefreshCw } from "lucide-react"; import { Button } from "~/client/components/ui/button"; import { Dialog, @@ -13,7 +13,6 @@ import { import { Input } from "~/client/components/ui/input"; import { Label } from "~/client/components/ui/label"; import { authClient } from "~/client/lib/auth-client"; -import { copyToClipboard } from "~/utils/clipboard"; type BackupCodesDialogProps = { open: boolean; @@ -64,11 +63,6 @@ export const BackupCodesDialog = ({ open, onOpenChange }: BackupCodesDialogProps }, 200); }; - const copyAllBackupCodes = () => { - const text = backupCodes.join("\n"); - void copyToClipboard(text); - }; - return ( @@ -84,24 +78,11 @@ export const BackupCodesDialog = ({ open, onOpenChange }: BackupCodesDialogProps <>
{backupCodes.map((code) => ( -
- {code} - +
+ {code}
))}
- ) : (
diff --git a/app/client/modules/settings/components/two-factor-setup-dialog.tsx b/app/client/modules/settings/components/two-factor-setup-dialog.tsx index c1d11a1d..5266fdc9 100644 --- a/app/client/modules/settings/components/two-factor-setup-dialog.tsx +++ b/app/client/modules/settings/components/two-factor-setup-dialog.tsx @@ -1,6 +1,5 @@ import { useState } from "react"; import { toast } from "sonner"; -import { Copy } from "lucide-react"; import { QRCodeCanvas } from "qrcode.react"; import { Button } from "~/client/components/ui/button"; import { @@ -15,7 +14,6 @@ import { Input } from "~/client/components/ui/input"; import { InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot } from "~/client/components/ui/input-otp"; import { Label } from "~/client/components/ui/label"; import { authClient } from "~/client/lib/auth-client"; -import { copyToClipboard } from "~/utils/clipboard"; type TwoFactorSetupDialogProps = { open: boolean; @@ -107,11 +105,6 @@ export const TwoFactorSetupDialog = ({ open, onOpenChange, onSuccess }: TwoFacto }, 200); }; - const copyAllBackupCodes = () => { - const text = backupCodes.join("\n"); - void copyToClipboard(text); - }; - return ( @@ -165,16 +158,8 @@ export const TwoFactorSetupDialog = ({ open, onOpenChange, onSuccess }: TwoFacto -
{backupCodes.length > 0 && ( @@ -182,24 +167,11 @@ export const TwoFactorSetupDialog = ({ open, onOpenChange, onSuccess }: TwoFacto
{backupCodes.map((code) => ( -
- {code} - +
+ {code}
))}
-
)} diff --git a/app/utils/clipboard.ts b/app/utils/clipboard.ts deleted file mode 100644 index f91c0153..00000000 --- a/app/utils/clipboard.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { toast } from "sonner"; - -export async function copyToClipboard(textToCopy: string) { - // Navigator clipboard api needs a secure context (https) - if (navigator.clipboard && window.isSecureContext) { - await navigator.clipboard.writeText(textToCopy); - toast.success("Copied to clipboard"); - } else { - // Use the 'out of viewport hidden text area' trick - const textArea = document.createElement("textarea"); - textArea.value = textToCopy; - - // Move textarea out of the viewport so it's not visible - textArea.style.position = "absolute"; - textArea.style.left = "-999999px"; - - document.body.prepend(textArea); - textArea.select(); - - try { - document.execCommand("copy"); - toast.success("Copied to clipboard"); - } catch (error) { - console.error(error); - } finally { - textArea.remove(); - } - } -}