디자이너 전체회의(20:30)
- CSS 나눠짐
- 마이페이지 메인
- 가격책정
- 게시물 및 이의제기 , 시작화면 => 내가 맡은 부분
문제 : 삭제 버튼 누르려고할 시 모든 토글이 열리는 현상 발생
(comment.jsx)
import React, {useState} from 'react'
import { useDispatch, useSelector } from "react-redux";
import photoIMG from "../assets/photoIMG.png";
import styled from "styled-components";
const Comment = ({comment, __deleteComment}) => {
// Comment 컴포넌트에서 comment, __deleteComment 받아온 뒤(댓글 삭제)
const { post } = useSelector((state) => state.details);
const dispatch = useDispatch();
const onDeleteButton = (payload) => {
if (window.confirm("정말 삭제하시겠습니까?")) {
dispatch(__deleteComment(payload));
}
};
// 원래 진행하려던 코드 진행
const [editTg, setEidtTg] = useState({
isEdit: false,
});
const editToggleHandler = () => {
const newEdit = {
isEdit: !editTg.isEdit,
};
setEidtTg(newEdit);
};
// 토글값 지정
return (
<div>
<StContainer>
<Buttons>
<div>
<img
style={{
width: 25,
height: 25,
borderRadius: "50%",
float: "left",
marginRight: 10
}}
src={
post.avatarUrl == (null || undefined)
? photoIMG
: post.avatarUrl
}
/>
<span>{comment.nickname} </span>
</div>
<Tgbutton onClick={editToggleHandler}>···</Tgbutton>
{editTg.isEdit === true ? (
<Button onClick={() => onDeleteButton(comment.id)}>
삭제
</Button>
) : null}
</Buttons>
</StContainer>
<span> {comment.comment}</span>
<hr/>
</div>
)
}
//CSS도 다른 분 도움 받아 진행. Div 위치 잘 파악하자. 색깔 입혀서 하면 편하다.
export default Comment
// 전체 컨테이너
const StContainer = styled.div`
width: 100%;
height: 50px;
position: relative;
`
//삭제 토글
const Buttons = styled.div`
display: flex;
justify-content: space-between;
width: 100%;
height: 40px;
`
const Tgbutton = styled.button`
border: none;
font-weight: 600;
width: 50px;
background-color: white;
`;
const Button = styled.button`
position : absolute;
top : 40px;
right : 0px;
width: 50px;
height: 40px;
/* margin-bottom: 3px; */
border: 1px solid #ddd;
border-radius: 5px;
background-color: #fff;
&:hover {
background-color: red;
}
`;
(CommentList.jsx)
props 받아서 진행된 코드라 참고만 하려고 올림
import React, { useState } from "react";
import styled from "styled-components";
import Comment from "./Comment"
const CommentList = (props) => {
return (
<>
{props.commentList &&
props.commentList.map((comment, index) => {
return (
<div key={index}>
<Comment comment={comment} __deleteComment={props.__deleteComment}/>
</div>
);
})}
</>
);
};
export default CommentList;