김대휘

CheckBox re-rendering

...@@ -7,7 +7,7 @@ import Icon from "@material-ui/core/Icon"; ...@@ -7,7 +7,7 @@ import Icon from "@material-ui/core/Icon";
7 import IconButton from "@material-ui/core/IconButton"; 7 import IconButton from "@material-ui/core/IconButton";
8 import TextField from "@material-ui/core/TextField"; 8 import TextField from "@material-ui/core/TextField";
9 import Button from "@material-ui/core/Button"; 9 import Button from "@material-ui/core/Button";
10 -import Typography from '@material-ui/core/Typography'; 10 +import Typography from "@material-ui/core/Typography";
11 11
12 const useStyles = makeStyles((theme) => ({ 12 const useStyles = makeStyles((theme) => ({
13 iconButton: { 13 iconButton: {
...@@ -19,7 +19,7 @@ const useStyles = makeStyles((theme) => ({ ...@@ -19,7 +19,7 @@ const useStyles = makeStyles((theme) => ({
19 }, 19 },
20 icon: { 20 icon: {
21 fontSize: 70, 21 fontSize: 70,
22 - color: "black" 22 + color: "black",
23 }, 23 },
24 24
25 paper: { 25 paper: {
...@@ -35,12 +35,12 @@ const useStyles = makeStyles((theme) => ({ ...@@ -35,12 +35,12 @@ const useStyles = makeStyles((theme) => ({
35 width: "30ch", 35 width: "30ch",
36 }, 36 },
37 }, 37 },
38 - button:{ 38 + button: {
39 - '& > *': { 39 + "& > *": {
40 margin: theme.spacing(1), 40 margin: theme.spacing(1),
41 - float:"right" 41 + float: "right",
42 }, 42 },
43 - } 43 + },
44 })); 44 }));
45 45
46 function getModalStyle() { 46 function getModalStyle() {
...@@ -64,27 +64,6 @@ export default function AddButton() { ...@@ -64,27 +64,6 @@ export default function AddButton() {
64 setOpen(false); 64 setOpen(false);
65 }; 65 };
66 66
67 - const body = (
68 - <div style={modalStyle} className={classes.paper}>
69 - <Typography variant="h5">ADD TODO LIST</Typography>
70 -
71 - <form className={classes.input} noValidate autoComplete="off">
72 - <TextField id="standard-basic" label="Title" />
73 - <TextField id="standard-basic" label="Todo 1" />
74 - <TextField id="standard-basic" label="Todo 1" />
75 - </form>
76 -
77 - <form className={classes.button}>
78 - <Button variant="outlined" color="primary" onClick={handleClose}>
79 - 확인
80 - </Button>
81 - <Button variant="outlined" color="secondary" onClick={handleClose}>
82 - 취소
83 - </Button>
84 - </form>
85 - </div>
86 - );
87 -
88 return ( 67 return (
89 <> 68 <>
90 <IconButton className={classes.iconButton} onClick={handleOpen}> 69 <IconButton className={classes.iconButton} onClick={handleOpen}>
...@@ -95,7 +74,24 @@ export default function AddButton() { ...@@ -95,7 +74,24 @@ export default function AddButton() {
95 aria-labelledby="simple-modal-title" 74 aria-labelledby="simple-modal-title"
96 aria-describedby="simple-modal-description" 75 aria-describedby="simple-modal-description"
97 > 76 >
98 - {body} 77 + <div style={modalStyle} className={classes.paper}>
78 + <Typography variant="h5">ADD TODO LIST</Typography>
79 +
80 + <form className={classes.input} noValidate autoComplete="off">
81 + <TextField id="standard-basic" label="Title" />
82 + <TextField id="standard-basic" label="Todo 1" />
83 + <TextField id="standard-basic" label="Todo 1" />
84 + </form>
85 +
86 + <form className={classes.button}>
87 + <Button variant="outlined" color="primary" onClick={handleClose}>
88 + 확인
89 + </Button>
90 + <Button variant="outlined" color="secondary" onClick={handleClose}>
91 + 취소
92 + </Button>
93 + </form>
94 + </div>
99 </Modal> 95 </Modal>
100 </> 96 </>
101 ); 97 );
......
1 -import React from "react"; 1 +import React, {useState} from "react";
2 import { makeStyles } from "@material-ui/core/styles"; 2 import { makeStyles } from "@material-ui/core/styles";
3 import Card from "@material-ui/core/Card"; 3 import Card from "@material-ui/core/Card";
4 import CardContent from "@material-ui/core/CardContent"; 4 import CardContent from "@material-ui/core/CardContent";
...@@ -30,15 +30,24 @@ const useStyles = makeStyles({ ...@@ -30,15 +30,24 @@ const useStyles = makeStyles({
30 }, 30 },
31 }); 31 });
32 32
33 +
33 export default function TodoCard({ data, isMine, isVisible }) { 34 export default function TodoCard({ data, isMine, isVisible }) {
34 const classes = useStyles(); 35 const classes = useStyles();
36 + const [render, setRender] = useState(0);
35 const todo = data.todo.split(","); 37 const todo = data.todo.split(",");
36 - const check = data.ck.split(",").map((ck) => { 38 + const [checkState, setCheckState] = useState(data.ck.split(",").map((ck) => {
37 return parseInt(ck); 39 return parseInt(ck);
38 - }); 40 + }))
39 -
40 let settingButton = null; 41 let settingButton = null;
41 42
43 + const handleCheck = (idx) => {
44 + let tempArr = checkState;
45 + tempArr[idx] = tempArr[idx]?0:1;
46 + setCheckState(tempArr);
47 + setRender([]);
48 + };
49 +
50 +
42 if (isMine) { 51 if (isMine) {
43 settingButton = ( 52 settingButton = (
44 <SettingButton></SettingButton> 53 <SettingButton></SettingButton>
...@@ -56,15 +65,16 @@ export default function TodoCard({ data, isMine, isVisible }) { ...@@ -56,15 +65,16 @@ export default function TodoCard({ data, isMine, isVisible }) {
56 <Typography className={classes.title} variant="h6"> 65 <Typography className={classes.title} variant="h6">
57 {data.title} 66 {data.title}
58 </Typography> 67 </Typography>
59 - {/* <Typography className={classes.percent} variant="h6"> 68 + <Typography className={classes.percent} variant="h6">
60 - 99% 69 +
61 - </Typography> */} 70 + {checkState.reduce((a, b) => a + b)}/{checkState.length}
71 + </Typography>
62 {todo.map((item, idx) => { 72 {todo.map((item, idx) => {
63 return ( 73 return (
64 <FormControlLabel 74 <FormControlLabel
65 className={classes.checkBox} 75 className={classes.checkBox}
66 - control={<Checkbox/>} 76 + control={<Checkbox onClick={e=>(handleCheck(idx))}/>}
67 - checked={check[idx]} 77 + checked={checkState[idx]}
68 label={item} 78 label={item}
69 /> 79 />
70 ); 80 );
......