Skip to content

Commit

Permalink
[#55]Refactor:코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunJungJo98 committed Mar 24, 2022
1 parent 61b1470 commit 1643dd4
Show file tree
Hide file tree
Showing 47 changed files with 3,934 additions and 3,331 deletions.
7 changes: 7 additions & 0 deletions frontend/sweet-red-beans/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true,
"bracketSameLine": true
}
103 changes: 53 additions & 50 deletions frontend/sweet-red-beans/src/components/Comment/Comment.js
Original file line number Diff line number Diff line change
@@ -1,86 +1,89 @@
import React, { useEffect, useState } from "react";
import axios from "axios";
import { useNavigate } from "react-router";
import { useSelector } from "react-redux";
import style from "../../css/Comment/Comment.module.css";
import { parseDate } from "../../parseDate/parseDate";
import React, { useEffect, useState } from 'react';
import axios from 'axios';
import { useNavigate } from 'react-router';
import { useSelector } from 'react-redux';
import style from '../../css/Comment/Comment.module.css';
import { parseDate } from '../../parseDate/parseDate';

const Comment = ({comment}) => {
console.log("댓글 렌더");
const Comment = ({ comment }) => {
console.log('댓글 렌더');
const navigation = useNavigate();

//const userid = useSelector(state => state.user.user_id);

const useConfirm = (message = null, onConfirm, onCancel) => {
if (!onConfirm || typeof onConfirm !== "function") {
if (!onConfirm || typeof onConfirm !== 'function') {
return;
}
if (onCancel && typeof onCancel !== "function") {
if (onCancel && typeof onCancel !== 'function') {
return;
}

const confirmAction = () => {
if (window.confirm(message)) {
onConfirm();
onConfirm();
} else {
onCancel();
onCancel();
}
};

return confirmAction;
};

//삭제버튼 눌렀을 때
const deleteConfirm = () => {
axios.delete('http://localhost:8080/information-share/comment',{
withCredentials: true,
data: {
user_id : "1",
axios
.delete('http://localhost:8080/information-share/comment', {
withCredentials: true,
data: {
user_id: '1',
comment_id: comment.comment_id,
},
})
.then((response) => {
if (response.data.result) {
alert('삭제되었습니다.');
//현재 페이지 리렌더
navigation(0);
} else {
alert('삭제에 실패했습니다.');
}
})
.then(response => {
if(response.data.result){
alert("삭제되었습니다.")
//현재 페이지 리렌더
navigation(0)
}
else {
alert("삭제에 실패했습니다.")
}
})
.catch(error => console.log(error));
}
})
.catch((error) => console.log(error));
};

const cancelConfirm = () => console.log("삭제 취소")
const cancelConfirm = () => console.log('삭제 취소');

const deleteClick = useConfirm(
"삭제하시겠습니까?",
'삭제하시겠습니까?',
deleteConfirm,
cancelConfirm
);

return (
<>
<div className={style.comment}>
<div className={style.topBar}>

<div>{comment.user_status === "정지" || comment.user_status === "탈퇴" ? "(알수없음)" : comment.comment_nickname}</div>
<div>{parseDate(comment.comment_written_date)}</div>
</div>

<div className={style.contentArea}>
<div>{comment.comment_content}</div>
<div>
{comment.is_mine ? <button onClick={deleteClick}>삭제</button> : null}
<div className={style.comment}>
<div className={style.topBar}>
<div>
{comment.user_status === '정지' ||
comment.user_status === '탈퇴'
? '(알수없음)'
: comment.comment_nickname}
</div>
<div>{parseDate(comment.comment_written_date)}</div>
</div>

<div className={style.contentArea}>
<div>{comment.comment_content}</div>
<div>
{comment.is_mine ? (
<button onClick={deleteClick}>삭제</button>
) : null}
</div>
</div>
</div>

</div>


</>
);
}
};

export default Comment;
export default Comment;
Loading

0 comments on commit 1643dd4

Please sign in to comment.