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; } let emptyState: State = { communityForm: { name: null, } } export class CreateCommunity extends Component { private subscription: Subscription; constructor(props, context) { super(props, context); this.state = 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; i.setState(i.state); } 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.data; } } } }