Skip to content

Commit 48b4047

Browse files
committed
Added preloaders
1 parent 112815b commit 48b4047

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

components/Home.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import Link from 'next/link';
22
import { useUser } from '../lib/hooks';
33
import AfterLogin from '../components/AfterLogin';
4+
import {useState} from 'react'
45

56
export default function Home() {
67
const [user, { mutate }] = useUser();
8+
const [loading, isLoading] = useState(false);
79
const handleLogout = async () => {
10+
isLoading(true);
811
await fetch('/api/auth', {
912
method: 'DELETE',
1013
});
1114
// set the user state to null
1215
mutate(null);
1316
M.toast({ html: 'Logged out' })
17+
isLoading(false);
1418
};
1519
return (
1620
<>
@@ -31,6 +35,9 @@ export default function Home() {
3135

3236
</div>
3337
<div className="card-stacked center-align">
38+
{loading ? <div class="progress white" style={{margin:0}}>
39+
<div class="indeterminate blue"></div>
40+
</div> : null}
3441
<div className="card-content">
3542
<h2 style={{ marginTop: '0' }}><span style={{ fontWeight: 'bolder', color: `${user ? '#2196f3' : '#7ed'}`, textShadow: '2px 2px black' }}>Hello </span>{!user ? 'Stranger' : user.name}</h2>
3643
{!user ? <div className="card-title und">Welcome to <strong><a onClick={() => M.toast({ html: 'Coming soon', classes: 'toast' })}>Tushar.dev</a></strong></div> : null}

0 commit comments

Comments
 (0)