Skip to content

Commit 0f3215f

Browse files
committed
Added Preloaders ⭕
1 parent 8bccf5a commit 0f3215f

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

components/AfterLogin.jsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import React,{useState} from 'react';
1+
import React, { useState } from 'react';
22
import { useUser } from '../lib/hooks';
33

44
export default function afterLogin() {
55
const [errorMsg, setErrorMsg] = useState("");
6-
const [user]=useUser();
6+
const [user] = useUser();
7+
const [Loader,updateLoad]=useState(false);
78
const handleSubmit = async (e) => {
89
e.preventDefault();
10+
updateLoad(true);
911
const body = {
1012
message: e.currentTarget.message.value,
1113
name: user.name
@@ -16,16 +18,17 @@ export default function afterLogin() {
1618
body: JSON.stringify(body)
1719
});
1820
if (res.status === 201) {
19-
M.toast({html: 'Message sent',classes:'green'})
21+
M.toast({ html: 'Message sent', classes: 'green' })
2022
} else {
2123
setErrorMsg(await res.text());
2224
}
25+
updateLoad(false);
2326
};
2427
return (<div className="row">
2528
<div className="col s12 m12">
2629
<div className="card-panel horizontal blue ">
27-
<span className="white-text">Hey you made it here {user?user.name:'Stranger'}, we all were waiting for you.<br/>I hope you like this Authentication module, Its simple yet important to know.
28-
I'll be updating it with many new stuff frequently.<br/><br/>Till then you can look around.<strong> Don't forget to drop a message for me.</strong></span>
30+
<span className="white-text">Hey you made it here {user ? user.name : 'Stranger'}, we all were waiting for you.<br />I hope you like this Authentication module, Its simple yet important to know.
31+
I'll be updating it with many new stuff frequently.<br /><br />Till then you can look around.<strong> Don't forget to drop a message for me.</strong></span>
2932
</div>
3033
</div>
3134
{errorMsg ? (
@@ -38,7 +41,19 @@ export default function afterLogin() {
3841
<label htmlFor="message">Message for developer</label>
3942
</div>
4043
<button className="btn-small waves-effect waves-light blue" type="submit" style={{ marginTop: '1.7rem' }}>Send
41-
<i className="material-icons right">send</i>
44+
{!Loader?<i className="material-icons right">send</i>:
45+
<div class="preloader-wrapper small active">
46+
<div class="spinner-layer spinner-green-only">
47+
<div class="circle-clipper left">
48+
<div class="circle"></div>
49+
</div><div class="gap-patch">
50+
<div class="circle"></div>
51+
</div><div class="circle-clipper right">
52+
<div class="circle"></div>
53+
</div>
54+
</div>
55+
</div>
56+
}
4257
</button>
4358
</form>
4459
</div>)

pages/api/message.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ handler.post(async (req, res) => {
1010
const { message,name } = req.body;
1111
const msg = await req.db
1212
.collection('messages')
13-
.insertOne({ name,message })
13+
.insertOne({ name,message,message_date:new Date()})
1414
.then(({ ops }) => ops[0]);
1515
res.status(201).end();
1616
});

style.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,13 @@ a{
4848
top:4.7rem !important;
4949
border-radius: 10px !important;
5050
height: 20rem !important;
51+
}
52+
.preloader-wrapper.small{
53+
width: 20px;
54+
height: 20px;
55+
margin-left: 10px;
56+
margin-bottom: -3px;
57+
.spinner-green, .spinner-green-only{
58+
border-color: #fff;
59+
}
5160
}

0 commit comments

Comments
 (0)