summaryrefslogtreecommitdiffstats
path: root/ui/src/components/community-form.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2019-10-18 17:20:27 -0700
committerDessalines <tyhou13@gmx.com>2019-10-18 17:20:27 -0700
commit4e5561283392d2ab1545cabb4455a8ffc490f86b (patch)
treea4ee9cc096826dc32faf3675212c7f95f1b3ea5e /ui/src/components/community-form.tsx
parent82ea5ae9186e5a8e631c87a61077e16713eb87a4 (diff)
Running prettier on code.
- #305 , #309
Diffstat (limited to 'ui/src/components/community-form.tsx')
-rw-r--r--ui/src/components/community-form.tsx134
1 files changed, 103 insertions, 31 deletions
diff --git a/ui/src/components/community-form.tsx b/ui/src/components/community-form.tsx
index 833d8a3f..e6c8ef09 100644
--- a/ui/src/components/community-form.tsx
+++ b/ui/src/components/community-form.tsx
@@ -1,7 +1,13 @@
import { Component, linkEvent } from 'inferno';
-import { Subscription } from "rxjs";
+import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
-import { CommunityForm as CommunityFormI, UserOperation, Category, ListCategoriesResponse, CommunityResponse } from '../interfaces';
+import {
+ CommunityForm as CommunityFormI,
+ UserOperation,
+ Category,
+ ListCategoriesResponse,
+ CommunityResponse,
+} from '../interfaces';
import { WebSocketService } from '../services';
import { msgOp, capitalizeFirstLetter } from '../utils';
import * as autosize from 'autosize';
@@ -23,7 +29,10 @@ interface CommunityFormState {
loading: boolean;
}
-export class CommunityForm extends Component<CommunityFormProps, CommunityFormState> {
+export class CommunityForm extends Component<
+ CommunityFormProps,
+ CommunityFormState
+> {
private subscription: Subscription;
private emptyState: CommunityFormState = {
@@ -34,8 +43,8 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt
nsfw: false,
},
categories: [],
- loading: false
- }
+ loading: false,
+ };
constructor(props: any, context: any) {
super(props, context);
@@ -50,16 +59,23 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt
description: this.props.community.description,
edit_id: this.props.community.id,
nsfw: this.props.community.nsfw,
- auth: null
- }
+ auth: null,
+ };
}
this.subscription = WebSocketService.Instance.subject
- .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
+ .pipe(
+ retryWhen(errors =>
+ errors.pipe(
+ delay(3000),
+ take(10)
+ )
+ )
+ )
.subscribe(
- (msg) => this.parseMessage(msg),
- (err) => console.error(err),
- () => console.log("complete")
+ msg => this.parseMessage(msg),
+ err => console.error(err),
+ () => console.log('complete')
);
WebSocketService.Instance.listCategories();
@@ -73,53 +89,110 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt
this.subscription.unsubscribe();
}
-
render() {
return (
<form onSubmit={linkEvent(this, this.handleCreateCommunitySubmit)}>
<div class="form-group row">
- <label class="col-12 col-form-label"><T i18nKey="name">#</T></label>
+ <label class="col-12 col-form-label">
+ <T i18nKey="name">#</T>
+ </label>
<div class="col-12">
- <input type="text" class="form-control" value={this.state.communityForm.name} onInput={linkEvent(this, this.handleCommunityNameChange)} required minLength={3} maxLength={20} pattern="[a-z0-9_]+" title={i18n.t('community_reqs')}/>
+ <input
+ type="text"
+ class="form-control"
+ value={this.state.communityForm.name}
+ onInput={linkEvent(this, this.handleCommunityNameChange)}
+ required
+ minLength={3}
+ maxLength={20}
+ pattern="[a-z0-9_]+"
+ title={i18n.t('community_reqs')}
+ />
</div>
</div>
<div class="form-group row">
- <label class="col-12 col-form-label"><T i18nKey="title">#</T></label>
+ <label class="col-12 col-form-label">
+ <T i18nKey="title">#</T>
+ </label>
<div class="col-12">
- <input type="text" value={this.state.communityForm.title} onInput={linkEvent(this, this.handleCommunityTitleChange)} class="form-control" required minLength={3} maxLength={100} />
+ <input
+ type="text"
+ value={this.state.communityForm.title}
+ onInput={linkEvent(this, this.handleCommunityTitleChange)}
+ class="form-control"
+ required
+ minLength={3}
+ maxLength={100}
+ />
</div>
</div>
<div class="form-group row">
- <label class="col-12 col-form-label"><T i18nKey="sidebar">#</T></label>
+ <label class="col-12 col-form-label">
+ <T i18nKey="sidebar">#</T>
+ </label>
<div class="col-12">
- <textarea value={this.state.communityForm.description} onInput={linkEvent(this, this.handleCommunityDescriptionChange)} class="form-control" rows={3} maxLength={10000} />
+ <textarea
+ value={this.state.communityForm.description}
+ onInput={linkEvent(this, this.handleCommunityDescriptionChange)}
+ class="form-control"
+ rows={3}
+ maxLength={10000}
+ />
</div>
</div>
<div class="form-group row">
- <label class="col-12 col-form-label"><T i18nKey="category">#</T></label>
+ <label class="col-12 col-form-label">
+ <T i18nKey="category">#</T>
+ </label>
<div class="col-12">
- <select class="form-control" value={this.state.communityForm.category_id} onInput={linkEvent(this, this.handleCommunityCategoryChange)}>
- {this.state.categories.map(category =>
+ <select
+ class="form-control"
+ value={this.state.communityForm.category_id}
+ onInput={linkEvent(this, this.handleCommunityCategoryChange)}
+ >
+ {this.state.categories.map(category => (
<option value={category.id}>{category.name}</option>
- )}
+ ))}
</select>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<div class="form-check">
- <input class="form-check-input" type="checkbox" checked={this.state.communityForm.nsfw} onChange={linkEvent(this, this.handleCommunityNsfwChange)}/>
- <label class="form-check-label"><T i18nKey="nsfw">#</T></label>
+ <input
+ class="form-check-input"
+ type="checkbox"
+ checked={this.state.communityForm.nsfw}
+ onChange={linkEvent(this, this.handleCommunityNsfwChange)}
+ />
+ <label class="form-check-label">
+ <T i18nKey="nsfw">#</T>
+ </label>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-12">
<button type="submit" class="btn btn-secondary mr-2">
- {this.state.loading ?
- <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> :
- this.props.community ? capitalizeFirstLetter(i18n.t('save')) : capitalizeFirstLetter(i18n.t('create'))}</button>
- {this.props.community && <button type="button" class="btn btn-secondary" onClick={linkEvent(this, this.handleCancel)}><T i18nKey="cancel">#</T></button>}
+ {this.state.loading ? (
+ <svg class="icon icon-spinner spin">
+ <use xlinkHref="#icon-spinner"></use>
+ </svg>
+ ) : this.props.community ? (
+ capitalizeFirstLetter(i18n.t('save'))
+ ) : (
+ capitalizeFirstLetter(i18n.t('create'))
+ )}
+ </button>
+ {this.props.community && (
+ <button
+ type="button"
+ class="btn btn-secondary"
+ onClick={linkEvent(this, this.handleCancel)}
+ >
+ <T i18nKey="cancel">#</T>
+ </button>
+ )}
</div>
</div>
</form>
@@ -174,7 +247,7 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt
this.state.loading = false;
this.setState(this.state);
return;
- } else if (op == UserOperation.ListCategories){
+ } else if (op == UserOperation.ListCategories) {
let res: ListCategoriesResponse = msg;
this.state.categories = res.categories;
if (!this.props.community) {
@@ -185,7 +258,7 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt
let res: CommunityResponse = msg;
this.state.loading = false;
this.props.onCreate(res.community);
- }
+ }
// TODO is ths necessary
else if (op == UserOperation.EditCommunity) {
let res: CommunityResponse = msg;
@@ -193,5 +266,4 @@ export class CommunityForm extends Component<CommunityFormProps, CommunityFormSt
this.props.onEdit(res.community);
}
}
-
}