]> Untitled Git - lemmy.git/blob - ui/src/components/create-post.tsx
Adding emoji support.
[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 import { PostFormParams } from '../interfaces';
5 import { i18n } from '../i18next';
6 import { T } from 'inferno-i18next';
7
8 export class CreatePost extends Component<any, any> {
9
10   constructor(props: any, context: any) {
11     super(props, context);
12     this.handlePostCreate = this.handlePostCreate.bind(this);
13   }
14
15   componentDidMount() {
16     document.title = `${i18n.t('create_post')} - ${WebSocketService.Instance.site.name}`;
17   }
18
19   render() {
20     return (
21       <div class="container">
22         <div class="row">
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} />
26           </div>
27         </div>
28       </div>
29     )
30   }
31
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"),
39     };
40
41     return params;
42   }
43
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];
51       }    
52     }
53     return undefined;
54   }
55
56   handlePostCreate(id: number) {
57     this.props.history.push(`/post/${id}`);
58   }
59 }
60
61