Skip to content

Commit

Permalink
Merge pull request #26 from GlideRide-online/patch-01
Browse files Browse the repository at this point in the history
added a timer for better user exp
  • Loading branch information
Akshat2Jain authored Jan 21, 2024
2 parents 45b025f + 7c12c0c commit 0c6c34f
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
36 changes: 36 additions & 0 deletions client/src/componetnts/Notification.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Notification.js

import React, { useState, useEffect } from "react";

const Notification = ({ message, duration, onClose }) => {
const [isVisible, setIsVisible] = useState(true);
const [timer, setTimer] = useState(duration);

useEffect(() => {
const interval = setInterval(() => {
setTimer((prevTimer) => {
if (prevTimer === 1) {
clearInterval(interval);
setIsVisible(false);
onClose();
}
return prevTimer - 1;
});
}, 1000);

return () => clearInterval(interval);
}, [duration, onClose]);

return (
<>
{isVisible && (
<div className="fixed font-roboto bottom-0 right-0 mb-4 mr-4 p-4 bg-black text-white rounded-md shadow-md">
<p>{message}</p>
<p className="mt-2 text-sm">{`${timer} seconds`}</p>
</div>
)}
</>
);
};

export default Notification;
27 changes: 25 additions & 2 deletions client/src/pages/Booking.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ import React, { useState, useEffect } from "react";
import Loading from "../componetnts/Loading";
import bgimg2 from "../assests/2.jpg";
import NoRideAvailable from "./NoRIdeAvailable";
import { message } from "antd";
// import { message } from "antd";
import Notification from "../componetnts/Notification";
const Booking = ({ showUi }) => {
const [isLoading, setIsLoading] = useState(true);
const [isHovered, setIsHovered] = useState(false);
const [imageLoaded, setImageLoaded] = useState(false);
const [notification, setNotification] = useState({
message: "",
duration: 10,
isVisible: false,
});
const containerStyle = {
backgroundColor: "#0A192F", // Background color
};
Expand Down Expand Up @@ -43,9 +49,19 @@ const Booking = ({ showUi }) => {
}, 2000); // Adjust the delay as needed
return () => clearTimeout(loadingTimeout);
}, []);
// Notification
const showNotification = (message, duration = 10) => {
setNotification({ message, duration, isVisible: true });

const timer = setTimeout(() => {
setNotification({ ...notification, isVisible: false });
}, duration * 1000);

return () => clearTimeout(timer);
};
// google login invoke
const googleLogin = async () => {
message.success("Please Wait! This may take few seconds");
showNotification("Please Wait! This may take a few seconds");
window.open(`${process.env.REACT_APP_SECRETROUTE}/auth/google`, "_self");
};

Expand Down Expand Up @@ -100,6 +116,13 @@ const Booking = ({ showUi }) => {
)}
</>
)}
{notification.isVisible && (
<Notification
message={notification.message}
duration={notification.duration}
onClose={() => setNotification({ ...notification, isVisible: false })}
/>
)}
</>
);
};
Expand Down

0 comments on commit 0c6c34f

Please sign in to comment.