|
|
@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno';
|
|
|
|
import { PostListings } from './post-listings';
|
|
|
|
import { PostListings } from './post-listings';
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
|
|
|
import { retryWhen, delay, take } from 'rxjs/operators';
|
|
|
|
import { PostForm as PostFormI, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces';
|
|
|
|
import { PostForm as PostFormI, PostFormParams, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType, SearchForm, SearchType, SearchResponse } from '../interfaces';
|
|
|
|
import { WebSocketService, UserService } from '../services';
|
|
|
|
import { WebSocketService, UserService } from '../services';
|
|
|
|
import { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter } from '../utils';
|
|
|
|
import { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter } from '../utils';
|
|
|
|
import * as autosize from 'autosize';
|
|
|
|
import * as autosize from 'autosize';
|
|
|
@ -11,7 +11,7 @@ import { T } from 'inferno-i18next';
|
|
|
|
|
|
|
|
|
|
|
|
interface PostFormProps {
|
|
|
|
interface PostFormProps {
|
|
|
|
post?: Post; // If a post is given, that means this is an edit
|
|
|
|
post?: Post; // If a post is given, that means this is an edit
|
|
|
|
prevCommunityName?: string;
|
|
|
|
params?: PostFormParams;
|
|
|
|
onCancel?(): any;
|
|
|
|
onCancel?(): any;
|
|
|
|
onCreate?(id: number): any;
|
|
|
|
onCreate?(id: number): any;
|
|
|
|
onEdit?(post: Post): any;
|
|
|
|
onEdit?(post: Post): any;
|
|
|
@ -62,6 +62,16 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.props.params) {
|
|
|
|
|
|
|
|
this.state.postForm.name = this.props.params.name;
|
|
|
|
|
|
|
|
if (this.props.params.url) {
|
|
|
|
|
|
|
|
this.state.postForm.url = this.props.params.url;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.props.params.body) {
|
|
|
|
|
|
|
|
this.state.postForm.body = this.props.params.body;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.subscription = WebSocketService.Instance.subject
|
|
|
|
this.subscription = WebSocketService.Instance.subject
|
|
|
|
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
|
|
|
|
.pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
|
|
|
|
.subscribe(
|
|
|
|
.subscribe(
|
|
|
@ -123,7 +133,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|
|
|
<textarea value={this.state.postForm.body} onInput={linkEvent(this, this.handlePostBodyChange)} class="form-control" rows={4} maxLength={10000} />
|
|
|
|
<textarea value={this.state.postForm.body} onInput={linkEvent(this, this.handlePostBodyChange)} class="form-control" rows={4} maxLength={10000} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{/* Cant change a community from an edit */}
|
|
|
|
|
|
|
|
{!this.props.post &&
|
|
|
|
{!this.props.post &&
|
|
|
|
<div class="form-group row">
|
|
|
|
<div class="form-group row">
|
|
|
|
<label class="col-sm-2 col-form-label"><T i18nKey="community">#</T></label>
|
|
|
|
<label class="col-sm-2 col-form-label"><T i18nKey="community">#</T></label>
|
|
|
@ -253,8 +262,8 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
|
|
|
this.state.communities = res.communities;
|
|
|
|
this.state.communities = res.communities;
|
|
|
|
if (this.props.post) {
|
|
|
|
if (this.props.post) {
|
|
|
|
this.state.postForm.community_id = this.props.post.community_id;
|
|
|
|
this.state.postForm.community_id = this.props.post.community_id;
|
|
|
|
} else if (this.props.prevCommunityName) {
|
|
|
|
} else if (this.props.params && this.props.params.community) {
|
|
|
|
let foundCommunityId = res.communities.find(r => r.name == this.props.prevCommunityName).id;
|
|
|
|
let foundCommunityId = res.communities.find(r => r.name == this.props.params.community).id;
|
|
|
|
this.state.postForm.community_id = foundCommunityId;
|
|
|
|
this.state.postForm.community_id = foundCommunityId;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
this.state.postForm.community_id = res.communities[0].id;
|
|
|
|
this.state.postForm.community_id = res.communities[0].id;
|
|
|
|