page.
Fixes #133
<div class="row">
<div class="col-12 col-lg-6 mb-4">
<h5>Create a Post</h5>
- <PostForm onCreate={this.handlePostCreate}/>
+ <PostForm onCreate={this.handlePostCreate} prevCommunityName={this.prevCommunityName} />
</div>
</div>
</div>
)
}
+ get prevCommunityName(): string {
+ if (this.props.location.state) {
+ let lastLocation = this.props.location.state.prevPath;
+ if (lastLocation.includes("/c/")) {
+ return lastLocation.split("/c/")[1];
+ }
+ }
+ return undefined;
+ }
+
handlePostCreate(id: number) {
this.props.history.push(`/post/${id}`);
}
<Link class="nav-link" to="/search">Search</Link>
</li>
<li class="nav-item">
- <Link class="nav-link" to="/create_post">Create Post</Link>
+ <Link class="nav-link" to={{pathname: '/create_post', state: { prevPath: this.currentLocation }}}>Create Post</Link>
</li>
<li class="nav-item">
<Link class="nav-link" to="/create_community">Create Community</Link>
}
}
+ get currentLocation() {
+ return this.context.router.history.location.pathname;
+ }
+
sendRepliesCount(res: GetRepliesResponse) {
UserService.Instance.sub.next({user: UserService.Instance.user, unreadCount: res.replies.filter(r => !r.read).length});
}
interface PostFormProps {
post?: Post; // If a post is given, that means this is an edit
+ prevCommunityName?: string;
onCancel?(): any;
onCreate?(id: number): any;
onEdit?(post: Post): any;
this.state.communities = res.communities;
if (this.props.post) {
this.state.postForm.community_id = this.props.post.community_id;
+ } else if (this.props.prevCommunityName) {
+ let foundCommunityId = res.communities.find(r => r.name == this.props.prevCommunityName).id;
+ this.state.postForm.community_id = foundCommunityId;
} else {
this.state.postForm.community_id = res.communities[0].id;
}