Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add posting restricted to mods #642

Merged
merged 2 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 28 additions & 2 deletions src/shared/components/community/community-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
authField,
capitalizeFirstLetter,
randomStr,
toast,
wsClient,
wsJsonToRes,
wsSubscribe,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
};
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/shared/components/community/create-community.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Necessary to fix a double error notification.

}
}
}
20 changes: 13 additions & 7 deletions src/shared/components/community/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The canPost check.

);
}

handleModRemoveShow(i: Sidebar) {
i.state.showRemoveDialog = true;
i.setState(i.state);
Expand Down
3 changes: 2 additions & 1 deletion src/shared/components/post/post-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down