Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a timer for better user exp #26

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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