From 7af899ee7553c280353937e79da1ce3abda5da71 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Thu, 22 Jun 2023 17:06:33 -0400 Subject: [PATCH] fix: Remove tippy duplicate functions --- src/shared/components/common/vote-buttons.tsx | 71 ++++++------------- 1 file changed, 22 insertions(+), 49 deletions(-) diff --git a/src/shared/components/common/vote-buttons.tsx b/src/shared/components/common/vote-buttons.tsx index dce46f5b..20e8da2a 100644 --- a/src/shared/components/common/vote-buttons.tsx +++ b/src/shared/components/common/vote-buttons.tsx @@ -23,6 +23,25 @@ interface VoteButtonsState { downvoteLoading: boolean; } +const tippy = (counts: CommentAggregates | PostAggregates): string => { + const points = I18NextService.i18n.t("number_of_points", { + count: Number(counts.score), + formattedCount: Number(counts.score), + }); + + const upvotes = I18NextService.i18n.t("number_of_upvotes", { + count: Number(counts.upvotes), + formattedCount: Number(counts.upvotes), + }); + + const downvotes = I18NextService.i18n.t("number_of_downvotes", { + count: Number(counts.downvotes), + formattedCount: Number(counts.downvotes), + }); + + return `${points} • ${upvotes} • ${downvotes}`; +}; + export class VoteButtonsCompact extends Component< VoteButtonsProps, VoteButtonsState @@ -36,29 +55,6 @@ export class VoteButtonsCompact extends Component< super(props, context); } - get pointsTippy(): string { - const points = I18NextService.i18n.t("number_of_points", { - count: Number(this.props.counts.score), - formattedCount: Number(this.props.counts.score), - }); - - const upvotes = I18NextService.i18n.t("number_of_upvotes", { - count: Number(this.props.counts.upvotes), - formattedCount: Number(this.props.counts.upvotes), - }); - - const downvotes = I18NextService.i18n.t("number_of_downvotes", { - count: Number(this.props.counts.downvotes), - formattedCount: Number(this.props.counts.downvotes), - }); - - return `${points} • ${upvotes} • ${downvotes}`; - } - - get tippy() { - return showScores() ? { "data-tippy-content": this.pointsTippy } : {}; - } - render() { return (
@@ -66,7 +62,7 @@ export class VoteButtonsCompact extends Component< className={`btn-animate btn py-0 px-1 ${ this.props.my_vote === 1 ? "text-info" : "text-muted" }`} - {...this.tippy} + data-tippy-content={tippy(this.props.counts)} onClick={linkEvent(this.props.postListing, this.props.handleUpvote)} aria-label={I18NextService.i18n.t("upvote")} aria-pressed={this.props.my_vote === 1} @@ -93,7 +89,7 @@ export class VoteButtonsCompact extends Component< this.props.postListing, this.props.handleDownvote )} - {...this.tippy} + data-tippy-content={tippy(this.props.counts)} aria-label={I18NextService.i18n.t("downvote")} aria-pressed={this.props.my_vote === -1} > @@ -130,29 +126,6 @@ export class VoteButtons extends Component { super(props, context); } - get pointsTippy(): string { - const points = I18NextService.i18n.t("number_of_points", { - count: Number(this.props.counts.score), - formattedCount: Number(this.props.counts.score), - }); - - const upvotes = I18NextService.i18n.t("number_of_upvotes", { - count: Number(this.props.counts.upvotes), - formattedCount: Number(this.props.counts.upvotes), - }); - - const downvotes = I18NextService.i18n.t("number_of_downvotes", { - count: Number(this.props.counts.downvotes), - formattedCount: Number(this.props.counts.downvotes), - }); - - return `${points} • ${upvotes} • ${downvotes}`; - } - - get tippy() { - return showScores() ? { "data-tippy-content": this.pointsTippy } : {}; - } - render() { return (
@@ -174,7 +147,7 @@ export class VoteButtons extends Component { {showScores() ? (
{numToSI(this.props.counts.score)}