[questions][fix] fix upvotes

pull/521/head
Jeff Sieu 3 years ago
parent 96b1a4c23f
commit c0b3313acc

@ -0,0 +1,28 @@
import { useAnswerCommentVote } from '~/utils/questions/useVote';
import type { CommentListItemProps } from './CommentListItem';
import CommentListItem from './CommentListItem';
export type AnswerCommentListItemProps = Omit<
CommentListItemProps,
'onDownvote' | 'onUpvote' | 'vote'
> & {
answerCommentId: string;
};
export default function AnswerCommentListItem({
answerCommentId,
...restProps
}: AnswerCommentListItemProps) {
const { handleDownvote, handleUpvote, vote } =
useAnswerCommentVote(answerCommentId);
return (
<CommentListItem
vote={vote}
onDownvote={handleDownvote}
onUpvote={handleUpvote}
{...restProps}
/>
);
}

@ -1,37 +1,37 @@
import { format } from 'date-fns'; import { format } from 'date-fns';
import { useAnswerCommentVote } from '~/utils/questions/useVote'; import type { BackendVote } from '../VotingButtons';
import VotingButtons from '../VotingButtons';
import VotingButtons from './VotingButtons'; export type CommentListItemProps = {
export type AnswerCommentListItemProps = {
answerCommentId: string;
authorImageUrl: string; authorImageUrl: string;
authorName: string; authorName: string;
content: string; content: string;
createdAt: Date; createdAt: Date;
onDownvote: () => void;
onUpvote: () => void;
upvoteCount: number; upvoteCount: number;
vote: BackendVote;
}; };
export default function AnswerCommentListItem({ export default function CommentListItem({
authorImageUrl, authorImageUrl,
authorName, authorName,
content, content,
createdAt, createdAt,
upvoteCount, upvoteCount,
answerCommentId, vote,
}: AnswerCommentListItemProps) { onDownvote,
const { handleDownvote, handleUpvote, vote } = onUpvote,
useAnswerCommentVote(answerCommentId); }: CommentListItemProps) {
return ( return (
<div className="flex gap-4 rounded-md border bg-white p-2"> <div className="flex gap-4 rounded-md border bg-white p-2">
<VotingButtons <VotingButtons
size="sm" size="sm"
upvoteCount={upvoteCount} upvoteCount={upvoteCount}
vote={vote} vote={vote}
onDownvote={handleDownvote} onDownvote={onDownvote}
onUpvote={handleUpvote} onUpvote={onUpvote}
/> />
<div className="mt-1 flex flex-col gap-1"> <div className="mt-1 flex flex-col gap-1">
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">

@ -0,0 +1,28 @@
import { useQuestionCommentVote } from '~/utils/questions/useVote';
import type { CommentListItemProps } from './CommentListItem';
import CommentListItem from './CommentListItem';
export type QuestionCommentListItemProps = Omit<
CommentListItemProps,
'onDownvote' | 'onUpvote' | 'vote'
> & {
questionCommentId: string;
};
export default function QuestionCommentListItem({
questionCommentId,
...restProps
}: QuestionCommentListItemProps) {
const { handleDownvote, handleUpvote, vote } =
useQuestionCommentVote(questionCommentId);
return (
<CommentListItem
vote={vote}
onDownvote={handleDownvote}
onUpvote={handleUpvote}
{...restProps}
/>
);
}

@ -5,8 +5,8 @@ import { useForm } from 'react-hook-form';
import { Button, TextArea } from '@tih/ui'; import { Button, TextArea } from '@tih/ui';
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics'; import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
import AnswerCommentListItem from '~/components/questions/AnswerCommentListItem';
import FullAnswerCard from '~/components/questions/card/FullAnswerCard'; import FullAnswerCard from '~/components/questions/card/FullAnswerCard';
import AnswerCommentListItem from '~/components/questions/comments/AnswerCommentListItem';
import FullScreenSpinner from '~/components/questions/FullScreenSpinner'; import FullScreenSpinner from '~/components/questions/FullScreenSpinner';
import BackButtonLayout from '~/components/questions/layout/BackButtonLayout'; import BackButtonLayout from '~/components/questions/layout/BackButtonLayout';
import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton'; import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton';

@ -5,9 +5,9 @@ import { useForm } from 'react-hook-form';
import { Button, Collapsible, HorizontalDivider, TextArea } from '@tih/ui'; import { Button, Collapsible, HorizontalDivider, TextArea } from '@tih/ui';
import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics'; import { useGoogleAnalytics } from '~/components/global/GoogleAnalytics';
import AnswerCommentListItem from '~/components/questions/AnswerCommentListItem';
import FullQuestionCard from '~/components/questions/card/question/FullQuestionCard'; import FullQuestionCard from '~/components/questions/card/question/FullQuestionCard';
import QuestionAnswerCard from '~/components/questions/card/QuestionAnswerCard'; import QuestionAnswerCard from '~/components/questions/card/QuestionAnswerCard';
import QuestionCommentListItem from '~/components/questions/comments/QuestionCommentListItem';
import FullScreenSpinner from '~/components/questions/FullScreenSpinner'; import FullScreenSpinner from '~/components/questions/FullScreenSpinner';
import BackButtonLayout from '~/components/questions/layout/BackButtonLayout'; import BackButtonLayout from '~/components/questions/layout/BackButtonLayout';
import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton'; import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton';
@ -248,13 +248,13 @@ export default function QuestionPage() {
{(commentData?.pages ?? []).flatMap( {(commentData?.pages ?? []).flatMap(
({ processedQuestionCommentsData: comments }) => ({ processedQuestionCommentsData: comments }) =>
comments.map((comment) => ( comments.map((comment) => (
<AnswerCommentListItem <QuestionCommentListItem
key={comment.id} key={comment.id}
answerCommentId={comment.id}
authorImageUrl={comment.userImage} authorImageUrl={comment.userImage}
authorName={comment.user} authorName={comment.user}
content={comment.content} content={comment.content}
createdAt={comment.createdAt} createdAt={comment.createdAt}
questionCommentId={comment.id}
upvoteCount={comment.numVotes} upvoteCount={comment.numVotes}
/> />
)), )),

Loading…
Cancel
Save