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
This commit is contained in:
biosfood 2023-09-06 14:43:19 +02:00 committed by GitHub
parent c49ca9e195
commit 8e2609a96d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 45 additions and 17 deletions

View file

@ -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",

View file

@ -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",

View file

@ -84,7 +84,7 @@ export class CommentForm extends Component<CommentFormProps, any> {
: 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<CommentFormProps, any> {
content,
post_id,
language_id,
form_id,
auth: myAuthRequired(),
});
} else {
@ -101,7 +100,6 @@ export class CommentForm extends Component<CommentFormProps, any> {
onUpsertComment({
content,
comment_id,
form_id,
language_id,
auth: myAuthRequired(),
});
@ -112,7 +110,6 @@ export class CommentForm extends Component<CommentFormProps, any> {
content,
parent_id,
post_id,
form_id,
language_id,
auth: myAuthRequired(),
});

View file

@ -107,6 +107,27 @@ export class ListingTypeSelect extends Component<
>
{I18NextService.i18n.t("all")}
</label>
{(UserService.Instance.myUserInfo?.moderates.length ?? 0) > 0 && (
<>
<input
id={`${this.id}-moderator-view`}
type="radio"
className="btn-check"
value={"ModeratorView"}
checked={this.state.type_ === "ModeratorView"}
onChange={linkEvent(this, this.handleTypeChange)}
/>
<label
htmlFor={`${this.id}-moderator-view`}
title={I18NextService.i18n.t("moderator_view_description")}
className={classNames("pointer btn btn-outline-secondary", {
active: this.state.type_ === "ModeratorView",
})}
>
{I18NextService.i18n.t("moderator_view")}
</label>
</>
)}
</div>
);
}

View file

@ -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);
}
}

View file

@ -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}
/>
</li>

View file

@ -1289,6 +1289,8 @@ export class Settings extends Component<any, SettingsState> {
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();

View file

@ -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;
}

View file

@ -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"