-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61b1470
commit 1643dd4
Showing
47 changed files
with
3,934 additions
and
3,331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
103
frontend/sweet-red-beans/src/components/Comment/Comment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.