diff options
Diffstat (limited to 'ui/src/components/post-form.tsx')
-rw-r--r-- | ui/src/components/post-form.tsx | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index bec73812..50b4acd1 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -3,11 +3,12 @@ import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; import { PostForm as PostFormI, Post, PostResponse, UserOperation, Community, ListCommunitiesResponse, ListCommunitiesForm, SortType } from '../interfaces'; import { WebSocketService, UserService } from '../services'; -import { msgOp } from '../utils'; +import { msgOp, getPageTitle } from '../utils'; import * as autosize from 'autosize'; interface PostFormProps { post?: Post; // If a post is given, that means this is an edit + prevCommunityName?: string; onCancel?(): any; onCreate?(id: number): any; onEdit?(post: Post): any; @@ -17,6 +18,7 @@ interface PostFormState { postForm: PostFormI; communities: Array<Community>; loading: boolean; + suggestedTitle: string; } export class PostForm extends Component<PostFormProps, PostFormState> { @@ -30,7 +32,8 @@ export class PostForm extends Component<PostFormProps, PostFormState> { creator_id: (UserService.Instance.user) ? UserService.Instance.user.id : null, }, communities: [], - loading: false + loading: false, + suggestedTitle: undefined, } constructor(props: any, context: any) { @@ -82,6 +85,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> { <label class="col-sm-2 col-form-label">URL</label> <div class="col-sm-10"> <input type="url" class="form-control" value={this.state.postForm.url} onInput={linkEvent(this, this.handlePostUrlChange)} /> + {this.state.suggestedTitle && + <span class="text-muted small font-weight-bold pointer" onClick={linkEvent(this, this.copySuggestedTitle)}>copy suggested title: {this.state.suggestedTitle}</span> + } </div> </div> <div class="form-group row"> @@ -93,13 +99,13 @@ export class PostForm extends Component<PostFormProps, PostFormState> { <div class="form-group row"> <label class="col-sm-2 col-form-label">Body</label> <div class="col-sm-10"> - <textarea value={this.state.postForm.body} onInput={linkEvent(this, this.handlePostBodyChange)} class="form-control" rows={4} /> + <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">Forum</label> + <label class="col-sm-2 col-form-label">Community</label> <div class="col-sm-10"> <select class="form-control" value={this.state.postForm.community_id} onInput={linkEvent(this, this.handlePostCommunityChange)}> {this.state.communities.map(community => @@ -134,8 +140,18 @@ export class PostForm extends Component<PostFormProps, PostFormState> { i.setState(i.state); } + copySuggestedTitle(i: PostForm) { + i.state.postForm.name = i.state.suggestedTitle; + i.state.suggestedTitle = undefined; + i.setState(i.state); + } + handlePostUrlChange(i: PostForm, event: any) { i.state.postForm.url = event.target.value; + getPageTitle(i.state.postForm.url).then(d => { + i.state.suggestedTitle = d; + i.setState(i.state); + }); i.setState(i.state); } @@ -170,6 +186,9 @@ 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; + this.state.postForm.community_id = foundCommunityId; } else { this.state.postForm.community_id = res.communities[0].id; } |