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> {
10 constructor(props: any, context: any) {
11 super(props, context);
12 this.handlePostCreate = this.handlePostCreate.bind(this);
16 document.title = `${i18n.t('create_post')} - ${WebSocketService.Instance.site.name}`;
21 <div class="container">
23 <div class="col-12 col-lg-6 offset-lg-3 mb-4">
24 <h5><T i18nKey="create_post">#</T></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("name"),
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}`);