Skip to content

Commit

Permalink
fix: 최소, 최대 글자 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
asaei623 committed Sep 25, 2023
1 parent a682753 commit 8a62cbd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
43 changes: 26 additions & 17 deletions src/components/PostDetail/CommentInputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,37 @@ const CommentInputBox = ({ idx }: { idx: number }) => {
const [text, setText] = useState<string>('');
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const newText = event.target.value;
setText(newText);
//최대 글자 500자
if (newText.length > 500) {
setText(text);
} else {
setText(newText);
}
};
const handleClickSend = async () => {
//수정하기 버튼을 누른 경우, 댓글 수정 기능을 수행하도록 변함
if (editState.editClicked) {
const [content, commentIdx] = [text, editState.commentIdx];
let res = await editCommentApi({ content, commentIdx });

if (res.isSuccess) {
alert('댓글이 수정되었습니다.');
//새로고침
resetEditComment(); //recoil atom 리셋
window.location.reload();
}
if (text.length < 2) {
alert('내용을 2자 이상 입력해주세요.');
} else {
const [content, postIdx] = [text, idx];
let res = await postCommentApi({ content, postIdx });
if (editState.editClicked) {
const [content, commentIdx] = [text, editState.commentIdx];
let res = await editCommentApi({ content, commentIdx });

if (res.isSuccess) {
alert('댓글이 수정되었습니다.');
//새로고침
resetEditComment(); //recoil atom 리셋
window.location.reload();
}
} else {
const [content, postIdx] = [text, idx];
let res = await postCommentApi({ content, postIdx });

if (res.isSuccess) {
alert('댓글이 등록되었습니다.');
//새로고침
window.location.reload();
if (res.isSuccess) {
alert('댓글이 등록되었습니다.');
//새로고침
window.location.reload();
}
}
}
};
Expand Down
13 changes: 9 additions & 4 deletions src/components/common/WriteConfirmBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,34 @@ const WriteConfirmBar = ({ postIdx }: { postIdx?: number }) => {

//onClick
const onClickWrite = () => {
let message, destination: string, api: any;
let message, destination: string, api: any, successMsg: string;

if (currentURI === '/ask/write') {
message = '질문을 등록하시겠습니까?';
destination = '/ask';
api = postQuestionApi({ title, category, content });
successMsg = '질문이 등록되었습니다.';
} else {
message = '답변을 등록하시겠습니까?';
destination = '/answer';
api = postIdx ? postAnswerApi({ postIdx, answer: content }) : '';
successMsg = '답변이 등록되었습니다.';
}

const result = window.confirm(message);
if (result) {
if (title && title.length < 10) {
alert('제목을 10자 이상 입력해주세요.');
if (title && title.length < 5) {
alert('제목을 5자 이상 입력해주세요.');
} else if (content.length < 10) {
alert('내용을 10자 이상 입력해주세요.');
} else {
const postApi = async () => {
try {
let res = await api;
res.isSuccess && navigate(destination);
if (res.isSuccess) {
alert(successMsg);
navigate(destination);
}
} catch (err) {}
};

Expand Down

0 comments on commit 8a62cbd

Please sign in to comment.