add copy link button
All checks were successful
Build and Deploy Website / build (push) Successful in 2m32s

This commit is contained in:
2026-02-28 23:06:18 -08:00
parent fb7decc608
commit 500c080d02
2 changed files with 17 additions and 3 deletions

View File

@@ -69,7 +69,7 @@ export default function Paste() {
setError(data.error ?? "Failed to create paste."); setError(data.error ?? "Failed to create paste.");
return; return;
} }
navigate(`/paste/${data.id}`); navigate(`/paste/${data.id}`, { state: { password: password || undefined } });
} catch { } catch {
setError("Network error. Please try again."); setError("Network error. Please try again.");
} finally { } finally {

View File

@@ -1,5 +1,5 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useParams, Link } from "react-router-dom"; import { useParams, Link, useLocation } from "react-router-dom";
import ContentLayout from "@cloudscape-design/components/content-layout"; import ContentLayout from "@cloudscape-design/components/content-layout";
import Header from "@cloudscape-design/components/header"; import Header from "@cloudscape-design/components/header";
import Container from "@cloudscape-design/components/container"; import Container from "@cloudscape-design/components/container";
@@ -29,12 +29,16 @@ function formatDate(iso: string) {
export default function PasteView() { export default function PasteView() {
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
const location = useLocation();
const [paste, setPaste] = useState<Paste | null>(null); const [paste, setPaste] = useState<Paste | null>(null);
const [status, setStatus] = useState< const [status, setStatus] = useState<
"loading" | "ok" | "notfound" | "expired" | "error" | "locked" "loading" | "ok" | "notfound" | "expired" | "error" | "locked"
>("loading"); >("loading");
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const [passwordInput, setPasswordInput] = useState(""); const [linkCopied, setLinkCopied] = useState(false);
const [passwordInput, setPasswordInput] = useState(
(location.state as { password?: string })?.password ?? "",
);
const [passwordError, setPasswordError] = useState<string | null>(null); const [passwordError, setPasswordError] = useState<string | null>(null);
const [unlocking, setUnlocking] = useState(false); const [unlocking, setUnlocking] = useState(false);
@@ -103,6 +107,13 @@ export default function PasteView() {
} }
} }
function handleCopyLink() {
navigator.clipboard.writeText(window.location.href).then(() => {
setLinkCopied(true);
setTimeout(() => setLinkCopied(false), 2000);
});
}
function handleCopy() { function handleCopy() {
if (!paste) return; if (!paste) return;
navigator.clipboard.writeText(paste.content).then(() => { navigator.clipboard.writeText(paste.content).then(() => {
@@ -194,6 +205,9 @@ export default function PasteView() {
variant="h1" variant="h1"
actions={ actions={
<SpaceBetween direction="horizontal" size="xs"> <SpaceBetween direction="horizontal" size="xs">
<Button onClick={handleCopyLink} iconName={linkCopied ? "status-positive" : "share"}>
{linkCopied ? "Copied!" : "Copy Link"}
</Button>
<Button onClick={handleCopy} iconName={copied ? "status-positive" : "copy"}> <Button onClick={handleCopy} iconName={copied ? "status-positive" : "copy"}>
{copied ? "Copied!" : "Copy"} {copied ? "Copied!" : "Copy"}
</Button> </Button>