From ba5cafef08a293674d7e585ba7617e3fc74c9014 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sun, 25 Jun 2023 18:01:25 -0400 Subject: [PATCH 01/10] chore: Separate post mod buttons into functions --- src/shared/components/post/post-listing.tsx | 368 +++++++++++--------- 1 file changed, 204 insertions(+), 164 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 76a3e445..76690986 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -718,6 +718,94 @@ export class PostListing extends Component { {(this.canMod_ || this.canAdmin_) && (
  • {this.modRemoveButton}
  • )} + + {this.canMod_ && ( + <> + {!this.creatorIsMod_ && + (!post_view.creator_banned_from_community ? ( +
  • {this.modBanFromCommunityButton}
  • + ) : ( +
  • {this.modUnbanFromCommunityButton}
  • + ))} + {!post_view.creator_banned_from_community && ( +
  • {this.addModToCommunityButton}
  • + )} + + )} + + {/* Community creators and admins can transfer community to another mod */} + {(amCommunityCreator(post_view.creator.id, this.props.moderators) || + this.canAdmin_) && + this.creatorIsMod_ && + (!this.state.showConfirmTransferCommunity ? ( +
  • + +
  • + ) : ( + <> +
  • + +
  • +
  • + +
  • +
  • + +
  • + + ))} + {/* Admins can ban from all, and appoint other admins */} + {this.canAdmin_ && ( + <> + {!this.creatorIsAdmin_ && ( + <> + {!isBanned(post_view.creator) ? ( +
  • {modBanButton}
  • + ) : ( +
  • {modUnbanButton}
  • + )} +
  • {purgePersonButton}
  • +
  • {purgePostButton}
  • + + )} + {!isBanned(post_view.creator) && post_view.creator.local && ( +
  • {toggleAdminButton}
  • + )} + + )} @@ -982,6 +1070,121 @@ export class PostListing extends Component { ); } + get modBanFromCommunityButton() { + return ( + + ); + } + + get modUnbanFromCommunityButton() { + return ( + + ); + } + + get addModToCommunityButton() { + return ( + + ); + } + + get modBanButton() { + return ( + + ); + } + + get modUnbanButton() { + return ( + + ); + } + + get purgePersonButton() { + return ( + + ); + } + + get purgePostButton() { + return ( + + ); + } + + get toggleAdminButton() { + return ( + + ); + } + get modRemoveButton() { const removed = this.postView.post.removed; return ( @@ -1011,170 +1214,7 @@ export class PostListing extends Component { // TODO: make nicer const post_view = this.postView; return ( - this.state.showAdvanced && ( -
    - {this.canMod_ && ( - <> - {!this.creatorIsMod_ && - (!post_view.creator_banned_from_community ? ( - - ) : ( - - ))} - {!post_view.creator_banned_from_community && ( - - )} - - )} - {/* Community creators and admins can transfer community to another mod */} - {(amCommunityCreator(post_view.creator.id, this.props.moderators) || - this.canAdmin_) && - this.creatorIsMod_ && - (!this.state.showConfirmTransferCommunity ? ( - - ) : ( - <> - - - - - ))} - {/* Admins can ban from all, and appoint other admins */} - {this.canAdmin_ && ( - <> - {!this.creatorIsAdmin_ && ( - <> - {!isBanned(post_view.creator) ? ( - - ) : ( - - )} - - - - )} - {!isBanned(post_view.creator) && post_view.creator.local && ( - - )} - - )} -
    - ) + this.state.showAdvanced &&
    ); } From c1e86f43a1e1391915ac0fc8f5e2b9ab3cceafb2 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sun, 25 Jun 2023 18:08:26 -0400 Subject: [PATCH 02/10] fix: Move things back to where they were --- src/shared/components/post/post-listing.tsx | 180 ++++++++++---------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 76690986..9186c418 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -718,94 +718,6 @@ export class PostListing extends Component { {(this.canMod_ || this.canAdmin_) && (
  • {this.modRemoveButton}
  • )} - - {this.canMod_ && ( - <> - {!this.creatorIsMod_ && - (!post_view.creator_banned_from_community ? ( -
  • {this.modBanFromCommunityButton}
  • - ) : ( -
  • {this.modUnbanFromCommunityButton}
  • - ))} - {!post_view.creator_banned_from_community && ( -
  • {this.addModToCommunityButton}
  • - )} - - )} - - {/* Community creators and admins can transfer community to another mod */} - {(amCommunityCreator(post_view.creator.id, this.props.moderators) || - this.canAdmin_) && - this.creatorIsMod_ && - (!this.state.showConfirmTransferCommunity ? ( -
  • - -
  • - ) : ( - <> -
  • - -
  • -
  • - -
  • -
  • - -
  • - - ))} - {/* Admins can ban from all, and appoint other admins */} - {this.canAdmin_ && ( - <> - {!this.creatorIsAdmin_ && ( - <> - {!isBanned(post_view.creator) ? ( -
  • {modBanButton}
  • - ) : ( -
  • {modUnbanButton}
  • - )} -
  • {purgePersonButton}
  • -
  • {purgePostButton}
  • - - )} - {!isBanned(post_view.creator) && post_view.creator.local && ( -
  • {toggleAdminButton}
  • - )} - - )} @@ -1214,7 +1126,97 @@ export class PostListing extends Component { // TODO: make nicer const post_view = this.postView; return ( - this.state.showAdvanced &&
    + this.state.showAdvanced && ( +
    + {this.canMod_ && ( + <> + {!this.creatorIsMod_ && + (!post_view.creator_banned_from_community ? ( +
  • {this.modBanFromCommunityButton}
  • + ) : ( +
  • {this.modUnbanFromCommunityButton}
  • + ))} + {!post_view.creator_banned_from_community && ( +
  • {this.addModToCommunityButton}
  • + )} + + )} + + {/* Community creators and admins can transfer community to another mod */} + {(amCommunityCreator(post_view.creator.id, this.props.moderators) || + this.canAdmin_) && + this.creatorIsMod_ && + (!this.state.showConfirmTransferCommunity ? ( +
  • + +
  • + ) : ( + <> +
  • + +
  • +
  • + +
  • +
  • + +
  • + + ))} + {/* Admins can ban from all, and appoint other admins */} + {this.canAdmin_ && ( + <> + {!this.creatorIsAdmin_ && ( + <> + {!isBanned(post_view.creator) ? ( +
  • {this.modBanButton}
  • + ) : ( +
  • {this.modUnbanButton}
  • + )} +
  • {this.purgePersonButton}
  • +
  • {this.purgePostButton}
  • + + )} + {!isBanned(post_view.creator) && post_view.creator.local && ( +
  • {this.toggleAdminButton}
  • + )} + + )} +
    + ) ); } From 69966369d3c182ec8821f45e013239d4aa6bd740 Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sun, 25 Jun 2023 18:11:12 -0400 Subject: [PATCH 03/10] fix: Remove extraneous classes --- src/shared/components/post/post-listing.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 9186c418..6b65cde3 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -985,7 +985,7 @@ export class PostListing extends Component { get modBanFromCommunityButton() { return ( + ) : ( + <> + + - - ) : ( - <> -
  • - -
  • -
  • - -
  • -
  • - -
  • ))} {/* Admins can ban from all, and appoint other admins */} @@ -1201,18 +1193,16 @@ export class PostListing extends Component { <> {!this.creatorIsAdmin_ && ( <> - {!isBanned(post_view.creator) ? ( -
  • {this.modBanButton}
  • - ) : ( -
  • {this.modUnbanButton}
  • - )} -
  • {this.purgePersonButton}
  • -
  • {this.purgePostButton}
  • + {!isBanned(post_view.creator) + ? this.modBanButton + : this.modUnbanButton} + {this.purgePersonButton} + {this.purgePostButton} )} - {!isBanned(post_view.creator) && post_view.creator.local && ( -
  • {this.toggleAdminButton}
  • - )} + {!isBanned(post_view.creator) && + post_view.creator.local && + this.toggleAdminButton} )} From 7259472254e68cc9c30950bf5ed66f05d95652bc Mon Sep 17 00:00:00 2001 From: Jay Sitter Date: Sun, 25 Jun 2023 18:15:59 -0400 Subject: [PATCH 05/10] fix: Restore removed classes --- src/shared/components/post/post-listing.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 15fa0813..60fb12ff 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1131,14 +1131,11 @@ export class PostListing extends Component { {this.canMod_ && ( <> {!this.creatorIsMod_ && - (!post_view.creator_banned_from_community ? ( -
  • {this.modBanFromCommunityButton}
  • - ) : ( -
  • {this.modUnbanFromCommunityButton}
  • - ))} - {!post_view.creator_banned_from_community && ( -
  • {this.addModToCommunityButton}
  • - )} + (!post_view.creator_banned_from_community + ? this.modBanFromCommunityButton + : this.modUnbanFromCommunityButton)} + {!post_view.creator_banned_from_community && + this.addModToCommunityButton} )} @@ -1160,13 +1157,13 @@ export class PostListing extends Component { ) : ( <> + + + + ); + } + + handleEmailInputChange(i: LoginReset, event: any) { + i.setState(s => ((s.form.email = event.target.value.trim()), s)); + } + + async handlePasswordReset(i: LoginReset, event: any) { + event.preventDefault(); + + const email = i.state.form.email; + + if (email && validEmail(email)) { + i.setState(s => ((s.form.loading = true), s)); + + const res = await HttpService.client.passwordReset({ email }); + + if (res.state == "success") { + toast(I18NextService.i18n.t("reset_password_mail_sent")); + i.context.router.history.push("/login"); + } + + i.setState(s => ((s.form.loading = false), s)); + } + } +} diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index 4dd64665..397288e8 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -1,7 +1,7 @@ import { myAuth, setIsoData } from "@utils/app"; import { isBrowser } from "@utils/browser"; -import { validEmail } from "@utils/helpers"; import { Component, linkEvent } from "inferno"; +import { NavLink } from "inferno-router"; import { GetSiteResponse, LoginResponse } from "lemmy-js-client"; import { I18NextService, UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; @@ -105,18 +105,12 @@ export class Login extends Component { required maxLength={60} /> - + {this.state.showTotp && ( @@ -214,15 +208,4 @@ export class Login extends Component { i.state.form.password = event.target.value; i.setState(i.state); } - - async handlePasswordReset(i: Login, event: any) { - event.preventDefault(); - const email = i.state.form.username_or_email; - if (email) { - const res = await HttpService.client.passwordReset({ email }); - if (res.state == "success") { - toast(I18NextService.i18n.t("reset_password_mail_sent")); - } - } - } } diff --git a/src/shared/routes.ts b/src/shared/routes.ts index 6e3ed498..01325afa 100644 --- a/src/shared/routes.ts +++ b/src/shared/routes.ts @@ -7,6 +7,7 @@ import { Home } from "./components/home/home"; import { Instances } from "./components/home/instances"; import { Legal } from "./components/home/legal"; import { Login } from "./components/home/login"; +import { LoginReset } from "./components/home/login-reset"; import { Setup } from "./components/home/setup"; import { Signup } from "./components/home/signup"; import { Modlog } from "./components/modlog"; @@ -38,6 +39,10 @@ export const routes: IRoutePropsWithFetch>[] = [ path: `/login`, component: Login, }, + { + path: `/login_reset`, + component: LoginReset, + }, { path: `/signup`, component: Signup,