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';
8 import { Community } from '../interfaces';
11 communityForm: CommunityForm;
14 let emptyState: State = {
20 export class CreateCommunity extends Component<any, State> {
21 private subscription: Subscription;
23 constructor(props, context) {
24 super(props, context);
26 this.state = emptyState;
28 this.subscription = WebSocketService.Instance.subject
29 .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
31 (msg) => this.parseMessage(msg),
32 (err) => console.error(err),
33 () => console.log("complete")
37 componentWillUnmount() {
38 this.subscription.unsubscribe();
43 <div class="container">
45 <div class="col-12 col-lg-6 mb-4">
46 {this.communityForm()}
56 <form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
58 <div class="form-group row">
59 <label class="col-sm-2 col-form-label">Name</label>
60 <div class="col-sm-10">
61 <input type="text" class="form-control" value={this.state.communityForm.name} onInput={linkEvent(this, this.handleCommunityNameChange)} required minLength={3} />
64 <div class="form-group row">
65 <div class="col-sm-10">
66 <button type="submit" class="btn btn-secondary">Create</button>
74 handleCreateCommunitySubmit(i: CreateCommunity, event) {
75 event.preventDefault();
76 WebSocketService.Instance.createCommunity(i.state.communityForm);
79 handleCommunityNameChange(i: CreateCommunity, event) {
80 i.state.communityForm.name = event.target.value;
84 parseMessage(msg: any) {
85 let op: UserOperation = msgOp(msg);
91 if (op == UserOperation.CreateCommunity) {
92 let community: Community = msg.data;