From 8e2609a96d7d939f6f55ccb794513e10252fabb7 Mon Sep 17 00:00:00 2001 From: biosfood Date: Wed, 6 Sep 2023 14:43:19 +0200 Subject: [PATCH] Add moderator view button (#1993) * update lemmy-js-client version * add moderator view to moderator view select * fix some linting problems introduced in recent lemmy-js-client changes * remove form id from mardown-textarea submit * add default delete_content as false * manually check if a user is an admin * update lemmy-js-client to 0.19.0-rc.7 --- package.json | 15 +++++++++---- src/server/utils/generate-manifest-json.ts | 3 ++- .../components/comment/comment-form.tsx | 5 +---- .../components/common/listing-type-select.tsx | 21 +++++++++++++++++++ .../components/common/markdown-textarea.tsx | 4 ++-- src/shared/components/person/profile.tsx | 2 +- src/shared/components/person/settings.tsx | 2 ++ src/shared/utils/roles/am-admin.ts | 2 +- yarn.lock | 8 +++---- 9 files changed, 45 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index addee2a7..92e0c1b0 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,16 @@ "translations:update": "git submodule update --remote --recursive" }, "lint-staged": { - "*.{ts,tsx,js}": ["prettier --write", "eslint --fix"], - "*.{css, scss}": ["prettier --write"], - "package.json": ["sortpack"] + "*.{ts,tsx,js}": [ + "prettier --write", + "eslint --fix" + ], + "*.{css, scss}": [ + "prettier --write" + ], + "package.json": [ + "sortpack" + ] }, "dependencies": { "@babel/plugin-proposal-decorators": "^7.21.5", @@ -61,7 +68,7 @@ "inferno-router": "^8.2.2", "inferno-server": "^8.2.2", "jwt-decode": "^3.1.2", - "lemmy-js-client": "0.19.0-rc.1", + "lemmy-js-client": "^0.19.0-rc.7", "lodash.isequal": "^4.5.0", "markdown-it": "^13.0.1", "markdown-it-container": "^3.0.0", diff --git a/src/server/utils/generate-manifest-json.ts b/src/server/utils/generate-manifest-json.ts index 3821b02b..dd56bc3c 100644 --- a/src/server/utils/generate-manifest-json.ts +++ b/src/server/utils/generate-manifest-json.ts @@ -73,7 +73,8 @@ export default async function ({ description: "Create a post.", }, ].concat( - my_user?.local_user_view.person.admin || !community_creation_admin_only + my_user?.local_user_view.local_user.admin || + !community_creation_admin_only ? [ { name: "Create Community", diff --git a/src/shared/components/comment/comment-form.tsx b/src/shared/components/comment/comment-form.tsx index 8eb10614..32c687c2 100644 --- a/src/shared/components/comment/comment-form.tsx +++ b/src/shared/components/comment/comment-form.tsx @@ -84,7 +84,7 @@ export class CommentForm extends Component { : capitalizeFirstLetter(I18NextService.i18n.t("reply")); } - handleCommentSubmit(content: string, form_id: string, language_id?: number) { + handleCommentSubmit(content: string, language_id?: number) { const { node, onUpsertComment, edit } = this.props; if (typeof node === "number") { const post_id = node; @@ -92,7 +92,6 @@ export class CommentForm extends Component { content, post_id, language_id, - form_id, auth: myAuthRequired(), }); } else { @@ -101,7 +100,6 @@ export class CommentForm extends Component { onUpsertComment({ content, comment_id, - form_id, language_id, auth: myAuthRequired(), }); @@ -112,7 +110,6 @@ export class CommentForm extends Component { content, parent_id, post_id, - form_id, language_id, auth: myAuthRequired(), }); diff --git a/src/shared/components/common/listing-type-select.tsx b/src/shared/components/common/listing-type-select.tsx index fc498184..3439fac4 100644 --- a/src/shared/components/common/listing-type-select.tsx +++ b/src/shared/components/common/listing-type-select.tsx @@ -107,6 +107,27 @@ export class ListingTypeSelect extends Component< > {I18NextService.i18n.t("all")} + {(UserService.Instance.myUserInfo?.moderates.length ?? 0) > 0 && ( + <> + + + + )} ); } diff --git a/src/shared/components/common/markdown-textarea.tsx b/src/shared/components/common/markdown-textarea.tsx index d0b67080..d122b472 100644 --- a/src/shared/components/common/markdown-textarea.tsx +++ b/src/shared/components/common/markdown-textarea.tsx @@ -48,7 +48,7 @@ interface MarkdownTextAreaProps { hideNavigationWarnings?: boolean; onContentChange?(val: string): void; onReplyCancel?(): void; - onSubmit?(content: string, formId: string, languageId?: number): void; + onSubmit?(content: string, languageId?: number): void; allLanguages: Language[]; // TODO should probably be nullable siteLanguages: number[]; // TODO same } @@ -534,7 +534,7 @@ export class MarkdownTextArea extends Component< event.preventDefault(); if (i.state.content) { i.setState({ loading: true, submitted: true }); - i.props.onSubmit?.(i.state.content, i.formId, i.state.languageId); + i.props.onSubmit?.(i.state.content, i.state.languageId); } } diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index 08ec7ad0..c8119b8c 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -499,7 +499,7 @@ export class Profile extends Component< classNames="ms-1" isBanned={isBanned(pv.person)} isDeleted={pv.person.deleted} - isAdmin={pv.person.admin} + isAdmin={isAdmin(pv.person.id, admins)} isBot={pv.person.bot_account} /> diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index 7576a22a..5e387972 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -1289,6 +1289,8 @@ export class Settings extends Component { const deleteAccountRes = await HttpService.client.deleteAccount({ password, auth: myAuthRequired(), + // TODO: promt user weather he wants the content to be deleted + delete_content: false, }); if (deleteAccountRes.state === "success") { UserService.Instance.logout(); diff --git a/src/shared/utils/roles/am-admin.ts b/src/shared/utils/roles/am-admin.ts index f9bd25f1..d864599c 100644 --- a/src/shared/utils/roles/am-admin.ts +++ b/src/shared/utils/roles/am-admin.ts @@ -3,5 +3,5 @@ import { UserService } from "../../services"; export default function amAdmin( myUserInfo = UserService.Instance.myUserInfo, ): boolean { - return myUserInfo?.local_user_view.person.admin ?? false; + return myUserInfo?.local_user_view.local_user.admin ?? false; } diff --git a/yarn.lock b/yarn.lock index 36838a90..7179bb2c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6035,10 +6035,10 @@ leac@^0.6.0: resolved "https://registry.yarnpkg.com/leac/-/leac-0.6.0.tgz#dcf136e382e666bd2475f44a1096061b70dc0912" integrity sha512-y+SqErxb8h7nE/fiEX07jsbuhrpO9lL8eca7/Y1nuWV2moNlXhyd59iDGcRf6moVyDMbmTNzL40SUyrFU/yDpg== -lemmy-js-client@0.19.0-rc.1: - version "0.19.0-rc.1" - resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.1.tgz#e6bf9abdd82ea7bb7035a120925498f6dd8851c9" - integrity sha512-d0rDCvGV8lh8JkRjeEZdWjuE2OAvrDSei+4LUUSrcJVVMqG9PdjPRstKJ3JG4kT1aH3Nsp5AQynMyh9iQrfgTg== +lemmy-js-client@^0.19.0-rc.7: + version "0.19.0-rc.7" + resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.19.0-rc.7.tgz#822dd85c44c2df03eafb71c6e046dbeeb6ed854d" + integrity sha512-dqnyepju5sCRu+zwwm8GeQtXJpRnz/mARo//fZBPz1EgNA70crWheamBoJ9GSm19znsZzu0853t8GxVhNT9iIw== dependencies: cross-fetch "^3.1.5" form-data "^4.0.0"