]> Untitled Git - lemmy-ui.git/commitdiff
Fix create post for federated communities. Fixes #76
authorDessalines <tyhou13@gmx.com>
Tue, 17 Nov 2020 01:34:41 +0000 (19:34 -0600)
committerDessalines <tyhou13@gmx.com>
Tue, 17 Nov 2020 01:34:41 +0000 (19:34 -0600)
package.json
src/shared/components/community-link.tsx
src/shared/components/create-post.tsx
src/shared/components/post-form.tsx
src/shared/components/sidebar.tsx
src/shared/components/user-listing.tsx
yarn.lock

index c748b5a9f287d9e4cb9ca65ee817d4631a6811db..89614fa33095b9b0b3f5772a69fbf2bcba53797a 100644 (file)
@@ -15,7 +15,7 @@
   },
   "repository": "https://github.com/LemmyNet/lemmy-ui",
   "dependencies": {
-    "@typescript-eslint/parser": "^4.7.0",
+    "@typescript-eslint/parser": "^4.8.0",
     "autosize": "^4.0.2",
     "choices.js": "^9.0.1",
     "emoji-short-name": "^1.0.0",
@@ -29,7 +29,7 @@
     "inferno-router": "^7.4.6",
     "inferno-server": "^7.4.6",
     "isomorphic-cookie": "^1.2.4",
-    "jwt-decode": "^3.1.1",
+    "jwt-decode": "^3.1.2",
     "markdown-it": "^12.0.2",
     "markdown-it-container": "^3.0.0",
     "markdown-it-emoji": "^2.0.0",
     "bootstrap": "^4.5.3",
     "bootswatch": "^4.5.3",
     "clean-webpack-plugin": "^3.0.0",
-    "copy-webpack-plugin": "^6.3.0",
+    "copy-webpack-plugin": "^6.3.1",
     "css-loader": "^5.0.1",
     "eslint": "^7.13.0",
     "eslint-plugin-jane": "^9.0.4",
     "husky": "^4.3.0",
-    "lemmy-js-client": "^1.0.15",
+    "lemmy-js-client": "^1.0.16",
     "lint-staged": "^10.5.1",
     "mini-css-extract-plugin": "^1.3.1",
     "node-fetch": "^2.6.1",
@@ -76,9 +76,9 @@
     "rimraf": "^3.0.2",
     "run-node-webpack-plugin": "^1.3.0",
     "sass-loader": "^10.1.0",
-    "sortpack": "^2.1.9",
+    "sortpack": "^2.1.10",
     "style-loader": "^2.0.0",
-    "terser": "^5.3.8",
+    "terser": "^5.4.0",
     "typescript": "^4.0.5",
     "webpack": "5.4.0",
     "webpack-cli": "^4.2.0",
index 0fc92177e40dc351000b7533922d9d65e9e2d2d3..8bf73ca38e0d62211a4a3c02a1053b4ac6ab3eab 100644 (file)
@@ -46,7 +46,7 @@ export class CommunityLink extends Component<CommunityLinkProps, any> {
         title={apubName}
         className={`${this.props.muted ? 'text-muted' : ''}`}
         to={link}
-        target={!local ? '_blank' : ''}
+        target={this.props.realLink ? '_blank' : ''}
       >
         {!this.props.hideAvatar && community.icon && showAvatars() && (
           <PictrsImage src={community.icon} icon />
index d692b8a2133df4127c5ee15e0074c148189ae1d3..a0eeb35c0907476b67f226ea9455981d80af9f37 100644 (file)
@@ -114,7 +114,10 @@ export class CreatePost extends Component<any, CreatePostState> {
     let urlParams = new URLSearchParams(this.props.location.search);
     let params: PostFormParams = {
       name: urlParams.get('title'),
-      community: urlParams.get('community') || this.prevCommunityName,
+      community_name: urlParams.get('community_name') || this.prevCommunityName,
+      community_id: urlParams.get('community_id')
+        ? Number(urlParams.get('community_id')) || this.prevCommunityId
+        : null,
       body: urlParams.get('body'),
       url: urlParams.get('url'),
     };
@@ -134,6 +137,18 @@ export class CreatePost extends Component<any, CreatePostState> {
     return null;
   }
 
+  get prevCommunityId(): number {
+    if (this.props.match.params.id) {
+      return this.props.match.params.id;
+    } else if (this.props.location.state) {
+      let lastLocation = this.props.location.state.prevPath;
+      if (lastLocation.includes('/community/')) {
+        return Number(lastLocation.split('/community/')[1]);
+      }
+    }
+    return null;
+  }
+
   handlePostCreate(id: number) {
     this.props.history.push(`/post/${id}`);
   }
index 3c7df35823e6fa5c834e96f835fc2af7e05ff7e3..5e683f1e46d4c156330347d81312d79ea3f94e65 100644 (file)
@@ -572,11 +572,19 @@ 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;
+    } else if (
+      this.props.params &&
+      (this.props.params.community_id || this.props.params.community_name)
+    ) {
+      if (this.props.params.community_name) {
+        let foundCommunityId = this.props.communities.find(
+          r => r.name == this.props.params.community_name
+        ).id;
+        this.state.postForm.community_id = foundCommunityId;
+      } else if (this.props.params.community_id) {
+        this.state.postForm.community_id = this.props.params.community_id;
+      }
+
       if (isBrowser()) {
         this.choices.setChoiceByValue(
           this.state.postForm.community_id.toString()
index c61db3568668bbae67016d78e4e04d1bd8741653..82b05af38dc82342f5e4d5ffefa9689d227bae63 100644 (file)
@@ -209,7 +209,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
           className={`btn btn-secondary btn-block mb-2 ${
             community.deleted || community.removed ? 'no-click' : ''
           }`}
-          to={`/create_post?community=${community.name}`}
+          to={`/create_post?community_id=${community.id}`}
         >
           {i18n.t('create_a_post')}
         </Link>
index 18deb5641518d91c147fb52a3a7bde0afa089dc6..43fa16e27db52a5159c0445ea03bbeb84d09e74f 100644 (file)
@@ -53,7 +53,7 @@ export class UserListing extends Component<UserListingProps, any> {
           title={apubName}
           className={this.props.muted ? 'text-muted' : 'text-info'}
           to={link}
-          target={!local ? '_blank' : ''}
+          target={this.props.realLink ? '_blank' : ''}
         >
           {!this.props.hideAvatar && user.avatar && showAvatars() && (
             <PictrsImage src={user.avatar} icon />
index fd15c78269d1d5e72c2834552a53e9f17808ca56..fc4e0ccb10037f7cf9b8753d88e0c070db5d85ee 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
     "@typescript-eslint/typescript-estree" "4.5.0"
     debug "^4.1.1"
 
-"@typescript-eslint/parser@^4.7.0":
-  version "4.7.0"
-  resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.7.0.tgz#44bdab0f788b478178368baa65d3365fdc63da1c"
-  integrity sha512-+meGV8bMP1sJHBI2AFq1GeTwofcGiur8LoIr6v+rEmD9knyCqDlrQcFHR0KDDfldHIFDU/enZ53fla6ReF4wRw==
-  dependencies:
-    "@typescript-eslint/scope-manager" "4.7.0"
-    "@typescript-eslint/types" "4.7.0"
-    "@typescript-eslint/typescript-estree" "4.7.0"
+"@typescript-eslint/parser@^4.8.0":
+  version "4.8.0"
+  resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.8.0.tgz#ff98c0435a3797d17083a63389078b8aa49dc81e"
+  integrity sha512-15sp9BIoZalx4wRgkebfau8KizVe6w0eTjPMnuST9kbIeOaloDy1xKkg7eJfFvE/MdCtKlEWZFLoJB8C0SEOaw==
+  dependencies:
+    "@typescript-eslint/scope-manager" "4.8.0"
+    "@typescript-eslint/types" "4.8.0"
+    "@typescript-eslint/typescript-estree" "4.8.0"
     debug "^4.1.1"
 
 "@typescript-eslint/scope-manager@4.1.0":
     "@typescript-eslint/types" "4.5.0"
     "@typescript-eslint/visitor-keys" "4.5.0"
 
-"@typescript-eslint/scope-manager@4.7.0":
-  version "4.7.0"
-  resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.7.0.tgz#2115526085fb72723ccdc1eeae75dec7126220ed"
-  integrity sha512-ILITvqwDJYbcDCROj6+Ob0oCKNg3SH46iWcNcTIT9B5aiVssoTYkhKjxOMNzR1F7WSJkik4zmuqve5MdnA0DyA==
+"@typescript-eslint/scope-manager@4.8.0":
+  version "4.8.0"
+  resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-4.8.0.tgz#f960b6c5df1a5b230b8488e71c5c04e58dd494e0"
+  integrity sha512-eJ+SV6w5WcyFusQ/Ru4A/c7E65HMGzWWGPJAqSuM/1EKEE6wOw9LUQTqAvLa6v2oIcaDo9F+/EyOPZgoD/BcLA==
   dependencies:
-    "@typescript-eslint/types" "4.7.0"
-    "@typescript-eslint/visitor-keys" "4.7.0"
+    "@typescript-eslint/types" "4.8.0"
+    "@typescript-eslint/visitor-keys" "4.8.0"
 
 "@typescript-eslint/types@4.1.0":
   version "4.1.0"
   resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.5.0.tgz#98256e07bad1c8d15d0c9627ebec82fd971bb3c3"
   integrity sha512-n2uQoXnyWNk0Les9MtF0gCK3JiWd987JQi97dMSxBOzVoLZXCNtxFckVqt1h8xuI1ix01t+iMY4h4rFMj/303g==
 
-"@typescript-eslint/types@4.7.0":
-  version "4.7.0"
-  resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.7.0.tgz#5e95ef5c740f43d942542b35811f87b62fccca69"
-  integrity sha512-uLszFe0wExJc+I7q0Z/+BnP7wao/kzX0hB5vJn4LIgrfrMLgnB2UXoReV19lkJQS1a1mHWGGODSxnBx6JQC3Sg==
+"@typescript-eslint/types@4.8.0":
+  version "4.8.0"
+  resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.8.0.tgz#87e73883637f662d9a638b0e9b01ed77edc44fb7"
+  integrity sha512-2/mGmXxr3sTxCvCT1mhR2b9rbfpMEBK41tiu0lMnMtZEbpphcUyrmgt2ogDFWNvsvyyeUxO1159eDrgFb7zV4Q==
 
 "@typescript-eslint/typescript-estree@4.1.0":
   version "4.1.0"
     semver "^7.3.2"
     tsutils "^3.17.1"
 
-"@typescript-eslint/typescript-estree@4.7.0":
-  version "4.7.0"
-  resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.7.0.tgz#539531167f05ba20eb0b6785567076679e29d393"
-  integrity sha512-5XZRQznD1MfUmxu1t8/j2Af4OxbA7EFU2rbo0No7meb46eHgGkSieFdfV6omiC/DGIBhH9H9gXn7okBbVOm8jw==
+"@typescript-eslint/typescript-estree@4.8.0":
+  version "4.8.0"
+  resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.8.0.tgz#b5160588495f18b739003b6078309b76fece0c55"
+  integrity sha512-jEdeERN8DIs7S8PlTdI7Sdy63Caxg2VtR21/RV7Z1Dtixiq/QEFSPrDXggMXKNOPPlrtMS+eCz7d7NV0HWLFVg==
   dependencies:
-    "@typescript-eslint/types" "4.7.0"
-    "@typescript-eslint/visitor-keys" "4.7.0"
+    "@typescript-eslint/types" "4.8.0"
+    "@typescript-eslint/visitor-keys" "4.8.0"
     debug "^4.1.1"
     globby "^11.0.1"
     is-glob "^4.0.1"
     "@typescript-eslint/types" "4.5.0"
     eslint-visitor-keys "^2.0.0"
 
-"@typescript-eslint/visitor-keys@4.7.0":
-  version "4.7.0"
-  resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.7.0.tgz#6783824f22acfc49e754970ed21b88ac03b80e6f"
-  integrity sha512-aDJDWuCRsf1lXOtignlfiPODkzSxxop7D0rZ91L6ZuMlcMCSh0YyK+gAfo5zN/ih6WxMwhoXgJWC3cWQdaKC+A==
+"@typescript-eslint/visitor-keys@4.8.0":
+  version "4.8.0"
+  resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.8.0.tgz#7786b92bbaf25c6aa9fb860eb8dbb1f7d3b7d0ad"
+  integrity sha512-JluNZLvnkRUr0h3L6MnQVLuy2rw9DpD0OyMC21FVbgcezr0LQkbBjDp9kyKZhuZrLrtq4mwPiIkpfRb8IRqneA==
   dependencies:
-    "@typescript-eslint/types" "4.7.0"
+    "@typescript-eslint/types" "4.8.0"
     eslint-visitor-keys "^2.0.0"
 
 "@webassemblyjs/ast@1.9.0":
@@ -2778,10 +2778,10 @@ copy-descriptor@^0.1.0:
   resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
   integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=
 
-copy-webpack-plugin@^6.3.0:
-  version "6.3.0"
-  resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-6.3.0.tgz#91820b63bbde7d73609accb86dab7e7386863f6f"
-  integrity sha512-kQ2cGGQLO6Ov2fe7rEGVxObI17dPeFkv8bRGnUAGZehOcrrObyAR9yWYlFGlJsyWM4EeuC/ytQNQkXxjYotMzg==
+copy-webpack-plugin@^6.3.1:
+  version "6.3.1"
+  resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-6.3.1.tgz#ceb6e9c3e4910e63a774fd4a27451156775f6e2a"
+  integrity sha512-SyIMdP6H3v+zPU+VIhKRsK0ZEF82KZ93JBlKOoIW8SkkuI84FSrHxG+aMTE1u4csbi9PLRqqWTIK+bfJ2xsFuQ==
   dependencies:
     cacache "^15.0.5"
     fast-glob "^3.2.4"
@@ -5387,10 +5387,10 @@ jsx-ast-utils@^2.4.1:
     array-includes "^3.1.1"
     object.assign "^4.1.1"
 
-jwt-decode@^3.1.1:
-  version "3.1.1"
-  resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.1.tgz#526710779567c380910139f790da2910c529e49f"
-  integrity sha512-EaH9dTD9ogCmxZRdiTsIUIJslqjoFfk8nEAi+Bq8u/aUjrVuhZ6eZjhWRH6SC9NBA0Lwr3K35H2zDnWvK/n4vQ==
+jwt-decode@^3.1.2:
+  version "3.1.2"
+  resolved "https://registry.yarnpkg.com/jwt-decode/-/jwt-decode-3.1.2.tgz#3fb319f3675a2df0c2895c8f5e9fa4b67b04ed59"
+  integrity sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==
 
 killable@^1.0.1:
   version "1.0.1"
@@ -5457,10 +5457,10 @@ lcid@^1.0.0:
   dependencies:
     invert-kv "^1.0.0"
 
-lemmy-js-client@^1.0.15:
-  version "1.0.15"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.15.tgz#7f47c8fd93c50d77a770d8828ca9aac7a227606e"
-  integrity sha512-2NkdwtdjuvyYsBiro5sdOirN3IuoQW1X7hH5az5fu59nKHLDpHm8BoktMmtf0u2cmOy+C5zg4ksK2UlG60Pe0g==
+lemmy-js-client@^1.0.16:
+  version "1.0.16"
+  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-1.0.16.tgz#84bf094c246d987f2f192bfac75340430821fee9"
+  integrity sha512-WvEEGrYNA2dzfzlufWB9LhUcll0O06WaUjSfBn5lYY/SFFsvBW5ImD42P/QwvN8Sgj6xVQiboe+Z8T++iAjKVw==
 
 leven@^3.1.0:
   version "3.1.0"
@@ -8431,10 +8431,10 @@ sorted-union-stream@~2.1.3:
     from2 "^1.3.0"
     stream-iterate "^1.1.0"
 
-sortpack@^2.1.9:
-  version "2.1.9"
-  resolved "https://registry.yarnpkg.com/sortpack/-/sortpack-2.1.9.tgz#cd3fc1139f3f51a5b61e46b81977b71438ecfad6"
-  integrity sha512-LLmHfEzIY+B2vucdnnjgXk97U2aU1C5gXrFYocfe+JM/uIBbk2KID3EEi3sRGxmKzx2ckUGOuJ5sCgWqTpIPkA==
+sortpack@^2.1.10:
+  version "2.1.10"
+  resolved "https://registry.yarnpkg.com/sortpack/-/sortpack-2.1.10.tgz#eb23257ff2db47954b0a7c3e4c84f71f1e32fac1"
+  integrity sha512-gJcTUZoIZoFDxyVhy+aJeUoknzs27K+EAuO+gTkWqxLZuiQYlgL1yu7u0B9cqMqavZcFMXcpmPBgovsDJXe3Fw==
 
 source-list-map@^2.0.0, source-list-map@^2.0.1:
   version "2.0.1"
@@ -8924,6 +8924,15 @@ terser@^5.3.8:
     source-map "~0.7.2"
     source-map-support "~0.5.19"
 
+terser@^5.4.0:
+  version "5.4.0"
+  resolved "https://registry.yarnpkg.com/terser/-/terser-5.4.0.tgz#9815c0839072d5c894e22c6fc508fbe9f5e7d7e8"
+  integrity sha512-3dZunFLbCJis9TAF2VnX+VrQLctRUmt1p3W2kCsJuZE4ZgWqh//+1MZ62EanewrqKoUf4zIaDGZAvml4UDc0OQ==
+  dependencies:
+    commander "^2.20.0"
+    source-map "~0.7.2"
+    source-map-support "~0.5.19"
+
 text-table@^0.2.0, text-table@~0.2.0:
   version "0.2.0"
   resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"