-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added like dislike feature in frontend for ques and answer
- Loading branch information
1 parent
2376842
commit 61fee8c
Showing
4 changed files
with
79 additions
and
22 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
45 changes: 37 additions & 8 deletions
45
Frontend-Realm/src/components/QuestionPage/AnswerList/AnswerItem.jsx
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,14 +1,43 @@ | ||
import React from 'react' | ||
import React from "react"; | ||
import axios from "axios" | ||
|
||
function AnswerItem({content="", author="", likes=0 ,dislikes=0, ansdbId=""}) { | ||
function AnswerItem({ | ||
content = "", | ||
author = "", | ||
likes = 0, | ||
dislikes = 0, | ||
ansdbId = "", | ||
}){ | ||
const likeAnswer = async () => { | ||
const res = await axios({ | ||
method: "POST", | ||
url: "http://localhost:3000/api/question/likeanswer", | ||
data: {ansId:ansdbId}, | ||
headers: { Authorization: localStorage.getItem("token") }, | ||
}); | ||
if(res.status===200){ | ||
window.location.reload(false); | ||
} | ||
}; | ||
const dislikeAnswer = async () => { | ||
const res = await axios({ | ||
method: "POST", | ||
url: "http://localhost:3000/api/question/dislikeanswer", | ||
data: {ansId:ansdbId}, | ||
headers: { Authorization: localStorage.getItem("token") }, | ||
}); | ||
if(res.status===200){ | ||
window.location.reload(false); | ||
} | ||
}; | ||
return ( | ||
<div> | ||
<div>{content}</div> | ||
<div>{author}</div> | ||
<div>{likes}</div> | ||
<div>{dislikes}</div> | ||
<div>{content}</div> | ||
<div>{author}</div> | ||
<div onClick={likeAnswer}>{likes}</div> | ||
<div onClick={dislikeAnswer}>{dislikes}</div> | ||
</div> | ||
) | ||
); | ||
} | ||
|
||
export default AnswerItem | ||
export default AnswerItem; |
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
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