1 import { Component, linkEvent } from 'inferno';
2 import { Subscription } from "rxjs";
3 import { retryWhen, delay, take } from 'rxjs/operators';
4 import { CommunityForm, UserOperation } from '../interfaces';
5 import { WebSocketService, UserService } from '../services';
6 import { msgOp } from '../utils';
9 communityForm: CommunityForm;
12 let emptyState: State = {
18 export class CreateCommunity extends Component<any, State> {
19 private subscription: Subscription;
21 constructor(props, context) {
22 super(props, context);
24 this.state = emptyState;
26 this.subscription = WebSocketService.Instance.subject
27 .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
29 (msg) => this.parseMessage(msg),
30 (err) => console.error(err),
34 componentWillUnmount() {
35 this.subscription.unsubscribe();
40 <div class="container">
42 <div class="col-12 col-lg-6 mb-4">
43 {this.communityForm()}
53 <form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
55 <div class="form-group row">
56 <label class="col-sm-2 col-form-label">Name</label>
57 <div class="col-sm-10">
58 <input type="text" class="form-control" value={this.state.communityForm.name} onInput={linkEvent(this, this.handleCommunityNameChange)} required minLength={3} />
61 <div class="form-group row">
62 <div class="col-sm-10">
63 <button type="submit" class="btn btn-secondary">Create</button>
71 handleCreateCommunitySubmit(i: CreateCommunity, event) {
72 event.preventDefault();
73 WebSocketService.Instance.createCommunity(i.state.communityForm);
76 handleCommunityNameChange(i: CreateCommunity, event) {
77 i.state.communityForm.name = event.target.value;
81 parseMessage(msg: any) {
82 let op: UserOperation = msgOp(msg);