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