diff --git a/src/components/MainPage.js b/src/components/MainPage.js index e1220f7..801c650 100644 --- a/src/components/MainPage.js +++ b/src/components/MainPage.js @@ -12,6 +12,7 @@ function MainPage({ const [result, setResult] = useState(""); const [error, setError] = useState(""); const [jsonError, setJsonError] = useState(""); + const [copySuccess, setCopySuccess] = useState(false); const evaluateExpression = () => { try { @@ -77,6 +78,26 @@ function MainPage({ setJsonError(""); }; + const copyToClipboard = async () => { + try { + await navigator.clipboard.writeText(result); + setCopySuccess(true); + setTimeout(() => setCopySuccess(false), 2000); + } catch (err) { + console.error("Failed to copy!", err); + } + }; + + const downloadResult = () => { + const blob = new Blob([result], { type: "application/json" }); + const url = URL.createObjectURL(blob); + const a = document.createElement("a"); + a.href = url; + a.download = "result.json"; + a.click(); + URL.revokeObjectURL(url); + }; + const loadSample = () => { const sampleData = { users: [ @@ -155,11 +176,54 @@ function MainPage({