add copy link button
All checks were successful
Build and Deploy Website / build (push) Successful in 2m32s
All checks were successful
Build and Deploy Website / build (push) Successful in 2m32s
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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<Paste | null>(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<string | null>(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={
|
||||
<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"}>
|
||||
{copied ? "Copied!" : "Copy"}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user