summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ui/src/components/create-post.tsx12
-rw-r--r--ui/src/components/navbar.tsx6
-rw-r--r--ui/src/components/post-form.tsx4
3 files changed, 20 insertions, 2 deletions
diff --git a/ui/src/components/create-post.tsx b/ui/src/components/create-post.tsx
index e2998ca7..1958be72 100644
--- a/ui/src/components/create-post.tsx
+++ b/ui/src/components/create-post.tsx
@@ -18,13 +18,23 @@ export class CreatePost extends Component<any, any> {
<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}`);
}
diff --git a/ui/src/components/navbar.tsx b/ui/src/components/navbar.tsx
index 31dab61b..ee19e5c5 100644
--- a/ui/src/components/navbar.tsx
+++ b/ui/src/components/navbar.tsx
@@ -79,7 +79,7 @@ export class Navbar extends Component<any, NavbarState> {
<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>
@@ -165,6 +165,10 @@ export class Navbar extends Component<any, NavbarState> {
}
}
+ 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});
}
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx
index ab936282..e4e75df4 100644
--- a/ui/src/components/post-form.tsx
+++ b/ui/src/components/post-form.tsx
@@ -8,6 +8,7 @@ import * as autosize from 'autosize';
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;
@@ -170,6 +171,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
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;
}