]> Untitled Git - lemmy.git/blob - ui/src/components/create-post.tsx
Adding create community and post buttons from sidebar.
[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.match.params.name) {
30       return this.props.match.params.name;
31     } else if (this.props.location.state) {
32       let lastLocation = this.props.location.state.prevPath;
33       if (lastLocation.includes("/c/")) {
34         return lastLocation.split("/c/")[1];
35       }    
36     }
37     return undefined;
38   }
39
40   handlePostCreate(id: number) {
41     this.props.history.push(`/post/${id}`);
42   }
43 }
44
45