diff --git a/Frontend/src/pages/Paste.tsx b/Frontend/src/pages/Paste.tsx index aee5f04..a10daf1 100644 --- a/Frontend/src/pages/Paste.tsx +++ b/Frontend/src/pages/Paste.tsx @@ -69,7 +69,7 @@ export default function Paste() { setError(data.error ?? "Failed to create paste."); return; } - navigate(`/paste/${data.id}`); + navigate(`/paste/${data.id}`, { state: { password: password || undefined } }); } catch { setError("Network error. Please try again."); } finally { diff --git a/Frontend/src/pages/PasteView.tsx b/Frontend/src/pages/PasteView.tsx index 0ac038d..1e39fef 100644 --- a/Frontend/src/pages/PasteView.tsx +++ b/Frontend/src/pages/PasteView.tsx @@ -1,5 +1,5 @@ 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 Header from "@cloudscape-design/components/header"; import Container from "@cloudscape-design/components/container"; @@ -29,12 +29,16 @@ function formatDate(iso: string) { export default function PasteView() { const { id } = useParams<{ id: string }>(); + const location = useLocation(); const [paste, setPaste] = useState(null); const [status, setStatus] = useState< "loading" | "ok" | "notfound" | "expired" | "error" | "locked" >("loading"); 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(null); 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() { if (!paste) return; navigator.clipboard.writeText(paste.content).then(() => { @@ -194,6 +205,9 @@ export default function PasteView() { variant="h1" actions={ +