]> Untitled Git - lemmy-ui.git/commitdiff
Fix create post from community bug. Fixes #39
authorDessalines <tyhou13@gmx.com>
Thu, 24 Sep 2020 13:42:20 +0000 (08:42 -0500)
committerDessalines <tyhou13@gmx.com>
Thu, 24 Sep 2020 13:42:20 +0000 (08:42 -0500)
src/server/index.tsx
src/shared/components/post-form.tsx

index 33cfe57fb99524d9034ea89fbed61d1aaba30c22..e7278d6b98c649d19846a4b395a27ec3c415b8f6 100644 (file)
@@ -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);
 
index 6137f53a6f2c62c72a3ea864f9d1162520141592..5c3c753928fff785ffb33a9b9bbad61163d613f4 100644 (file)
@@ -524,17 +524,6 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
   }
 
   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<PostFormProps, PostFormState> {
         );
       }
     }
+
+    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) {