]> Untitled Git - lemmy.git/blobdiff - ui/src/components/password_change.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / password_change.tsx
index 9445e8ed610a58ffa831d6ca31976898aad900c5..527f21e045e463362746789269c16b9deeed1a3b 100644 (file)
@@ -1,4 +1,5 @@
 import { Component, linkEvent } from 'inferno';
+import { Helmet } from 'inferno-helmet';
 import { Subscription } from 'rxjs';
 import { retryWhen, delay, take } from 'rxjs/operators';
 import {
@@ -6,7 +7,9 @@ import {
   LoginResponse,
   PasswordChangeForm,
   WebSocketJsonResponse,
-} from '../interfaces';
+  GetSiteResponse,
+  Site,
+} from 'lemmy-js-client';
 import { WebSocketService, UserService } from '../services';
 import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
 import { i18n } from '../i18next';
@@ -14,6 +17,7 @@ import { i18n } from '../i18next';
 interface State {
   passwordChangeForm: PasswordChangeForm;
   loading: boolean;
+  site: Site;
 }
 
 export class PasswordChange extends Component<any, State> {
@@ -26,6 +30,7 @@ export class PasswordChange extends Component<any, State> {
       password_verify: undefined,
     },
     loading: false,
+    site: undefined,
   };
 
   constructor(props: any, context: any) {
@@ -40,21 +45,25 @@ export class PasswordChange extends Component<any, State> {
         err => console.error(err),
         () => console.log('complete')
       );
+    WebSocketService.Instance.getSite();
   }
 
   componentWillUnmount() {
     this.subscription.unsubscribe();
   }
 
-  componentDidMount() {
-    document.title = `${i18n.t('password_change')} - ${
-      WebSocketService.Instance.site.name
-    }`;
+  get documentTitle(): string {
+    if (this.state.site) {
+      return `${i18n.t('password_change')} - ${this.state.site.name}`;
+    } else {
+      return 'Lemmy';
+    }
   }
 
   render() {
     return (
       <div class="container">
+        <Helmet title={this.documentTitle} />
         <div class="row">
           <div class="col-12 col-lg-6 offset-lg-3 mb-4">
             <h5>{i18n.t('password_change')}</h5>
@@ -138,14 +147,16 @@ export class PasswordChange extends Component<any, State> {
       this.state.loading = false;
       this.setState(this.state);
       return;
-    } else {
-      if (res.op == UserOperation.PasswordChange) {
-        let data = res.data as LoginResponse;
-        this.state = this.emptyState;
-        this.setState(this.state);
-        UserService.Instance.login(data);
-        this.props.history.push('/');
-      }
+    } else if (res.op == UserOperation.PasswordChange) {
+      let data = res.data as LoginResponse;
+      this.state = this.emptyState;
+      this.setState(this.state);
+      UserService.Instance.login(data);
+      this.props.history.push('/');
+    } else if (res.op == UserOperation.GetSite) {
+      let data = res.data as GetSiteResponse;
+      this.state.site = data.site;
+      this.setState(this.state);
     }
   }
 }