2019-04-08 05:19:02 +00:00
|
|
|
import { Component } from 'inferno';
|
2019-04-03 20:59:37 +00:00
|
|
|
import { PostForm } from './post-form';
|
2019-06-03 01:35:46 +00:00
|
|
|
import { WebSocketService } from '../services';
|
2019-08-22 23:13:26 +00:00
|
|
|
import { PostFormParams } from '../interfaces';
|
2019-08-10 00:14:43 +00:00
|
|
|
import { i18n } from '../i18next';
|
|
|
|
import { T } from 'inferno-i18next';
|
2019-03-23 01:42:57 +00:00
|
|
|
|
2019-04-03 20:59:37 +00:00
|
|
|
export class CreatePost extends Component<any, any> {
|
2019-03-26 18:00:18 +00:00
|
|
|
|
2019-04-08 05:19:02 +00:00
|
|
|
constructor(props: any, context: any) {
|
2019-03-23 01:42:57 +00:00
|
|
|
super(props, context);
|
2019-04-03 20:59:37 +00:00
|
|
|
this.handlePostCreate = this.handlePostCreate.bind(this);
|
2019-03-26 18:00:18 +00:00
|
|
|
}
|
2019-03-23 01:42:57 +00:00
|
|
|
|
2019-04-22 16:24:13 +00:00
|
|
|
componentDidMount() {
|
2019-08-10 00:14:43 +00:00
|
|
|
document.title = `${i18n.t('create_post')} - ${WebSocketService.Instance.site.name}`;
|
2019-04-22 16:24:13 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 01:42:57 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div class="container">
|
|
|
|
<div class="row">
|
2019-07-29 01:57:09 +00:00
|
|
|
<div class="col-12 col-lg-6 offset-lg-3 mb-4">
|
2019-08-10 00:14:43 +00:00
|
|
|
<h5><T i18nKey="create_post">#</T></h5>
|
2019-08-22 23:13:26 +00:00
|
|
|
<PostForm onCreate={this.handlePostCreate} params={this.params} />
|
2019-03-23 01:42:57 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-08-22 23:13:26 +00:00
|
|
|
get params(): PostFormParams {
|
|
|
|
let urlParams = new URLSearchParams(this.props.location.search);
|
|
|
|
let params: PostFormParams = {
|
|
|
|
name: urlParams.get("name"),
|
|
|
|
community: urlParams.get("community") || this.prevCommunityName,
|
|
|
|
body: urlParams.get("body"),
|
|
|
|
url: urlParams.get("url"),
|
|
|
|
};
|
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2019-04-29 16:07:41 +00:00
|
|
|
get prevCommunityName(): string {
|
2019-05-08 16:07:34 +00:00
|
|
|
if (this.props.match.params.name) {
|
|
|
|
return this.props.match.params.name;
|
|
|
|
} else if (this.props.location.state) {
|
2019-04-29 16:07:41 +00:00
|
|
|
let lastLocation = this.props.location.state.prevPath;
|
|
|
|
if (lastLocation.includes("/c/")) {
|
|
|
|
return lastLocation.split("/c/")[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2019-04-03 20:59:37 +00:00
|
|
|
handlePostCreate(id: number) {
|
|
|
|
this.props.history.push(`/post/${id}`);
|
2019-03-26 18:00:18 +00:00
|
|
|
}
|
2019-04-03 20:59:37 +00:00
|
|
|
}
|
2019-03-26 18:00:18 +00:00
|
|
|
|
2019-03-23 01:42:57 +00:00
|
|
|
|