Login: make it visible that it's loading.

master
Tom Hacohen 4 years ago
parent 430d313be1
commit a540514f87

@ -22,16 +22,20 @@ import LoadingIndicator from "./widgets/LoadingIndicator";
export default function LoginGate() { export default function LoginGate() {
const credentials = useCredentials(); const credentials = useCredentials();
const dispatch = useDispatch(); const dispatch = useDispatch();
const [loading, setLoading] = React.useState(false);
const [fetchError, setFetchError] = React.useState<Error>(); const [fetchError, setFetchError] = React.useState<Error>();
async function onFormSubmit(username: string, password: string, serviceApiUrl?: string) { async function onFormSubmit(username: string, password: string, serviceApiUrl?: string) {
try { try {
setLoading(true);
setFetchError(undefined); setFetchError(undefined);
const ret = login(username, password, serviceApiUrl); const ret = login(username, password, serviceApiUrl);
await ret.payload; await ret.payload;
dispatch(ret); dispatch(ret);
} catch (e) { } catch (e) {
setFetchError(e); setFetchError(e);
} finally {
setLoading(false);
} }
} }
@ -56,6 +60,7 @@ export default function LoginGate() {
<h2>Please Log In</h2> <h2>Please Log In</h2>
<LoginForm <LoginForm
onSubmit={onFormSubmit} onSubmit={onFormSubmit}
loading={loading}
error={fetchError} error={fetchError}
/> />
<hr style={style.divider} /> <hr style={style.divider} />

@ -11,6 +11,7 @@ import Switch from "@material-ui/core/Switch";
import ExternalLink from "../widgets/ExternalLink"; import ExternalLink from "../widgets/ExternalLink";
import * as C from "../constants"; import * as C from "../constants";
import LoadingIndicator from "../widgets/LoadingIndicator";
interface FormErrors { interface FormErrors {
errorEmail?: string; errorEmail?: string;
@ -128,6 +129,15 @@ class LoginForm extends React.PureComponent {
); );
} }
if (this.props.loading) {
return (
<div style={{ textAlign: "center" }}>
<LoadingIndicator />
<p>Deriving encryption data...</p>
</div>
);
}
return ( return (
<React.Fragment> <React.Fragment>
{(this.props.error) && (<div>Error! {this.props.error.message}</div>)} {(this.props.error) && (<div>Error! {this.props.error.message}</div>)}

@ -6,6 +6,7 @@ import { createAction as origCreateAction, ActionMeta } from "redux-actions";
import * as Etebase from "etebase"; import * as Etebase from "etebase";
import { SettingsType } from "./"; import { SettingsType } from "./";
import { startTask } from "../helpers";
type FunctionAny = (...args: any[]) => any; type FunctionAny = (...args: any[]) => any;
@ -34,8 +35,10 @@ export const logout = createAction(
export const login = createAction( export const login = createAction(
"LOGIN", "LOGIN",
async (username: string, password: string, server: string | undefined) => { async (username: string, password: string, server: string | undefined) => {
const etebase = await Etebase.Account.login(username, password, server); return startTask((async () => {
return etebase.save(); const etebase = await Etebase.Account.login(username, password, server);
return etebase.save();
}));
} }
); );

Loading…
Cancel
Save