From 4c94060068c880e1d259f7b16962c7aa4747e8ae Mon Sep 17 00:00:00 2001 From: Roman-hal <85693082+Roman-Hal@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:34:18 +0100 Subject: [PATCH 1/4] upadated_functionality updated of the functionality of the textarea and backend --- client/src/pages/Home.js | 70 +++++++++++++++++++++++++++++++++------- server/api.js | 18 +++++++---- 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/client/src/pages/Home.js b/client/src/pages/Home.js index 55f715c..c341a3b 100644 --- a/client/src/pages/Home.js +++ b/client/src/pages/Home.js @@ -4,12 +4,14 @@ import { useState } from "react"; import Header from "../Components/Header"; import Footer from "../Components/Footer"; import Button from "react-bootstrap/Button"; +//import App from "../App"; import "./Home.css"; // import logo from "./logo.svg"; export function Home() { const [val, setVal] = useState(""); + const [content, setContent] = useState(""); /*const [message, setMessage] = useState("Loading..."); useEffect(() => { @@ -27,24 +29,68 @@ export function Home() { console.error(err); }); }, []);*/ + const onSubmit = (e) => { + e.preventDefault(content); + + if (!content) { + alert("Add some text"); + return; + } else if (val === content) { + alert("update text please"); + } else { + onAdd(content); + console.log(onAdd); + console.log(content); + setContent(content); + setVal(content); + } + }; + + const onAdd = async ({ content }) => { + const result = await ( + await fetch("http://localhost:3100/api/corrections", { + //const result = await(await fetch(`${ api }/corrections`, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + content, + }), + //body: JSON.stringify(item), + }) + ).json(); + + if (!result.error) { + console.log(result); + //navigate("/Loginmain"); + //window.location.reload(); + } else { + console.log(result.error); + } + }; return (

Hello World

{/* this the label */} - - {/*textarea with spellcheck function*/} - +
+
+ + + +
+
*/} -