summaryrefslogtreecommitdiffstats
path: root/ui/src/components/post-form.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/components/post-form.tsx')
-rw-r--r--ui/src/components/post-form.tsx37
1 files changed, 23 insertions, 14 deletions
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx
index d21b2fb4..f502e7f3 100644
--- a/ui/src/components/post-form.tsx
+++ b/ui/src/components/post-form.tsx
@@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno';
import { PostListings } from './post-listings';
import { Subscription } from "rxjs";
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 { msgOp, getPageTitle, debounce, validURL, capitalizeFirstLetter } from '../utils';
import * as autosize from 'autosize';
@@ -11,7 +11,7 @@ import { T } from 'inferno-i18next';
interface PostFormProps {
post?: Post; // If a post is given, that means this is an edit
- prevCommunityName?: string;
+ params?: PostFormParams;
onCancel?(): any;
onCreate?(id: number): any;
onEdit?(post: Post): any;
@@ -62,20 +62,30 @@ 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
- .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
- .subscribe(
- (msg) => this.parseMessage(msg),
+ .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
+ .subscribe(
+ (msg) => this.parseMessage(msg),
(err) => console.error(err),
() => console.log('complete')
- );
+ );
- let listCommunitiesForm: ListCommunitiesForm = {
- sort: SortType[SortType.TopAll],
- limit: 9999,
- }
+ let listCommunitiesForm: ListCommunitiesForm = {
+ sort: SortType[SortType.TopAll],
+ limit: 9999,
+ }
- WebSocketService.Instance.listCommunities(listCommunitiesForm);
+ WebSocketService.Instance.listCommunities(listCommunitiesForm);
}
componentDidMount() {
@@ -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} />
</div>
</div>
- {/* Cant change a community from an edit */}
{!this.props.post &&
<div class="form-group row">
<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;
if (this.props.post) {
this.state.postForm.community_id = this.props.post.community_id;
- } else if (this.props.prevCommunityName) {
- let foundCommunityId = res.communities.find(r => r.name == this.props.prevCommunityName).id;
+ } else if (this.props.params && this.props.params.community) {
+ let foundCommunityId = res.communities.find(r => r.name == this.props.params.community).id;
this.state.postForm.community_id = foundCommunityId;
} else {
this.state.postForm.community_id = res.communities[0].id;