[questions][fix] update comment count after posting comment

pull/549/head
Jeff Sieu 2 years ago
parent bd21b93df2
commit 9c84b87d5a

@ -81,6 +81,24 @@ export default function QuestionPage() {
sortType: SortType.NEW, sortType: SortType.NEW,
}, },
]); ]);
const previousData = utils.getQueryData([
'questions.answers.getAnswerById',
{ answerId: answerId as string },
]);
if (previousData === undefined) {
return;
}
utils.setQueryData(
['questions.answers.getAnswerById', { answerId: answerId as string }],
{
...previousData,
numComments: previousData.numComments + 1,
},
);
event({ event({
action: 'questions.comment', action: 'questions.comment',
category: 'engagement', category: 'engagement',

@ -110,6 +110,24 @@ export default function QuestionPage() {
utils.invalidateQueries( utils.invalidateQueries(
'questions.questions.comments.getQuestionComments', 'questions.questions.comments.getQuestionComments',
); );
const previousData = utils.getQueryData([
'questions.questions.getQuestionById',
{ id: questionId as string },
]);
if (previousData === undefined) {
return;
}
utils.setQueryData(
['questions.questions.getQuestionById', { id: questionId as string }],
{
...previousData,
numComments: previousData.numComments + 1,
},
);
event({ event({
action: 'questions.comment', action: 'questions.comment',
category: 'engagement', category: 'engagement',
@ -142,6 +160,23 @@ export default function QuestionPage() {
{ {
onSuccess: () => { onSuccess: () => {
utils.invalidateQueries('questions.answers.getAnswers'); utils.invalidateQueries('questions.answers.getAnswers');
const previousData = utils.getQueryData([
'questions.questions.getQuestionById',
{ id: questionId as string },
]);
if (previousData === undefined) {
return;
}
utils.setQueryData(
['questions.questions.getQuestionById', { id: questionId as string }],
{
...previousData,
numAnswers: previousData.numAnswers + 1,
},
);
event({ event({
action: 'questions.answer', action: 'questions.answer',
category: 'engagement', category: 'engagement',
@ -228,7 +263,10 @@ export default function QuestionPage() {
<Collapsible <Collapsible
defaultOpen={true} defaultOpen={true}
label={ label={
<div className="text-primary-700">{`${question.numComments} comment(s)`}</div> <div className="text-primary-700">
{question.numComments}{' '}
{question.numComments === 1 ? 'comment' : 'comments'}
</div>
}> }>
<div className="flex flex-col gap-4 text-black"> <div className="flex flex-col gap-4 text-black">
<div className="flex justify-end gap-2"> <div className="flex justify-end gap-2">
@ -310,7 +348,8 @@ export default function QuestionPage() {
</form> </form>
<div className="flex items-center justify-between gap-4"> <div className="flex items-center justify-between gap-4">
<p className="text-xl font-semibold"> <p className="text-xl font-semibold">
{question.numAnswers} answers {question.numAnswers}{' '}
{question.numAnswers === 1 ? 'answer' : 'answers'}
</p> </p>
<div className="flex items-end gap-4"> <div className="flex items-end gap-4">
<SortOptionsSelect <SortOptionsSelect

Loading…
Cancel
Save