]> Untitled Git - lemmy.git/blob - ui/src/components/create-post.tsx
Merge branch 'master' into master
[lemmy.git] / ui / src / components / create-post.tsx
1 import { Component } from 'inferno';
2 import { PostForm } from './post-form';
3
4 export class CreatePost extends Component<any, any> {
5
6   constructor(props: any, context: any) {
7     super(props, context);
8     this.handlePostCreate = this.handlePostCreate.bind(this);
9   }
10
11   componentDidMount() {
12     document.title = "Create Post - Lemmy";
13   }
14
15   render() {
16     return (
17       <div class="container">
18         <div class="row">
19           <div class="col-12 col-lg-6 mb-4">
20             <h5>Create a Post</h5>
21             <PostForm onCreate={this.handlePostCreate} prevCommunityName={this.prevCommunityName} />
22           </div>
23         </div>
24       </div>
25     )
26   }
27
28   get prevCommunityName(): string {
29     if (this.props.location.state) {
30       let lastLocation = this.props.location.state.prevPath;
31       if (lastLocation.includes("/c/")) {
32         return lastLocation.split("/c/")[1];
33       }    
34     }
35     return undefined;
36   }
37
38   handlePostCreate(id: number) {
39     this.props.history.push(`/post/${id}`);
40   }
41 }
42
43