]> Untitled Git - lemmy-ui.git/commitdiff
fix toaster upon user settings change (#1802)
authorAlec Armbruster <35377827+alectrocute@users.noreply.github.com>
Tue, 4 Jul 2023 21:08:32 +0000 (17:08 -0400)
committerGitHub <noreply@github.com>
Tue, 4 Jul 2023 21:08:32 +0000 (17:08 -0400)
Co-authored-by: SleeplessOne1917 <abias1122@gmail.com>
src/shared/components/home/login.tsx
src/shared/components/home/setup.tsx
src/shared/components/home/signup.tsx
src/shared/components/person/password-change.tsx
src/shared/components/person/settings.tsx
src/shared/services/UserService.ts

index ffc372b3a14f0a1d8681022847112372dbaf225a..e2986b57dc15cbc4c9e08fedbd9a1e1a7ccfe73e 100644 (file)
@@ -175,7 +175,9 @@ export class Login extends Component<any, State> {
         }
 
         case "success": {
-          UserService.Instance.login(loginRes.data);
+          UserService.Instance.login({
+            res: loginRes.data,
+          });
           const site = await HttpService.client.getSite({
             auth: myAuth(),
           });
index 943fd5f8e9d225052e308713cc6ef29bbea629f6..f4bdb5551d6deb48dc74af2224eea158e4f83579 100644 (file)
@@ -206,7 +206,7 @@ export class Setup extends Component<any, State> {
       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 });
       }
     }
index 1e1f636af39bb0d247167cd430037ff71443895f..bb1e1f1142be867fd69c742914f90aa2b70d5ab6 100644 (file)
@@ -469,7 +469,9 @@ export class Signup extends Component<any, State> {
 
           // 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() });
 
index 68a22f6293bc0718ad8d8fdf37f172213e770c8c..565f55e6ce2853d0be7c6e53bf294d2a163a0632 100644 (file)
@@ -135,7 +135,9 @@ export class PasswordChange extends Component<any, State> {
 
       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") {
index dfdf79c4bf03a574b6b02d4bb14040b129c597c6..4caef458bbe84600baa0906672b36867bb92ca09 100644 (file)
@@ -1175,8 +1175,12 @@ export class Settings extends Component<any, SettingsState> {
       ...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<any, SettingsState> {
         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"));
       }
index 0724f400f3128e267ee869d54c9f3b78cc4145db..70e8e9cadae7b79e8de43aa288ce14adf8031b58 100644 (file)
@@ -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();
     }