diff --git a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx index a76a9a1f..9c7f9d19 100644 --- a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx +++ b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx @@ -81,6 +81,24 @@ export default function QuestionPage() { 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({ action: 'questions.comment', category: 'engagement', diff --git a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx index c526a9be..b38e4024 100644 --- a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx +++ b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx @@ -110,6 +110,24 @@ export default function QuestionPage() { utils.invalidateQueries( '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({ action: 'questions.comment', category: 'engagement', @@ -142,6 +160,23 @@ export default function QuestionPage() { { onSuccess: () => { 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({ action: 'questions.answer', category: 'engagement', @@ -228,7 +263,10 @@ export default function QuestionPage() { {`${question.numComments} comment(s)`} +
+ {question.numComments}{' '} + {question.numComments === 1 ? 'comment' : 'comments'} +
}>
@@ -310,7 +348,8 @@ export default function QuestionPage() {

- {question.numAnswers} answers + {question.numAnswers}{' '} + {question.numAnswers === 1 ? 'answer' : 'answers'}