From be30134109e3f9ac15e63dda979fd5c96e0b40a1 Mon Sep 17 00:00:00 2001 From: TRP <83850231+trp02@users.noreply.github.com> Date: Wed, 28 Feb 2024 18:41:11 -0500 Subject: [PATCH] added preset paramters and reading (#419) * added preset paramters and reading * removed loop bug * remove testing interface --- src/components/form.jsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/components/form.jsx b/src/components/form.jsx index 185d7a8a..38ccb3f4 100644 --- a/src/components/form.jsx +++ b/src/components/form.jsx @@ -1,5 +1,7 @@ import { useEffect, useRef, useState } from "react"; import { LoadingSpinner } from "./loadingSpinner"; +const searchParams = new URLSearchParams(window.location.search); +const prefillVar = searchParams.get("prefill_var"); const Form = () => { const [data, setData] = useState(null); @@ -59,12 +61,33 @@ const Form = () => { } }; + const copyToClipboard = (e) => { + e.preventDefault(); + const link = `${window.location.origin}/?prefill_var=${userInput}`; + navigator.clipboard + .writeText(link) + .then(() => { + console.log("Link copied to clipboard"); + }) + .catch((err) => { + console.error("Could not copy text: ", err); + }); + }; + useEffect(() => { if (!isUserInputBlank) { previousUserInput.current = userInput; } }, [userInput]); + useEffect(() => { + if (prefillVar) { + setUserInput(prefillVar); + const mockEvent = { preventDefault: () => {} }; + fetchData(mockEvent); + } + }, [isUserInputBlank]); + return (
{data.definition}
+ copyToClipboard(e)} + className="text-blue-600 hover:text-blue-800 visited:text-purple-600">{data.alternatives}