This commit is contained in:
powermaker450 2024-08-29 21:00:20 +00:00
parent 4b9ccfd8cc
commit 6db0a17851
3 changed files with 56 additions and 65 deletions

View file

@ -1,4 +1,4 @@
import { Alert, Grow, Rating, Slide, Typography } from "@mui/material"; import { Alert, Grow, Rating, Typography } from "@mui/material";
import "./App.css"; import "./App.css";
import ButtonRow, { ActionProps } from "./components/ButtonRow"; import ButtonRow, { ActionProps } from "./components/ButtonRow";
import ReviewField, { ReviewFieldProps } from "./components/ReviewField"; import ReviewField, { ReviewFieldProps } from "./components/ReviewField";
@ -15,17 +15,17 @@ function App() {
const fields: ReviewFieldProps[] = [ const fields: ReviewFieldProps[] = [
{ {
name: "Name", name: "Name",
dynamicState: useState("") dynamicState: useState(""),
}, },
{ {
name: "Title", name: "Title",
dynamicState: useState("") dynamicState: useState(""),
}, },
{ {
name: "Content", name: "Content",
dynamicState: useState(""), dynamicState: useState(""),
expandable: true expandable: true,
} },
]; ];
const clearValues = () => { const clearValues = () => {
@ -34,7 +34,7 @@ function App() {
}); });
setNewRating(null); setNewRating(null);
} };
const showThenHide = async () => { const showThenHide = async () => {
await fetch("http://localhost:8080/post", { await fetch("http://localhost:8080/post", {
@ -43,13 +43,17 @@ function App() {
rating: rating, rating: rating,
username: fields[0].dynamicState[0], username: fields[0].dynamicState[0],
title: fields[1].dynamicState[0], title: fields[1].dynamicState[0],
content: fields[2].dynamicState[0] content: fields[2].dynamicState[0],
}) }),
}) })
.then(async (response) => { .then(async (response) => {
const result = await response.json(); const result = await response.json();
changeInfoText(result.error ? `${result.error.type}: ${result.error.message}` : `Success: ${result.message}`); changeInfoText(
result.error
? `${result.error.type}: ${result.error.message}`
: `Success: ${result.message}`,
);
changeInfo(true); changeInfo(true);
@ -66,38 +70,28 @@ function App() {
changeAlert(false); changeAlert(false);
}, 2500); }, 2500);
}); });
} };
const buttons: ActionProps[] = [ const buttons: ActionProps[] = [
{ {
name: "Clear", name: "Clear",
type: "outlined", type: "outlined",
action: clearValues action: clearValues,
}, },
{ {
name: "Submit", name: "Submit",
type: "contained", type: "contained",
action: showThenHide action: showThenHide,
}, },
]; ];
const info = ( const info = <Alert severity="info">{infoText}</Alert>;
<Alert severity="info">
{infoText}
</Alert>
);
const alert = ( const alert = <Alert severity="error">{alertText}</Alert>;
<Alert severity="error">
{alertText}
</Alert>
);
return ( return (
<> <>
<Typography variant="h3"> <Typography variant="h3">Simple Review Client</Typography>
Simple Review Client
</Typography>
<br /> <br />

View file

@ -14,12 +14,10 @@ interface ReviewFieldOpts {
} }
const ReviewField = ({ fields }: ReviewFieldOpts) => { const ReviewField = ({ fields }: ReviewFieldOpts) => {
return ( return (
<Box component="form" noValidate autoComplete="off"> <Box component="form" noValidate autoComplete="off">
<Stack spacing={1}> <Stack spacing={1}>
{ {fields.map((field) => {
fields.map((field) => {
return ( return (
<TextField <TextField
id={field.name} id={field.name}
@ -27,16 +25,15 @@ const ReviewField = ({ fields }: ReviewFieldOpts) => {
label={field.name} label={field.name}
value={field.dynamicState[0]} value={field.dynamicState[0]}
multiline={field.expandable ?? false} multiline={field.expandable ?? false}
onChange={(({ target }) => { onChange={({ target }) => {
field.dynamicState[1](target.value); field.dynamicState[1](target.value);
})} }}
variant={field.variant ?? "outlined"} variant={field.variant ?? "outlined"}
helperText={field.help} helperText={field.help}
autoComplete="off" autoComplete="off"
/> />
) );
}) })}
}
</Stack> </Stack>
</Box> </Box>
); );