import { Component, linkEvent } from 'inferno';
+import { Helmet } from 'inferno-helmet';
import { Subscription } from 'rxjs';
import { retryWhen, delay, take } from 'rxjs/operators';
import {
UserOperation,
LoginResponse,
PasswordChangeForm,
-} from '../interfaces';
+ WebSocketJsonResponse,
+ GetSiteResponse,
+ Site,
+} from 'lemmy-js-client';
import { WebSocketService, UserService } from '../services';
-import { wsJsonToRes, capitalizeFirstLetter } from '../utils';
+import { wsJsonToRes, capitalizeFirstLetter, toast } from '../utils';
import { i18n } from '../i18next';
-import { T } from 'inferno-i18next';
interface State {
passwordChangeForm: PasswordChangeForm;
loading: boolean;
+ site: Site;
}
export class PasswordChange extends Component<any, State> {
password_verify: undefined,
},
loading: false,
+ site: undefined,
};
constructor(props: any, context: any) {
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>
- <T i18nKey="password_change">#</T>
- </h5>
+ <h5>{i18n.t('password_change')}</h5>
{this.passwordChangeForm()}
</div>
</div>
<form onSubmit={linkEvent(this, this.handlePasswordChangeSubmit)}>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
- <T i18nKey="new_password">#</T>
+ {i18n.t('new_password')}
</label>
<div class="col-sm-10">
<input
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">
- <T i18nKey="verify_password">#</T>
+ {i18n.t('verify_password')}
</label>
<div class="col-sm-10">
<input
WebSocketService.Instance.passwordChange(i.state.passwordChangeForm);
}
- parseMessage(msg: any) {
+ parseMessage(msg: WebSocketJsonResponse) {
let res = wsJsonToRes(msg);
if (msg.error) {
- alert(i18n.t(msg.error));
+ toast(i18n.t(msg.error), 'danger');
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);
}
}
}