X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fperson%2Fsettings.tsx;h=d024aae222b80081fa9941401443cfdc25353173;hb=b7ec7ae3110c560968e0cb24a32f1fe9166eec29;hp=b97064e6042262ad0446d32dc0c03fc4701f6554;hpb=91908d2872278769ae666b68a17a1b88a0d64321;p=lemmy-ui.git diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index b97064e..d024aae 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -1,3 +1,20 @@ +import { + communityToChoice, + fetchCommunities, + fetchThemeList, + fetchUsers, + myAuth, + myAuthRequired, + personToChoice, + setIsoData, + setTheme, + showLocal, + updateCommunityBlock, + updatePersonBlock, +} from "@utils/app"; +import { capitalizeFirstLetter, debounce } from "@utils/helpers"; +import { Choice } from "@utils/types"; +import classNames from "classnames"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; import { @@ -11,37 +28,19 @@ import { PersonBlockView, SortType, } from "lemmy-js-client"; -import { i18n, languages } from "../../i18next"; +import { elementUrl, emDash, relTags } from "../../config"; import { UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; -import { - Choice, - capitalizeFirstLetter, - communityToChoice, - debounce, - elementUrl, - emDash, - fetchCommunities, - fetchThemeList, - fetchUsers, - myAuth, - myAuthRequired, - personToChoice, - relTags, - setIsoData, - setTheme, - setupTippy, - showLocal, - toast, - updateCommunityBlock, - updatePersonBlock, -} from "../../utils"; +import { I18NextService, languages } from "../../services/I18NextService"; +import { setupTippy } from "../../tippy"; +import { toast } from "../../toast"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; import { ImageUploadForm } from "../common/image-upload-form"; import { LanguageSelect } from "../common/language-select"; import { ListingTypeSelect } from "../common/listing-type-select"; import { MarkdownTextArea } from "../common/markdown-textarea"; +import PasswordInput from "../common/password-input"; import { SearchableSelect } from "../common/searchable-select"; import { SortSelect } from "../common/sort-select"; import Tabs from "../common/tabs"; @@ -115,7 +114,7 @@ const Filter = ({ className="col-md-4 col-form-label" htmlFor={`block-${filterType}-filter`} > - {i18n.t(`block_${filterType}` as NoOptionI18nKeys)} + {I18NextService.i18n.t(`block_${filterType}` as NoOptionI18nKeys)}
{ } get documentTitle(): string { - return i18n.t("settings"); + return I18NextService.i18n.t("settings"); } render() { @@ -251,12 +250,12 @@ export class Settings extends Component { tabs={[ { key: "settings", - label: i18n.t("settings"), + label: I18NextService.i18n.t("settings"), getNode: this.userSettings, }, { key: "blocks", - label: i18n.t("blocks"), + label: I18NextService.i18n.t("blocks"), getNode: this.blockCards, }, ]} @@ -265,34 +264,50 @@ export class Settings extends Component { ); } - userSettings() { + userSettings(isSelected) { return ( -
-
-
-
{this.saveUserSettingsHtmlForm()}
+
+
+
+
+
{this.saveUserSettingsHtmlForm()}
+
-
-
-
-
{this.changePasswordHtmlForm()}
+
+
+
{this.changePasswordHtmlForm()}
+
); } - blockCards() { + blockCards(isSelected) { return ( -
-
-
-
{this.blockUserCard()}
+
+
+
+
+
{this.blockUserCard()}
+
-
-
-
-
{this.blockCommunityCard()}
+
+
+
{this.blockCommunityCard()}
+
@@ -302,61 +317,32 @@ export class Settings extends Component { changePasswordHtmlForm() { return ( <> -
{i18n.t("change_password")}
+

{I18NextService.i18n.t("change_password")}

-
- -
- -
+
+
-
- -
- -
+
+
-
- -
- -
+
+
@@ -395,7 +381,7 @@ export class Settings extends Component { blockedUsersList() { return ( <> -
{i18n.t("blocked_users")}
+

{I18NextService.i18n.t("blocked_users")}

    {this.state.personBlocks.map(pb => (
  • @@ -407,7 +393,7 @@ export class Settings extends Component { { ctx: this, recipientId: pb.target.id }, this.handleUnblockPerson )} - data-tippy-content={i18n.t("unblock_user")} + data-tippy-content={I18NextService.i18n.t("unblock_user")} > @@ -439,7 +425,7 @@ export class Settings extends Component { blockedCommunitiesList() { return ( <> -
    {i18n.t("blocked_communities")}
    +

    {I18NextService.i18n.t("blocked_communities")}

      {this.state.communityBlocks.map(cb => (
    • @@ -451,7 +437,9 @@ export class Settings extends Component { { ctx: this, communityId: cb.community.id }, this.handleUnblockCommunity )} - data-tippy-content={i18n.t("unblock_community")} + data-tippy-content={I18NextService.i18n.t( + "unblock_community" + )} > @@ -468,18 +456,18 @@ export class Settings extends Component { return ( <> -
      {i18n.t("settings")}
      +

      {I18NextService.i18n.t("settings")}

      {
      {
      {
      @@ -538,11 +526,11 @@ export class Settings extends Component {
      {
      {
      { className="form-select d-inline-block w-auto" > + + - {this.state.themeList.map(theme => (
      - +
      {
      { onChange={linkEvent(this, this.handleShowNsfwChange)} />
      @@ -674,7 +671,7 @@ export class Settings extends Component { onChange={linkEvent(this, this.handleShowScoresChange)} />
      @@ -688,7 +685,7 @@ export class Settings extends Component { onChange={linkEvent(this, this.handleShowAvatarsChange)} />
      @@ -702,7 +699,7 @@ export class Settings extends Component { onChange={linkEvent(this, this.handleBotAccount)} />
      @@ -719,7 +716,7 @@ export class Settings extends Component { className="form-check-label" htmlFor="user-show-bot-accounts" > - {i18n.t("show_bot_accounts")} + {I18NextService.i18n.t("show_bot_accounts")}
@@ -736,7 +733,7 @@ export class Settings extends Component { className="form-check-label" htmlFor="user-show-read-posts" > - {i18n.t("show_read_posts")} + {I18NextService.i18n.t("show_read_posts")}
@@ -753,7 +750,7 @@ export class Settings extends Component { className="form-check-label" htmlFor="user-show-new-post-notifs" > - {i18n.t("show_new_post_notifs")} + {I18NextService.i18n.t("show_new_post_notifs")}
@@ -776,7 +773,7 @@ export class Settings extends Component { className="form-check-label" htmlFor="user-send-notifications-to-email" > - {i18n.t("send_notifications_to_email")} + {I18NextService.i18n.t("send_notifications_to_email")}
@@ -786,60 +783,67 @@ export class Settings extends Component { {this.state.saveRes.state === "loading" ? ( ) : ( - capitalizeFirstLetter(i18n.t("save")) + capitalizeFirstLetter(I18NextService.i18n.t("save")) )}

-
+ {this.state.deleteAccountShowConfirm && ( <> -
- {i18n.t("delete_account_confirm")} -
- + {I18NextService.i18n.t("delete_account_confirm")} + + )} -
+ ); @@ -862,7 +866,7 @@ export class Settings extends Component { onChange={linkEvent(this, this.handleGenerateTotp)} />
@@ -872,7 +876,7 @@ export class Settings extends Component { <>
@@ -887,7 +891,7 @@ export class Settings extends Component { onChange={linkEvent(this, this.handleRemoveTotp)} />
@@ -1036,7 +1040,7 @@ export class Settings extends Component { // Coerce false to undefined here, so it won't generate it. const checked: boolean | undefined = event.target.checked || undefined; if (checked) { - toast(i18n.t("two_factor_setup_instructions")); + toast(I18NextService.i18n.t("two_factor_setup_instructions")); } i.setState(s => ((s.saveUserSettingsForm.generate_totp_2fa = checked), s)); } @@ -1064,7 +1068,9 @@ export class Settings extends Component { handleInterfaceLangChange(i: Settings, event: any) { const newLang = event.target.value ?? "browser"; - i18n.changeLanguage(newLang === "browser" ? navigator.languages : newLang); + I18NextService.i18n.changeLanguage( + newLang === "browser" ? navigator.languages : newLang + ); i.setState( s => ((s.saveUserSettingsForm.interface_language = event.target.value), s) @@ -1151,10 +1157,13 @@ export class Settings extends Component { ...i.state.saveUserSettingsForm, auth: myAuthRequired(), }); + if (saveRes.state === "success") { - UserService.Instance.login(saveRes.data); - location.reload(); - toast(i18n.t("saved")); + UserService.Instance.login({ + res: saveRes.data, + showToast: false, + }); + toast(I18NextService.i18n.t("saved")); window.scrollTo(0, 0); } @@ -1175,9 +1184,12 @@ export class Settings extends Component { auth: myAuthRequired(), }); if (changePasswordRes.state === "success") { - UserService.Instance.login(changePasswordRes.data); + UserService.Instance.login({ + res: changePasswordRes.data, + showToast: false, + }); window.scrollTo(0, 0); - toast(i18n.t("password_changed")); + toast(I18NextService.i18n.t("password_changed")); } i.setState({ changePasswordRes }); @@ -1192,7 +1204,8 @@ export class Settings extends Component { i.setState(s => ((s.deleteAccountForm.password = event.target.value), s)); } - async handleDeleteAccount(i: Settings) { + async handleDeleteAccount(i: Settings, event: Event) { + event.preventDefault(); const password = i.state.deleteAccountForm.password; if (password) { i.setState({ deleteAccountRes: { state: "loading" } });