]> Untitled Git - lemmy-ui.git/commitdiff
Add posting restricted to mods (#642)
authorDessalines <dessalines@users.noreply.github.com>
Mon, 23 May 2022 19:22:15 +0000 (15:22 -0400)
committerGitHub <noreply@github.com>
Mon, 23 May 2022 19:22:15 +0000 (15:22 -0400)
* Adding only mods can post. Fixes #641

* Fixing canPost check

package.json
src/shared/components/community/community-form.tsx
src/shared/components/community/create-community.tsx
src/shared/components/community/sidebar.tsx
src/shared/components/post/post-form.tsx
yarn.lock

index d928bf9c5e37f08bada87674008f9a21ccb4dedd..6b0090c18cc4fdc6e695af2b07127c27cf5dbc3a 100644 (file)
@@ -74,7 +74,7 @@
     "eslint-plugin-prettier": "^4.0.0",
     "husky": "^7.0.4",
     "import-sort-style-module": "^6.0.0",
-    "lemmy-js-client": "0.17.0-rc.5",
+    "lemmy-js-client": "0.16.4-rc.2",
     "lint-staged": "^12.4.1",
     "mini-css-extract-plugin": "^2.6.0",
     "node-fetch": "^2.6.1",
index 9de05bf81d5700b54a680a22e65c2f68414959e3..0f12a252dccc12d1a23aca7616899ae38ee79e5e 100644 (file)
@@ -14,7 +14,6 @@ import {
   authField,
   capitalizeFirstLetter,
   randomStr,
-  toast,
   wsClient,
   wsJsonToRes,
   wsSubscribe,
@@ -51,6 +50,7 @@ export class CommunityForm extends Component<
       nsfw: false,
       icon: null,
       banner: null,
+      posting_restricted_to_mods: false,
       auth: authField(false),
     },
     loading: false,
@@ -79,6 +79,7 @@ export class CommunityForm extends Component<
         nsfw: cv.community.nsfw,
         icon: cv.community.icon,
         banner: cv.community.banner,
+        posting_restricted_to_mods: cv.community.posting_restricted_to_mods,
         auth: authField(),
       };
     }
@@ -227,6 +228,25 @@ export class CommunityForm extends Component<
               </div>
             </div>
           )}
+          <div class="form-group row">
+            <legend class="col-form-label col-6 pt-0">
+              {i18n.t("only_mods_can_post_in_community")}
+            </legend>
+            <div class="col-6">
+              <div class="form-check">
+                <input
+                  class="form-check-input position-static"
+                  id="community-only-mods-can-post"
+                  type="checkbox"
+                  checked={this.state.communityForm.posting_restricted_to_mods}
+                  onChange={linkEvent(
+                    this,
+                    this.handleCommunityPostingRestrictedToMods
+                  )}
+                />
+              </div>
+            </div>
+          </div>
           <div class="form-group row">
             <div class="col-12">
               <button
@@ -295,6 +315,11 @@ export class CommunityForm extends Component<
     i.setState(i.state);
   }
 
+  handleCommunityPostingRestrictedToMods(i: CommunityForm, event: any) {
+    i.state.communityForm.posting_restricted_to_mods = event.target.checked;
+    i.setState(i.state);
+  }
+
   handleCancel(i: CommunityForm) {
     i.props.onCancel();
   }
@@ -323,7 +348,8 @@ export class CommunityForm extends Component<
     let op = wsUserOp(msg);
     console.log(msg);
     if (msg.error) {
-      toast(i18n.t(msg.error), "danger");
+      // Errors handled by top level pages
+      // toast(i18n.t(msg.error), "danger");
       this.state.loading = false;
       this.setState(this.state);
       return;
index c43e727c7cbc7dd0b3b91100a6a4bb02760de5f6..f40bfd21e87ca993a0bc66f4e4e7e0b2d190d7a8 100644 (file)
@@ -76,8 +76,7 @@ export class CreateCommunity extends Component<any, CreateCommunityState> {
 
   parseMessage(msg: any) {
     if (msg.error) {
-      // Toast errors are already handled by community-form
-      return;
+      toast(i18n.t(msg.error), "danger");
     }
   }
 }
index b13cb8e03a113e7255be5ed6d68c472aedbff433..baa655fb8f8234fc030d90667db4003f0a0cdf94 100644 (file)
@@ -82,7 +82,7 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
             {this.communityTitle()}
             {this.adminButtons()}
             {this.subscribe()}
-            {this.createPost()}
+            {this.canPost && this.createPost()}
           </div>
         </div>
         <div class="card border-secondary mb-3">
@@ -250,16 +250,14 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
   }
 
   createPost() {
-    let community_view = this.props.community_view;
+    let cv = this.props.community_view;
     return (
-      community_view.subscribed && (
+      cv.subscribed && (
         <Link
           className={`btn btn-secondary btn-block mb-2 ${
-            community_view.community.deleted || community_view.community.removed
-              ? "no-click"
-              : ""
+            cv.community.deleted || cv.community.removed ? "no-click" : ""
           }`}
-          to={`/create_post?community_id=${community_view.community.id}`}
+          to={`/create_post?community_id=${cv.community.id}`}
         >
           {i18n.t("create_a_post")}
         </Link>
@@ -536,6 +534,14 @@ export class Sidebar extends Component<SidebarProps, SidebarState> {
     );
   }
 
+  get canPost(): boolean {
+    return (
+      !this.props.community_view.community.posting_restricted_to_mods ||
+      this.canMod ||
+      this.canAdmin
+    );
+  }
+
   handleModRemoveShow(i: Sidebar) {
     i.state.showRemoveDialog = true;
     i.setState(i.state);
index e9c221896d74acafbe1412bbae18971512e67c70..de0b7657a56fd94a22cf8b84a9792d2841bbf48b 100644 (file)
@@ -636,7 +636,8 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
     let op = wsUserOp(msg);
     console.log(msg);
     if (msg.error) {
-      toast(i18n.t(msg.error), "danger");
+      // Errors handled by top level pages
+      // toast(i18n.t(msg.error), "danger");
       this.state.loading = false;
       this.setState(this.state);
       return;
index 19ddfccea8c9ec3a0ee52d8d9e9201ca2d28d1ec..2e326f1ec854b24a41baf6b0c6e91e57df6f87ac 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -4813,10 +4813,10 @@ lcid@^1.0.0:
   dependencies:
     invert-kv "^1.0.0"
 
-lemmy-js-client@0.17.0-rc.5:
-  version "0.17.0-rc.5"
-  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.17.0-rc.5.tgz#8065ddca68acfbccc7a693ae0f31d6ab66dce972"
-  integrity sha512-IuSYaK4//KVFg+s4Av/PaxMM2tQpP3sL6G3zXfzbrZfCEtBp9ZlOEMFAu/neRgNumVh+R/koIwf8iLh4UdYCdg==
+lemmy-js-client@0.16.4-rc.2:
+  version "0.16.4-rc.2"
+  resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.16.4-rc.2.tgz#849b054ff37668c242db0202070bdb35f357f069"
+  integrity sha512-7ftHxpecqhHddfTJJC02eMB6N0jrtUBZVjt6CGC74J06kplBrsBQVETBqm33G1h1/SPHRHU1mqQ+f03PwsL+Ng==
 
 levn@^0.4.1:
   version "0.4.1"