Skip to content

Commit

Permalink
Merge pull request #609 from pearpearB/Fix/댓글답글여러개열리는문제-592
Browse files Browse the repository at this point in the history
[Fix] 댓글의 답글 달기 여러개 열리는 문제 Close #592
  • Loading branch information
pearpearB authored Apr 5, 2022
2 parents 51437fe + d88c38f commit ebccda6
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 89 deletions.
15 changes: 4 additions & 11 deletions client/src/components/CommentInput/CommentInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ export default function CommentInput({
}: Props) {
const [comment, setComment] = useState<string>('');

const newCmtInputHandler = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setComment(e.target.value);
};

// const submitKeyboardHandler = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
// if (e.key === 'Enter') {
// submitCmtHandler(comment)
// setComment('')
// }
// }

useEffect(() => {
if (defaultContent) setComment(defaultContent);
}, []);

const newCmtInputHandler = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setComment(e.target.value);
};

const submitValidHandler = () => {
submitCmtHandler(comment);
setComment('');
Expand Down
17 changes: 14 additions & 3 deletions client/src/components/Comments/Comments.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useQueryClient, useMutation } from 'react-query';
import instance from 'utils/functions/axios';
import DropdownMenu from 'components/DropdownMenu/DropdownMenu';
Expand Down Expand Up @@ -32,7 +32,6 @@ type GreetingProps = {
roleType: string;
comment: CommentData;
commentsUserList: number[];
// setReRender: React.Dispatch<React.SetStateAction<boolean>>
};

function Comments({ roleType, comment, commentsUserList }: GreetingProps) {
Expand Down Expand Up @@ -69,6 +68,18 @@ function Comments({ roleType, comment, commentsUserList }: GreetingProps) {
instance.put(path, data),
);

useEffect(() => {
if (openReCmt) {
window.addEventListener(
'click',
() => {
setOpenReCmt(false);
},
{ once: true },
);
}
});

const modifyCmtHandler = () => {
setOpenEditor(!openEditor);
};
Expand Down Expand Up @@ -226,7 +237,7 @@ function Comments({ roleType, comment, commentsUserList }: GreetingProps) {
<>
<GLine />
<FLine />
<RecommentContainer>
<RecommentContainer onClick={(e) => e.stopPropagation()}>
<span>&#8627;</span>
<ReCommentWrap>
<CommentInput
Expand Down
16 changes: 14 additions & 2 deletions client/src/components/Comments/ReComments.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useQueryClient, useMutation } from 'react-query';
import instance from 'utils/functions/axios';
import DropdownMenu from 'components/DropdownMenu/DropdownMenu';
Expand Down Expand Up @@ -65,6 +65,18 @@ function ReComments({ roleType, recomment, commentsUserList }: GreetingProps) {
instance.put(path, data),
);

useEffect(() => {
if (openReReCmt) {
window.addEventListener(
'click',
() => {
setOpenReReCmt(false);
},
{ once: true },
);
}
});

const modifyCmtHandler = () => {
setOpenEditor(!openEditor);
};
Expand Down Expand Up @@ -239,7 +251,7 @@ function ReComments({ roleType, recomment, commentsUserList }: GreetingProps) {
<>
<GLine />
<FLine />
<RecommentContainer>
<RecommentContainer onClick={(e) => e.stopPropagation()}>
<span>&#8627;</span>
<ReCommentWrap>
<CommentInput
Expand Down
11 changes: 5 additions & 6 deletions client/src/components/DropdownMenu/DropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useState, useRef, useEffect } from 'react';
import { useState, useEffect } from 'react';
import { IoEllipsisVerticalOutline } from 'react-icons/io5';
import ReportModal from 'components/Modal/ReportModal';
import DeleteModal from 'components/Modal/DeleteModal';
import { DropdownWrap, HamburgerButton, DropdownBox, MenuList } from './styled';
import { ALL } from 'dns';

type GreetingProps = {
isPost: boolean;
Expand All @@ -30,10 +29,6 @@ export default function DropdownMenu({
const [openDeleteModal, setOpenDeleteModal] = useState<boolean>(false);
const [openReportModal, setOpenReportModal] = useState<boolean>(false);

const dropdownHandler = () => {
setOpenDropdown(!openDropdown);
};

useEffect(() => {
if (openDropdown) {
window.addEventListener(
Expand All @@ -46,6 +41,10 @@ export default function DropdownMenu({
}
});

const dropdownHandler = () => {
setOpenDropdown(!openDropdown);
};

const deleteModalHandler = () => {
setOpenDropdown(false);
setOpenDeleteModal(!openDeleteModal);
Expand Down
224 changes: 157 additions & 67 deletions client/src/components/Modal/ReportModal.tsx
Original file line number Diff line number Diff line change
@@ -1,78 +1,168 @@
import React, { useState } from 'react';
import { PageName, Squares, TopBar } from 'styles/styled';
import { ModalBackdrop, ReportModalContainer, ContentContainer, Instruction, ReportBox, ListName, ReportList, Buttons } from './styled';
import {
ModalBackdrop,
ReportModalContainer,
ContentContainer,
Instruction,
ReportBox,
ListName,
ReportList,
Buttons,
} from './styled';

type GreetingProps = {
clickModalHandler: () => void;
reportHandler: (reportIssue: string) => void;
clickModalHandler: () => void;
reportHandler: (reportIssue: string) => void;
};

export default function ReportModal ({ clickModalHandler, reportHandler }: GreetingProps) {
const [reportIssue, setReportIssue] = useState<string>('');
const [openIssue, setOpenIssue] = useState<boolean>(false);
export default function ReportModal({
clickModalHandler,
reportHandler,
}: GreetingProps) {
const [reportIssue, setReportIssue] = useState<string>('');
const [openIssue, setOpenIssue] = useState<boolean>(false);

const issueHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
setOpenIssue(false);
setReportIssue(event.target.value);
}
const issueHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
setOpenIssue(false);
setReportIssue(event.target.value);
};

const issueInputHandler = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
setReportIssue(event.target.value);
}
const issueInputHandler = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
setReportIssue(event.target.value);
};

const openIssueHandler = () => {
setOpenIssue(!openIssue);
setReportIssue('');
}
const openIssueHandler = () => {
setOpenIssue(!openIssue);
setReportIssue('');
};

const submitReportAndCloseModal = () => {
reportHandler(reportIssue);
clickModalHandler();
}
console.log(reportIssue)
return (
<>
<ModalBackdrop onClick={clickModalHandler}>
<ReportModalContainer onClick={(e) => e.stopPropagation()}>
<TopBar>
<PageName>신고하기</PageName>
<Squares>
<div>&#9866;</div>
<div>&#10064;</div>
<div onClick={clickModalHandler}>&times;</div>
</Squares>
</TopBar>
<ContentContainer>
<Instruction>
<div>신고는 반대 의견을 표시하는 기능이 아닙니다.</div>
<div>허위신고일 경우, 서비스 이용이 제한될 수 있으니 신중하게 신고해주세요.</div>
</Instruction>
<ReportBox>
<ListName>신고사유</ListName>
<ReportList>
<form>
<div><input type="radio" onChange={issueHandler} name="issue" value="욕설/혐오"/>욕설/폭력/혐오/차별적 표현입니다.</div>
<div><input type="radio" onChange={issueHandler} name="issue" value="인권침해"/>명예훼손/사칭/사생활침해 게시물입니다.</div>
<div><input type="radio" onChange={issueHandler} name="issue" value="개인정보"/>개인정보 노출 게시물입니다.</div>
<div><input type="radio" onChange={issueHandler} name="issue" value="음란물"/>음란물입니다.</div>
<div><input type="radio" onChange={issueHandler} name="issue" value="불법정보"/>불법정보를 포함하고 있습니다.</div>
<div><input type="radio" onChange={issueHandler} name="issue" value="스팸/도배"/>스팸홍보/도배글입니다.</div>
<div><input type="radio" onChange={issueHandler} name="issue" value="분탕"/>지나친 분란을 유도합니다.</div>
<div><input type="radio" onClick={openIssueHandler} name="issue" value="기타"/>직접입력</div>
{openIssue &&
<div><textarea placeholder={'신고사유를 입력해주세요.'} onChange={issueInputHandler} value={reportIssue} maxLength={300} /></div>
}
</form>
</ReportList>
</ReportBox>
<Buttons>
<form >
<input type="button" onClick={submitReportAndCloseModal} value="신고" />
</form>
</Buttons>
</ContentContainer>
</ReportModalContainer>
</ModalBackdrop>
</>
);
const submitReportAndCloseModal = () => {
reportHandler(reportIssue);
clickModalHandler();
};

return (
<>
<ModalBackdrop onClick={clickModalHandler}>
<ReportModalContainer onClick={(e) => e.stopPropagation()}>
<TopBar>
<PageName>신고하기</PageName>
<Squares>
<div>&#9866;</div>
<div>&#10064;</div>
<div onClick={clickModalHandler}>&times;</div>
</Squares>
</TopBar>
<ContentContainer>
<Instruction>
<div>신고는 반대 의견을 표시하는 기능이 아닙니다.</div>
<div>
허위신고일 경우, 서비스 이용이 제한될 수 있으니 신중하게
신고해주세요.
</div>
</Instruction>
<ReportBox>
<ListName>신고사유</ListName>
<ReportList>
<form>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="욕설/혐오"
/>
욕설/폭력/혐오/차별적 표현입니다.
</div>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="인권침해"
/>
명예훼손/사칭/사생활침해 게시물입니다.
</div>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="개인정보"
/>
개인정보 노출 게시물입니다.
</div>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="음란물"
/>
음란물입니다.
</div>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="불법정보"
/>
불법정보를 포함하고 있습니다.
</div>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="스팸/도배"
/>
스팸홍보/도배글입니다.
</div>
<div>
<input
type="radio"
onChange={issueHandler}
name="issue"
value="분탕"
/>
지나친 분란을 유도합니다.
</div>
<div>
<input
type="radio"
onClick={openIssueHandler}
name="issue"
value="기타"
/>
직접입력
</div>
{openIssue && (
<div>
<textarea
placeholder={'신고사유를 입력해주세요.'}
onChange={issueInputHandler}
value={reportIssue}
maxLength={300}
/>
</div>
)}
</form>
</ReportList>
</ReportBox>
<Buttons>
<form>
<input
type="button"
onClick={submitReportAndCloseModal}
value="신고"
/>
</form>
</Buttons>
</ContentContainer>
</ReportModalContainer>
</ModalBackdrop>
</>
);
}

0 comments on commit ebccda6

Please sign in to comment.