Showing
4 changed files
with
53 additions
and
45 deletions
| ... | @@ -2,15 +2,8 @@ import React, { useState } from "react"; | ... | @@ -2,15 +2,8 @@ import React, { useState } from "react"; |
| 2 | import { makeStyles } from "@material-ui/core/styles"; | 2 | import { makeStyles } from "@material-ui/core/styles"; |
| 3 | import ModalControl from "./ModalControl.js"; | 3 | import ModalControl from "./ModalControl.js"; |
| 4 | 4 | ||
| 5 | -import Modal from "@material-ui/core/Modal"; | ||
| 6 | import Icon from "@material-ui/core/Icon"; | 5 | import Icon from "@material-ui/core/Icon"; |
| 7 | import IconButton from "@material-ui/core/IconButton"; | 6 | import IconButton from "@material-ui/core/IconButton"; |
| 8 | -import TextField from "@material-ui/core/TextField"; | ||
| 9 | -import Button from "@material-ui/core/Button"; | ||
| 10 | -import Typography from "@material-ui/core/Typography"; | ||
| 11 | -import AddIcon from "@material-ui/icons/Add"; | ||
| 12 | -import FormControlLabel from "@material-ui/core/FormControlLabel"; | ||
| 13 | -import Checkbox from "@material-ui/core/Checkbox"; | ||
| 14 | 7 | ||
| 15 | const useStyles = makeStyles((theme) => ({ | 8 | const useStyles = makeStyles((theme) => ({ |
| 16 | iconButton: { | 9 | iconButton: { |
| ... | @@ -49,7 +42,6 @@ export default function AddButton() { | ... | @@ -49,7 +42,6 @@ export default function AddButton() { |
| 49 | }; | 42 | }; |
| 50 | 43 | ||
| 51 | const handleClose = () => { | 44 | const handleClose = () => { |
| 52 | - console.log(1); | ||
| 53 | setOpen(false); | 45 | setOpen(false); |
| 54 | }; | 46 | }; |
| 55 | 47 | ||
| ... | @@ -64,7 +56,7 @@ export default function AddButton() { | ... | @@ -64,7 +56,7 @@ export default function AddButton() { |
| 64 | } else { | 56 | } else { |
| 65 | return ( | 57 | return ( |
| 66 | <> | 58 | <> |
| 67 | - <ModalControl state={open} handleClose={handleClose} /> | 59 | + <ModalControl handleClose={handleClose} /> |
| 68 | </> | 60 | </> |
| 69 | ); | 61 | ); |
| 70 | } | 62 | } | ... | ... |
| ... | @@ -70,9 +70,11 @@ const useStyles = makeStyles((theme) => ({ | ... | @@ -70,9 +70,11 @@ const useStyles = makeStyles((theme) => ({ |
| 70 | }, | 70 | }, |
| 71 | })); | 71 | })); |
| 72 | 72 | ||
| 73 | -export default function AddButton({ state, handleClose }) { | 73 | +export default function AddButton({ handleClose }) { |
| 74 | const classes = useStyles(); | 74 | const classes = useStyles(); |
| 75 | + const initCk = new Array(3,0); | ||
| 75 | const [title, setTitle] = useState(""); | 76 | const [title, setTitle] = useState(""); |
| 77 | + const [date, setDate] = useState(new Date()); | ||
| 76 | const [isPublic, setIsPublic] = useState(1); | 78 | const [isPublic, setIsPublic] = useState(1); |
| 77 | const [textList, setTextList] = useState(new Array()); | 79 | const [textList, setTextList] = useState(new Array()); |
| 78 | const [textFieldBody, setTextFieldBody] = useState([ | 80 | const [textFieldBody, setTextFieldBody] = useState([ |
| ... | @@ -80,6 +82,7 @@ export default function AddButton({ state, handleClose }) { | ... | @@ -80,6 +82,7 @@ export default function AddButton({ state, handleClose }) { |
| 80 | ]); | 82 | ]); |
| 81 | 83 | ||
| 82 | const addApi = (data) => { | 84 | const addApi = (data) => { |
| 85 | + console.log(data); | ||
| 83 | return fetch("/api/addcard", { | 86 | return fetch("/api/addcard", { |
| 84 | method: "POST", | 87 | method: "POST", |
| 85 | headers: { | 88 | headers: { |
| ... | @@ -89,16 +92,25 @@ export default function AddButton({ state, handleClose }) { | ... | @@ -89,16 +92,25 @@ export default function AddButton({ state, handleClose }) { |
| 89 | }).then((response) => response.json()); | 92 | }).then((response) => response.json()); |
| 90 | }; | 93 | }; |
| 91 | 94 | ||
| 92 | - // const initData = () => { | 95 | + const checkAndClose = () => { |
| 93 | - // const initArr = new Array("","","","",""); | 96 | + if (title === "") { |
| 94 | - // setTitle(""); | 97 | + alert("Please enter a title!"); |
| 95 | - // setIsPublic(1); | 98 | + } else if (checkEemptyList(textList)) { |
| 96 | - // setTextList(initArr); | 99 | + alert("Please fill in the blank!"); |
| 97 | - // console.log(textList,1); | 100 | + } else { |
| 98 | - // setTextFieldBody([ | 101 | + const initCK = Array.apply(null, Array(textList.length)).map(Number.prototype.valueOf,0); |
| 99 | - // <TextField required label="To do 1" onChange={(e) => handleText(e, 0)} />, | 102 | + addApi({ |
| 100 | - // ]); | 103 | + isPublic: isPublic, |
| 101 | - // }; | 104 | + name: "testName", |
| 105 | + date: date.toLocaleDateString(), | ||
| 106 | + time: date.toLocaleTimeString(), | ||
| 107 | + title: title, | ||
| 108 | + todo: textList.join(","), | ||
| 109 | + ck: initCK.join(","), | ||
| 110 | + }); | ||
| 111 | + handleClose(); | ||
| 112 | + } | ||
| 113 | + }; | ||
| 102 | 114 | ||
| 103 | const checkEemptyList = (arr) => { | 115 | const checkEemptyList = (arr) => { |
| 104 | if (arr.length === 0) { | 116 | if (arr.length === 0) { |
| ... | @@ -112,18 +124,6 @@ export default function AddButton({ state, handleClose }) { | ... | @@ -112,18 +124,6 @@ export default function AddButton({ state, handleClose }) { |
| 112 | return 0; | 124 | return 0; |
| 113 | }; | 125 | }; |
| 114 | 126 | ||
| 115 | - const checkAndClose = () => { | ||
| 116 | - if (title === "") { | ||
| 117 | - alert("Please enter a title!"); | ||
| 118 | - } else if (checkEemptyList(textList)) { | ||
| 119 | - alert("Please fill in the blank!"); | ||
| 120 | - } else { | ||
| 121 | - //initData(); | ||
| 122 | - console.log(textList); | ||
| 123 | - handleClose(); | ||
| 124 | - } | ||
| 125 | - }; | ||
| 126 | - | ||
| 127 | const handleTitle = (e) => { | 127 | const handleTitle = (e) => { |
| 128 | setTitle(e.target.value); | 128 | setTitle(e.target.value); |
| 129 | }; | 129 | }; | ... | ... |
| ... | @@ -31,14 +31,13 @@ const useStyles = makeStyles({ | ... | @@ -31,14 +31,13 @@ const useStyles = makeStyles({ |
| 31 | }); | 31 | }); |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | -export default function TodoCard({ data, isMine, isVisible }) { | 34 | +export default function TodoCard({ data, isMine}) { |
| 35 | const classes = useStyles(); | 35 | const classes = useStyles(); |
| 36 | const [render, setRender] = useState(0); | 36 | const [render, setRender] = useState(0); |
| 37 | - const todo = data.todo.split(",").slice(0,-1).map((text)=>{ | 37 | + const todo = data.todo.split(",").map((text)=>{ |
| 38 | return text; | 38 | return text; |
| 39 | }); | 39 | }); |
| 40 | - console.log(todo); | 40 | + const [checkState, setCheckState] = useState(data.ck.split(",").map((ck) => { |
| 41 | - const [checkState, setCheckState] = useState(data.ck.split(",").slice(0,-1).map((ck) => { | ||
| 42 | return parseInt(ck); | 41 | return parseInt(ck); |
| 43 | })) | 42 | })) |
| 44 | let settingButton = null; | 43 | let settingButton = null; |
| ... | @@ -59,8 +58,8 @@ export default function TodoCard({ data, isMine, isVisible }) { | ... | @@ -59,8 +58,8 @@ export default function TodoCard({ data, isMine, isVisible }) { |
| 59 | return ( | 58 | return ( |
| 60 | <Card className={classes.root}> | 59 | <Card className={classes.root}> |
| 61 | <CardContent> | 60 | <CardContent> |
| 62 | - <Typography className={classes.date} color="textSecondary" gutterBottom> | 61 | + <Typography className={classes.date} gutterBottom> {/*color="textSecondary"*/} |
| 63 | - {data.date} · {data.name} | 62 | + {data.name} · {data.time} |
| 64 | </Typography> | 63 | </Typography> |
| 65 | 64 | ||
| 66 | {settingButton} | 65 | {settingButton} |
| ... | @@ -73,6 +72,7 @@ export default function TodoCard({ data, isMine, isVisible }) { | ... | @@ -73,6 +72,7 @@ export default function TodoCard({ data, isMine, isVisible }) { |
| 73 | {checkState.reduce((a, b) => a + b)}/{checkState.length} | 72 | {checkState.reduce((a, b) => a + b)}/{checkState.length} |
| 74 | </Typography> | 73 | </Typography> |
| 75 | {todo.map((item, idx) => { | 74 | {todo.map((item, idx) => { |
| 75 | + console.log(item); | ||
| 76 | return ( | 76 | return ( |
| 77 | <FormControlLabel | 77 | <FormControlLabel |
| 78 | className={classes.checkBox} | 78 | className={classes.checkBox} | ... | ... |
| ... | @@ -5,16 +5,16 @@ const app = express(); | ... | @@ -5,16 +5,16 @@ const app = express(); |
| 5 | 5 | ||
| 6 | const port = process.env.PORT || 5000; | 6 | const port = process.env.PORT || 5000; |
| 7 | 7 | ||
| 8 | -const data = fs.readFileSync('./database.json'); | 8 | +const data = fs.readFileSync("./database.json"); |
| 9 | const conf = JSON.parse(data); | 9 | const conf = JSON.parse(data); |
| 10 | -const mysql = require('mysql'); | 10 | +const mysql = require("mysql"); |
| 11 | 11 | ||
| 12 | const connection = mysql.createConnection({ | 12 | const connection = mysql.createConnection({ |
| 13 | host: conf.host, | 13 | host: conf.host, |
| 14 | user: conf.user, | 14 | user: conf.user, |
| 15 | password: conf.password, | 15 | password: conf.password, |
| 16 | port: conf.port, | 16 | port: conf.port, |
| 17 | - database: conf.database | 17 | + database: conf.database, |
| 18 | }); | 18 | }); |
| 19 | 19 | ||
| 20 | connection.connect(); | 20 | connection.connect(); |
| ... | @@ -23,12 +23,28 @@ app.use(bodyParser.json()); | ... | @@ -23,12 +23,28 @@ app.use(bodyParser.json()); |
| 23 | app.use(bodyParser.urlencoded({ extended: true })); | 23 | app.use(bodyParser.urlencoded({ extended: true })); |
| 24 | 24 | ||
| 25 | app.get("/api/cards", (req, res) => { | 25 | app.get("/api/cards", (req, res) => { |
| 26 | - connection.query( | 26 | + connection.query("SELECT * FROM CARDINFO", (err, rows, fields) => { |
| 27 | - 'SELECT * FROM CARDINFO', | ||
| 28 | - (err,rows,fields)=>{ | ||
| 29 | res.send(rows); | 27 | res.send(rows); |
| 28 | + }); | ||
| 29 | +}); | ||
| 30 | + | ||
| 31 | +app.post("/api/addcard", (req, res) => { | ||
| 32 | + const data = req.body; | ||
| 33 | + const sql = "INSERT INTO CARDINFO(isPublic,name,date,time,title,todo,ck) VALUES(?,?,?,?,?,?,?);"; | ||
| 34 | + const params =[data.isPublic,data.name,data.date,data.time,data.title,data.todo,data.ck]; | ||
| 35 | + connection.query(sql, params, (err, rows, fields) => { | ||
| 36 | + if (err) { | ||
| 37 | + res.send({ | ||
| 38 | + code: 400, | ||
| 39 | + message: "error", | ||
| 40 | + }); | ||
| 41 | + } else { | ||
| 42 | + res.send({ | ||
| 43 | + code: 200, | ||
| 44 | + message: "success", | ||
| 45 | + }); | ||
| 30 | } | 46 | } |
| 31 | - ) | 47 | + }); |
| 32 | }); | 48 | }); |
| 33 | 49 | ||
| 34 | app.listen(port, () => console.log(`Listening on port ${port}`)); | 50 | app.listen(port, () => console.log(`Listening on port ${port}`)); | ... | ... |
-
Please register or login to post a comment