mirror of
https://gitlab.w-hs.de/an14051/backerup-website.git
synced 2026-07-27 17:35:29 +00:00
feat: implement clipboard utility for copying text and update components to use it
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { copyText } from "@/lib/clipboard";
|
||||
|
||||
export default function CopyLinkButton({ token }: { token: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
@@ -8,21 +9,11 @@ export default function CopyLinkButton({ token }: { token: string }) {
|
||||
async function copy() {
|
||||
const url = `${window.location.origin}/files/${token}`;
|
||||
try {
|
||||
await navigator.clipboard.writeText(url);
|
||||
await copyText(url);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2500);
|
||||
} catch {
|
||||
// Fallback for browsers that deny clipboard access
|
||||
const el = document.createElement("textarea");
|
||||
el.value = url;
|
||||
el.style.position = "fixed";
|
||||
el.style.opacity = "0";
|
||||
document.body.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(el);
|
||||
setCopied(true);
|
||||
setTimeout(() => setCopied(false), 2500);
|
||||
// copy completely unavailable (e.g. sandboxed iframe) — do nothing
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user