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';
6 import { T } from 'inferno-i18next';
8 export class CreatePost extends Component<any, any> {
9 constructor(props: any, context: any) {
10 super(props, context);
11 this.handlePostCreate = this.handlePostCreate.bind(this);
15 document.title = `${i18n.t('create_post')} - ${
16 WebSocketService.Instance.site.name
22 <div class="container">
24 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
26 { i18n.t('create_post') }
28 <PostForm onCreate={this.handlePostCreate} params={this.params} />
35 get params(): PostFormParams {
36 let urlParams = new URLSearchParams(this.props.location.search);
37 let params: PostFormParams = {
38 name: urlParams.get('title'),
39 community: urlParams.get('community') || this.prevCommunityName,
40 body: urlParams.get('body'),
41 url: urlParams.get('url'),
47 get prevCommunityName(): string {
48 if (this.props.match.params.name) {
49 return this.props.match.params.name;
50 } else if (this.props.location.state) {
51 let lastLocation = this.props.location.state.prevPath;
52 if (lastLocation.includes('/c/')) {
53 return lastLocation.split('/c/')[1];
59 handlePostCreate(id: number) {
60 this.props.history.push(`/post/${id}`);