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