import { Component, linkEvent } from 'inferno'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; import { PostForm as PostFormI, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp } from '../utils'; import { MomentTime } from './moment-time'; interface PostFormProps { post?: Post; // If a post is given, that means this is an edit onCancel?(); onCreate?(id: number); onEdit?(post: Post); } interface PostFormState { postForm: PostFormI; communities: Array; } export class PostForm extends Component { private subscription: Subscription; private emptyState: PostFormState = { postForm: { name: null, auth: null, community_id: null }, communities: [] } constructor(props, context) { super(props, context); this.state = this.emptyState; if (this.props.post) { this.state.postForm = { body: this.props.post.body, name: this.props.post.name, community_id: this.props.post.community_id, edit_id: this.props.post.id, url: this.props.post.url, auth: null } } 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.listCommunities(); } componentWillUnmount() { this.subscription.unsubscribe(); } render() { return (