import { Component, linkEvent } from 'inferno'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; import { UserOperation, Community, Post as PostI, PostResponse, Comment, CommentForm } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp } from '../utils'; interface State { post: PostI; commentForm: CommentForm; comments: Array; } export class Post extends Component { private subscription: Subscription; private emptyState: State = { post: { name: null, attributed_to: null, community_id: null, id: null, published: null, }, commentForm: { auth: null, content: null, post_id: null }, comments: [] } constructor(props, context) { super(props, context); let postId = Number(this.props.match.params.id); this.state = this.emptyState; this.state.commentForm.post_id = postId; this.subscription = WebSocketService.Instance.subject .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10)))) .subscribe( (msg) => this.parseMessage(msg), (err) => console.error(err), () => console.log('complete') ); WebSocketService.Instance.getPost(postId); } componentWillUnmount() { this.subscription.unsubscribe(); } render() { return (
{this.state.post.name} {this.commentForm()} {this.comments()}
) } comments() { return (

Comments

{this.state.comments.map(comment =>
{comment.content}
)}
) } commentForm() { return (

Create Comment