diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 5e59d161..394de6ec 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -3,7 +3,6 @@ import { getCommentParentId, myAuth, myAuthRequired, - newVote, showScores, } from "@utils/app"; import { futureDaysToUnixTime, numToSI } from "@utils/helpers"; @@ -56,13 +55,14 @@ import { CommentNodeI, CommentViewType, PurgeType, - VoteType, + VoteContentType, } from "../../interfaces"; import { mdToHtml, mdToHtmlNoImages } from "../../markdown"; import { I18NextService, UserService } from "../../services"; import { setupTippy } from "../../tippy"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; +import { VoteButtonsCompact } from "../common/vote-buttons"; import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; import { CommentForm } from "./comment-form"; @@ -283,7 +283,7 @@ export class CommentNode extends Component { node.comment_view.counts.child_count > 0; return ( -
  • +
  • { )} {/* This is an expanding spacer for mobile */}
    + {showScores() && ( <> - - {this.state.upvoteLoading ? ( - - ) : ( - - {numToSI(this.commentView.counts.score)} - - )} - + {numToSI(this.commentView.counts.score)} + )} @@ -451,60 +440,14 @@ export class CommentNode extends Component { )} {UserService.Instance.myUserInfo && !this.props.viewOnly && ( <> - - {this.props.enableDownvotes && ( - - )} + + {this.props.enableDownvotes && ( + + )} +
    + ); + } +} + +export class VoteButtons extends Component { + state: VoteButtonsState = { + upvoteLoading: false, + downvoteLoading: false, + }; + + constructor(props: any, context: any) { + super(props, context); + } + + render() { + return ( +
    + + {showScores() ? ( +
    + {numToSI(this.props.counts.score)} +
    + ) : ( +
    + )} + {this.props.enableDownvotes && ( + + )} +
    + ); + } +} diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index d2fe98de..e5694fa7 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1,11 +1,10 @@ -import { myAuthRequired, newVote, showScores } from "@utils/app"; +import { myAuthRequired } from "@utils/app"; import { canShare, share } from "@utils/browser"; import { getExternalHost, getHttpBase } from "@utils/env"; import { capitalizeFirstLetter, futureDaysToUnixTime, hostname, - numToSI, } from "@utils/helpers"; import { isImage, isVideo } from "@utils/media"; import { @@ -44,13 +43,19 @@ import { TransferCommunity, } from "lemmy-js-client"; import { relTags } from "../../config"; -import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces"; +import { + BanType, + PostFormParams, + PurgeType, + VoteContentType, +} from "../../interfaces"; import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown"; import { I18NextService, UserService } from "../../services"; import { setupTippy } from "../../tippy"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; import { PictrsImage } from "../common/pictrs-image"; +import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons"; import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; import { MetadataCard } from "./metadata-card"; @@ -78,8 +83,6 @@ interface PostListingState { showBody: boolean; showReportDialog: boolean; reportReason?: string; - upvoteLoading: boolean; - downvoteLoading: boolean; reportLoading: boolean; blockLoading: boolean; lockLoading: boolean; @@ -142,8 +145,6 @@ export class PostListing extends Component { showMoreMobile: false, showBody: false, showReportDialog: false, - upvoteLoading: false, - downvoteLoading: false, purgeLoading: false, reportLoading: false, blockLoading: false, @@ -169,8 +170,6 @@ export class PostListing extends Component { componentWillReceiveProps(nextProps: PostListingProps) { if (this.props !== nextProps) { this.setState({ - upvoteLoading: false, - downvoteLoading: false, purgeLoading: false, reportLoading: false, blockLoading: false, @@ -424,55 +423,6 @@ export class PostListing extends Component { ); } - voteBar() { - return ( -
    - - {showScores() ? ( -
    - {numToSI(this.postView.counts.score)} -
    - ) : ( -
    - )} - {this.props.enableDownvotes && ( - - )} -
    - ); - } - get postLink() { const post = this.postView.post; return ( @@ -652,7 +602,16 @@ export class PostListing extends Component { )} - {mobile && !this.props.viewOnly && this.mobileVotes} + {mobile && !this.props.viewOnly && ( + + )} {UserService.Instance.myUserInfo && !this.props.viewOnly && this.postActions()} @@ -782,69 +741,6 @@ export class PostListing extends Component { : pv.unread_comments; } - get mobileVotes() { - // TODO: make nicer - const tippy = showScores() - ? { "data-tippy-content": this.pointsTippy } - : {}; - return ( - <> -
    - - {this.props.enableDownvotes && ( - - )} -
    - - ); - } - get saveButton() { const saved = this.postView.saved; const label = saved @@ -943,7 +839,6 @@ export class PostListing extends Component {