import { Component, linkEvent } from 'inferno'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; import { CommunityForm, UserOperation } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp } from '../utils'; import { Community } from '../interfaces'; interface State { communityForm: CommunityForm; } export class CreateCommunity extends Component { private subscription: Subscription; private emptyState: State = { communityForm: { name: null, } } constructor(props, context) { super(props, context); this.state = this.emptyState; 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") ); } componentWillUnmount() { this.subscription.unsubscribe(); } render() { return (
{this.communityForm()}
) } communityForm() { return (

Create Forum

); } handleCreateCommunitySubmit(i: CreateCommunity, event) { event.preventDefault(); WebSocketService.Instance.createCommunity(i.state.communityForm); } handleCommunityNameChange(i: CreateCommunity, event) { i.state.communityForm.name = event.target.value; } parseMessage(msg: any) { let op: UserOperation = msgOp(msg); console.log(msg); if (msg.error) { alert(msg.error); return; } else { if (op == UserOperation.CreateCommunity) { let community: Community = msg.community; this.props.history.push(`/community/${community.id}`); } } } }