From add2f61f42ea41babd1b5c324fdf3393202061eb Mon Sep 17 00:00:00 2001 From: Dessalines Date: Thu, 24 Sep 2020 08:42:20 -0500 Subject: [PATCH] Fix create post from community bug. Fixes #39 --- src/server/index.tsx | 2 +- src/shared/components/post-form.tsx | 28 +++++++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/server/index.tsx b/src/server/index.tsx index 33cfe57..e7278d6 100644 --- a/src/server/index.tsx +++ b/src/server/index.tsx @@ -24,7 +24,7 @@ server.use('/static', express.static(path.resolve('./dist'))); // server.use(cookieParser()); server.get('/*', async (req, res) => { - const activeRoute = routes.find(route => matchPath(req.url, route)) || {}; + const activeRoute = routes.find(route => matchPath(req.path, route)) || {}; const context = {} as any; let auth: string = IsomorphicCookie.load('jwt', req); diff --git a/src/shared/components/post-form.tsx b/src/shared/components/post-form.tsx index 6137f53..5c3c753 100644 --- a/src/shared/components/post-form.tsx +++ b/src/shared/components/post-form.tsx @@ -524,17 +524,6 @@ export class PostForm extends Component { } setupCommunities() { - if (this.props.post) { - this.state.postForm.community_id = this.props.post.community_id; - } else if (this.props.params && this.props.params.community) { - let foundCommunityId = this.props.communities.find( - r => r.name == this.props.params.community - ).id; - this.state.postForm.community_id = foundCommunityId; - } else { - // By default, the null valued 'Select a Community' - } - // Set up select searching if (isBrowser()) { let selectId: any = document.getElementById('post-community'); @@ -580,6 +569,23 @@ export class PostForm extends Component { ); } } + + if (this.props.post) { + this.state.postForm.community_id = this.props.post.community_id; + } else if (this.props.params && this.props.params.community) { + let foundCommunityId = this.props.communities.find( + r => r.name == this.props.params.community + ).id; + this.state.postForm.community_id = foundCommunityId; + if (isBrowser()) { + this.choices.setChoiceByValue( + this.state.postForm.community_id.toString() + ); + } + this.setState(this.state); + } else { + // By default, the null valued 'Select a Community' + } } parseMessage(msg: WebSocketJsonResponse) { -- 2.44.1