1 import { Component } from 'inferno';
2 import { PostForm } from './post-form';
3 import { WebSocketService } from '../services';
4 import { PostFormParams } from '../interfaces';
5 import { i18n } from '../i18next';
7 export class CreatePost extends Component<any, any> {
8 constructor(props: any, context: any) {
10 this.handlePostCreate = this.handlePostCreate.bind(this);
14 document.title = `${i18n.t('create_post')} - ${
15 WebSocketService.Instance.site.name
21 <div class="container">
23 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
24 <h5>{i18n.t('create_post')}</h5>
25 <PostForm onCreate={this.handlePostCreate} params={this.params} />
32 get params(): PostFormParams {
33 let urlParams = new URLSearchParams(this.props.location.search);
34 let params: PostFormParams = {
35 name: urlParams.get('title'),
36 community: urlParams.get('community') || this.prevCommunityName,
37 body: urlParams.get('body'),
38 url: urlParams.get('url'),
44 get prevCommunityName(): string {
45 if (this.props.match.params.name) {
46 return this.props.match.params.name;
47 } else if (this.props.location.state) {
48 let lastLocation = this.props.location.state.prevPath;
49 if (lastLocation.includes('/c/')) {
50 return lastLocation.split('/c/')[1];
56 handlePostCreate(id: number) {
57 this.props.history.push(`/post/${id}`);