김대휘

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,7 +64,16 @@ export default function AddButton() { ...@@ -64,7 +64,16 @@ export default function AddButton() {
64 setOpen(false); 64 setOpen(false);
65 }; 65 };
66 66
67 - const body = ( 67 + return (
68 + <>
69 + <IconButton className={classes.iconButton} onClick={handleOpen}>
70 + <Icon className={classes.icon}>add_circle</Icon>
71 + </IconButton>
72 + <Modal
73 + open={open}
74 + aria-labelledby="simple-modal-title"
75 + aria-describedby="simple-modal-description"
76 + >
68 <div style={modalStyle} className={classes.paper}> 77 <div style={modalStyle} className={classes.paper}>
69 <Typography variant="h5">ADD TODO LIST</Typography> 78 <Typography variant="h5">ADD TODO LIST</Typography>
70 79
...@@ -83,19 +92,6 @@ export default function AddButton() { ...@@ -83,19 +92,6 @@ export default function AddButton() {
83 </Button> 92 </Button>
84 </form> 93 </form>
85 </div> 94 </div>
86 - );
87 -
88 - return (
89 - <>
90 - <IconButton className={classes.iconButton} onClick={handleOpen}>
91 - <Icon className={classes.icon}>add_circle</Icon>
92 - </IconButton>
93 - <Modal
94 - open={open}
95 - aria-labelledby="simple-modal-title"
96 - aria-describedby="simple-modal-description"
97 - >
98 - {body}
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 );
......