Skip to content

Commit b6e22d3

Browse files
committed
Added preloaders
1 parent 15fb9cf commit b6e22d3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

components/Login.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { MdEmail } from "react-icons/md";
22
import { RiLockPasswordFill } from "react-icons/ri";
3-
import { AiTwotoneHome } from 'react-icons/ai';
43
import React, { useState, useEffect } from "react";
54
import { useRouter } from "next/router";
65
import { useUser } from "../lib/hooks";
@@ -10,13 +9,14 @@ export default function Login() {
109
const router = useRouter();
1110
const [errorMsg, setErrorMsg] = useState("");
1211
const [user, { mutate }] = useUser();
12+
const [loading,isLoading]=useState(user?true:false);
1313
useEffect(() => {
1414
// redirect to home if user is authenticated
1515
if (user) router.replace("/");
1616
}, [user]);
1717

1818
async function onSubmit(e) {
19-
19+
isLoading(true);
2020
e.preventDefault();
2121
const body = {
2222
email: e.currentTarget.email.value,
@@ -32,12 +32,16 @@ export default function Login() {
3232
mutate(userObj);
3333
M.toast({ html: 'Logged in', classes: 'blue' })
3434
} else {
35+
isLoading(false);
3536
setErrorMsg("Incorrect username or password. Try again!");
3637
}
3738
}
3839

3940
return (
4041
<>
42+
{loading?<div class="progress">
43+
<div class="indeterminate"></div>
44+
</div>:null}
4145
<div className="row">
4246
<div className="col s12 m12">
4347
<div className="card z-depth-0">

0 commit comments

Comments
 (0)