import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; import { WebSocketService, UserService } from '../services'; import { Post, CreatePostLikeResponse, CreatePostLikeForm } from '../interfaces'; import { MomentTime } from './moment-time'; import { mdToHtml } from '../utils'; interface PostListingState { } interface PostListingProps { post: Post; showCommunity?: boolean; showBody?: boolean; } export class PostListing extends Component { private emptyState: PostListingState = { } constructor(props, context) { super(props, context); this.state = this.emptyState; this.handlePostLike = this.handlePostLike.bind(this); this.handlePostDisLike = this.handlePostDisLike.bind(this); } render() { let post = this.props.post; return (
{post.score}
{post.url ?
{post.name} {(new URL(post.url)).hostname}
:
{post.name}
}
  • by {post.creator_name} {this.props.showCommunity && to {post.community_name} }
  • ( +{post.upvotes} | -{post.downvotes} )
  • {post.number_of_comments} Comments
{this.props.showBody && this.props.post.body &&
}
) } // private get myPost(): boolean { // return this.props.node.comment.attributed_to == UserService.Instance.fediUserId; // } handlePostLike(i: PostListing, event) { let form: CreatePostLikeForm = { post_id: i.props.post.id, score: (i.props.post.my_vote == 1) ? 0 : 1 }; WebSocketService.Instance.likePost(form); } handlePostDisLike(i: PostListing, event) { let form: CreatePostLikeForm = { post_id: i.props.post.id, score: (i.props.post.my_vote == -1) ? 0 : -1 }; WebSocketService.Instance.likePost(form); } }