From d0099b49412ac76aac196d15e9e08177673d5415 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 29 Apr 2019 09:07:41 -0700 Subject: [PATCH] Auto-select current community if creating a post from the community page. Fixes #133 --- ui/src/components/create-post.tsx | 12 +++++++++++- ui/src/components/navbar.tsx | 6 +++++- ui/src/components/post-form.tsx | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ui/src/components/create-post.tsx b/ui/src/components/create-post.tsx index e2998ca7e..1958be72d 100644 --- a/ui/src/components/create-post.tsx +++ b/ui/src/components/create-post.tsx @@ -18,13 +18,23 @@ export class CreatePost extends Component {
Create a Post
- +
) } + 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 31dab61b6..ee19e5c5b 100644 --- a/ui/src/components/navbar.tsx +++ b/ui/src/components/navbar.tsx @@ -79,7 +79,7 @@ export class Navbar extends Component { Search