import { showScores } from "@utils/app"; import { numToSI } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; import { CommentAggregates, PostAggregates } from "lemmy-js-client"; import { I18NextService } from "../../services"; import { Icon, Spinner } from "../common/icon"; import { PostListing } from "../post/post-listing"; interface VoteButtonsProps { postListing: PostListing; enableDownvotes?: boolean; upvoteLoading?: boolean; downvoteLoading?: boolean; handleUpvote: (i: PostListing) => void; handleDownvote: (i: PostListing) => void; counts: CommentAggregates | PostAggregates; my_vote?: number; } interface VoteButtonsState { upvoteLoading: boolean; downvoteLoading: boolean; } export class VoteButtonsCompact extends Component< VoteButtonsProps, VoteButtonsState > { state: VoteButtonsState = { upvoteLoading: false, downvoteLoading: false, }; constructor(props: any, context: any) { 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 ( <>
{numToSI(this.props.counts.score)} {this.props.enableDownvotes && ( )}
); } } export class VoteButtons extends Component { state: VotesState = { upvoteLoading: false, downvoteLoading: false, }; constructor(props: any, context: any) { 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 (
{showScores() ? (
{numToSI(this.props.counts.score)}
) : (
)} {this.props.enableDownvotes && ( )}
); } }