diff --git a/client/src/components/PaginatedList.jsx b/client/src/components/PaginatedList.jsx index 78d469d..95f4dd6 100644 --- a/client/src/components/PaginatedList.jsx +++ b/client/src/components/PaginatedList.jsx @@ -12,7 +12,9 @@ export default function PaginatedList({ }) { return ( - {data.length ? data.map((item) => Component(item)) : noData && } + {data.length + ? data.map((item, index) => ) + : noData && } {count > 1 && ( getAnswerVote(question_id, answer_id); const updateVote = (data) => updateAnswerVote(question_id, answer_id, data); const postComment = async (data) => { diff --git a/client/src/components/QAComponents/Comment.jsx b/client/src/components/QAComponents/Comment.jsx index cffd13a..fde20b1 100644 --- a/client/src/components/QAComponents/Comment.jsx +++ b/client/src/components/QAComponents/Comment.jsx @@ -12,12 +12,9 @@ export default function Comment({ question_id, text, upvotes, - }) { const getVote = () => getCommentVote(question_id, comment_id); const updateVote = (data) => updateCommentVote(question_id, comment_id, data); - const {permissions} = useQuestion(); - let canVote = permissions.canVote; return ( @@ -25,9 +22,9 @@ export default function Comment({ {text} - + ); -} \ No newline at end of file +} diff --git a/client/src/controllers/QAControllers/CommentControlController.js b/client/src/controllers/QAControllers/CommentControlController.js index 8be7382..db8b1be 100644 --- a/client/src/controllers/QAControllers/CommentControlController.js +++ b/client/src/controllers/QAControllers/CommentControlController.js @@ -7,6 +7,7 @@ import { commentSchema } from 'services/schemas'; export default function CommentControlController({ postComment, canComment }) { const [show, setShow] = useState(false); + const navigate = useNavigate(); const toggleShow = () => { setShow(!show); @@ -16,6 +17,7 @@ export default function CommentControlController({ postComment, canComment }) { await postComment(data); toggleShow(); + navigate(''); }; return CommentControl({ diff --git a/client/src/controllers/QAControllers/QAPaginatedListController.jsx b/client/src/controllers/QAControllers/QAPaginatedListController.jsx index 061e4ce..eadd8e5 100644 --- a/client/src/controllers/QAControllers/QAPaginatedListController.jsx +++ b/client/src/controllers/QAControllers/QAPaginatedListController.jsx @@ -4,42 +4,56 @@ import { Answer, AnswerComment, Comment } from 'components/QAComponents'; import { getAnswerComments, getAnswers, getQuestionComments } from 'services/questionsServices'; export function AnswerCommentsList({ answer_id, comments: count }) { - const { questionData: { question_id } } = useQuestion(); + const { + questionData: { question_id }, + } = useQuestion(); const getData = ({ comment_id }) => getAnswerComments(question_id, answer_id, { after: comment_id }) - .then(({ comments }) => comments.map(comment => ({ ...comment, answer_id, question_id }))) + .then(({ comments }) => + comments.map((comment) => ({ ...comment, answer_id, question_id })) + ) .catch(() => []); return ; } export function AnswersList() { - const { questionData: { answers: count, loading, question_id } } = useQuestion(); + const { + permissions: { canComment, canAccept }, + questionData: { answers: count, loading, question_id }, + } = useQuestion(); - const sortByPoints = answers => answers.sort((a, b) => b.upvotes - b.downvotes - a.upvotes + a.downvotes); + const sortByPoints = (answers) => + answers.sort((a, b) => b.upvotes - b.downvotes - a.upvotes + a.downvotes); const getData = ({ answer_id }) => getAnswers(question_id, { after: answer_id }) - .then(({ answers }) => sortByPoints(answers).map(answer => ({ ...answer, question_id }))) + .then(({ answers }) => + sortByPoints(answers).map((answer) => ({ ...answer, question_id })) + ) .catch(() => []); + const NewAnswer = (props) => ; + return ( - !loading && + !loading && ); } export function CommentsList() { - const { questionData: { comments: count, loading, question_id } } = useQuestion(); + const { + questionData: { comments: count, loading, question_id }, + } = useQuestion(); - const sortByCreatedAt = comments => comments.sort((a, b) => a.createdAt - b.createdAt); + const sortByCreatedAt = (comments) => comments.sort((a, b) => a.createdAt - b.createdAt); const getData = ({ comment_id }) => getQuestionComments(question_id, { after: comment_id }) - .then(({ comments }) => sortByCreatedAt(comments).map(comment => ({ ...comment, question_id }))) + .then(({ comments }) => + sortByCreatedAt(comments).map((comment) => ({ ...comment, question_id })) + ) .catch(() => []); - return ( - !loading && - ); + return !loading && ; }