summaryrefslogtreecommitdiffstats
path: root/ui/src/components/login.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-01-18 23:54:10 -0500
committerDessalines <tyhou13@gmx.com>2020-01-18 23:54:10 -0500
commita044718066623f19d51196d444bd199c1231cebe (patch)
treecbffb18d826df1330ce2b7f1a814205ba45148d1 /ui/src/components/login.tsx
parent05ee5a8b600fdd7a64ad66bb52978befed3a7614 (diff)
First pass at fixing UI to work with new websocketresponses.
Diffstat (limited to 'ui/src/components/login.tsx')
-rw-r--r--ui/src/components/login.tsx37
1 files changed, 15 insertions, 22 deletions
diff --git a/ui/src/components/login.tsx b/ui/src/components/login.tsx
index 53b7a22f..42d5e05f 100644
--- a/ui/src/components/login.tsx
+++ b/ui/src/components/login.tsx
@@ -10,7 +10,7 @@ import {
GetSiteResponse,
} from '../interfaces';
import { WebSocketService, UserService } from '../services';
-import { msgOp, validEmail } from '../utils';
+import { wsJsonToRes, validEmail } from '../utils';
import { i18n } from '../i18next';
import { T } from 'inferno-i18next';
@@ -48,14 +48,7 @@ export class Login extends Component<any, State> {
this.state = this.emptyState;
this.subscription = WebSocketService.Instance.subject
- .pipe(
- retryWhen(errors =>
- errors.pipe(
- delay(3000),
- take(10)
- )
- )
- )
+ .pipe(retryWhen(errors => errors.pipe(delay(3000), take(10))))
.subscribe(
msg => this.parseMessage(msg),
err => console.error(err),
@@ -300,30 +293,30 @@ export class Login extends Component<any, State> {
}
parseMessage(msg: any) {
- let op: UserOperation = msgOp(msg);
- if (msg.error) {
- alert(i18n.t(msg.error));
+ let res = wsJsonToRes(msg);
+ if (res.error) {
+ alert(i18n.t(res.error));
this.state = this.emptyState;
this.setState(this.state);
return;
} else {
- if (op == UserOperation.Login) {
+ if (res.op == UserOperation.Login) {
+ let data = res.data as LoginResponse;
this.state = this.emptyState;
this.setState(this.state);
- let res: LoginResponse = msg;
- UserService.Instance.login(res);
+ UserService.Instance.login(data);
this.props.history.push('/');
- } else if (op == UserOperation.Register) {
+ } else if (res.op == UserOperation.Register) {
+ let data = res.data as LoginResponse;
this.state = this.emptyState;
this.setState(this.state);
- let res: LoginResponse = msg;
- UserService.Instance.login(res);
+ UserService.Instance.login(data);
this.props.history.push('/communities');
- } else if (op == UserOperation.PasswordReset) {
+ } else if (res.op == UserOperation.PasswordReset) {
alert(i18n.t('reset_password_mail_sent'));
- } else if (op == UserOperation.GetSite) {
- let res: GetSiteResponse = msg;
- this.state.enable_nsfw = res.site.enable_nsfw;
+ } else if (res.op == UserOperation.GetSite) {
+ let data = res.data as GetSiteResponse;
+ this.state.enable_nsfw = data.site.enable_nsfw;
this.setState(this.state);
document.title = `${i18n.t('login')} - ${
WebSocketService.Instance.site.name