import { Alert, Grow, Rating, Slide, Typography } from "@mui/material"; import "./App.css"; import ButtonRow, { ActionProps } from "./components/ButtonRow"; import ReviewField, { ReviewFieldProps } from "./components/ReviewField"; import { useState } from "react"; function App() { const [rating, setNewRating] = useState(0); const [showAlert, changeAlert] = useState(false); const [alertText, changeAlertText] = useState(""); const [showInfo, changeInfo] = useState(false); const [infoText, changeInfoText] = useState(""); const fields: ReviewFieldProps[] = [ { name: "Name", dynamicState: useState("") }, { name: "Title", dynamicState: useState("") }, { name: "Content", dynamicState: useState(""), expandable: true } ]; const clearValues = () => { fields.forEach((field) => { field.dynamicState[1](""); }); setNewRating(null); } const showThenHide = async () => { await fetch("http://localhost:8080/post", { method: "POST", body: JSON.stringify({ rating: rating, username: fields[0].dynamicState[0], title: fields[1].dynamicState[0], content: fields[2].dynamicState[0] }) }) .then(async (response) => { const result = await response.json(); changeInfoText(result.error ? `${result.error.type}: ${result.error.message}` : `Success: ${result.message}`); changeInfo(true); setTimeout(() => { changeInfo(false); }, 2000); }) .catch((err) => { changeAlertText(err.toString()); changeAlert(true); setTimeout(() => { changeAlert(false); }, 2500); }); } const buttons: ActionProps[] = [ { name: "Clear", type: "outlined", action: clearValues }, { name: "Submit", type: "contained", action: showThenHide }, ]; const info = ( {infoText} ); const alert = ( {alertText} ); return ( <> Simple Review Client
{ setNewRating(newRating); }} />



{alert} {info} ); } export default App;