diff --git a/app/(app)/create/[[...paramsArr]]/_client.tsx b/app/(app)/create/[[...paramsArr]]/_client.tsx index eefef459f..5b6471796 100644 --- a/app/(app)/create/[[...paramsArr]]/_client.tsx +++ b/app/(app)/create/[[...paramsArr]]/_client.tsx @@ -20,7 +20,7 @@ import { config } from "@/markdoc/config"; import { useParams, useRouter } from "next/navigation"; import { usePrompt } from "@/components/PromptService"; import { Switch } from "@/components/Switch/Switch"; - +import copy from "copy-to-clipboard"; import { PostStatus, getPostStatus, isValidScheduleTime } from "@/utils/post"; const Create = () => { @@ -39,6 +39,7 @@ const Create = () => { const [isPostScheduled, setIsPostScheduled] = useState(false); const [shouldRefetch, setShouldRefetch] = useState(true); const [unsavedChanges, setUnsavedChanges] = useState(false); + const [copied, setCopied] = useState(false); const { unsavedChanges: _unsaved, setUnsavedChanges: _setUnsaved } = usePrompt(); @@ -112,6 +113,13 @@ const Create = () => { }, ); + const PREVIEW_URL = `${process.env.VERCEL_URL || "http://localhost:3000"}/draft/${postId}`; + + const handleCopyToClipboard = () => { + copy(PREVIEW_URL); + setCopied(true); + }; + useEffect(() => { if (isError) { toast.error("Error saving"); @@ -134,6 +142,11 @@ const Create = () => { } }, [dataStatus, shouldRefetch]); + useEffect(() => { + const to = setTimeout(setCopied, 2000, false); + return () => clearTimeout(to); + }, [copied]); + const getFormData = () => { const data = getValues(); const formData = { @@ -304,193 +317,218 @@ const Create = () => { <>
-
- -
-
-
-
- -