From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Tue, 4 Jul 2023 21:08:32 +0000 (-0400) Subject: fix toaster upon user settings change (#1802) X-Git-Url: http://these/git/ui/assets/static/%7Biframely.thumbnail_url%7D?a=commitdiff_plain;h=c3ab9e74f8775f4b811866d2675b00f9702bde3d;p=lemmy-ui.git fix toaster upon user settings change (#1802) Co-authored-by: SleeplessOne1917 --- diff --git a/src/shared/components/home/login.tsx b/src/shared/components/home/login.tsx index ffc372b..e2986b5 100644 --- a/src/shared/components/home/login.tsx +++ b/src/shared/components/home/login.tsx @@ -175,7 +175,9 @@ export class Login extends Component { } case "success": { - UserService.Instance.login(loginRes.data); + UserService.Instance.login({ + res: loginRes.data, + }); const site = await HttpService.client.getSite({ auth: myAuth(), }); diff --git a/src/shared/components/home/setup.tsx b/src/shared/components/home/setup.tsx index 943fd5f..f4bdb55 100644 --- a/src/shared/components/home/setup.tsx +++ b/src/shared/components/home/setup.tsx @@ -206,7 +206,7 @@ export class Setup extends Component { if (i.state.registerRes.state == "success") { const data = i.state.registerRes.data; - UserService.Instance.login(data); + UserService.Instance.login({ res: data }); i.setState({ doneRegisteringUser: true }); } } diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index 1e1f636..bb1e1f1 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -469,7 +469,9 @@ export class Signup extends Component { // Only log them in if a jwt was set if (data.jwt) { - UserService.Instance.login(data); + UserService.Instance.login({ + res: data, + }); const site = await HttpService.client.getSite({ auth: myAuth() }); diff --git a/src/shared/components/person/password-change.tsx b/src/shared/components/person/password-change.tsx index 68a22f6..565f55e 100644 --- a/src/shared/components/person/password-change.tsx +++ b/src/shared/components/person/password-change.tsx @@ -135,7 +135,9 @@ export class PasswordChange extends Component { if (i.state.passwordChangeRes.state === "success") { const data = i.state.passwordChangeRes.data; - UserService.Instance.login(data); + UserService.Instance.login({ + res: data, + }); const site = await HttpService.client.getSite({ auth: myAuth() }); if (site.state === "success") { diff --git a/src/shared/components/person/settings.tsx b/src/shared/components/person/settings.tsx index dfdf79c..4caef45 100644 --- a/src/shared/components/person/settings.tsx +++ b/src/shared/components/person/settings.tsx @@ -1175,8 +1175,12 @@ export class Settings extends Component { ...i.state.saveUserSettingsForm, auth: myAuthRequired(), }); + if (saveRes.state === "success") { - UserService.Instance.login(saveRes.data); + UserService.Instance.login({ + res: saveRes.data, + showToast: false, + }); toast(I18NextService.i18n.t("saved")); window.scrollTo(0, 0); } @@ -1198,7 +1202,10 @@ 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(I18NextService.i18n.t("password_changed")); } diff --git a/src/shared/services/UserService.ts b/src/shared/services/UserService.ts index 0724f40..70e8e9c 100644 --- a/src/shared/services/UserService.ts +++ b/src/shared/services/UserService.ts @@ -26,12 +26,18 @@ export class UserService { this.#setJwtInfo(); } - public login(res: LoginResponse) { + public login({ + res, + showToast = true, + }: { + res: LoginResponse; + showToast?: boolean; + }) { const expires = new Date(); expires.setDate(expires.getDate() + 365); if (isBrowser() && res.jwt) { - toast(I18NextService.i18n.t("logged_in")); + showToast && toast(I18NextService.i18n.t("logged_in")); setAuthCookie(res.jwt); this.#setJwtInfo(); }