Skip to content

Commit

Permalink
feat(Notification): added notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
HoseaCodes committed Dec 10, 2021
1 parent 349d094 commit 3d270ca
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/Components/Notification/Notification.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, {useState, useEffect} from 'react';
import './Notification.css';

const Notification = (props) => {
const [exit, setExit] = useState(false);
const [width, setWidth] = useState(0);
const [intervalID, setIntervalID] = useState(null);

const handleStartTimer = () => {

const id = setInterval(() => {
setWidth((prevState) => {
if (prevState < 100) {
return prevState + 0.5;
}
clearInterval(id);
return prevState;
});
}, 10)

setIntervalID(id);

};

const handlePauseTimer = () => {
clearInterval(intervalID);
};

const handleCloseNotification = () => {
handlePauseTimer();
setExit(true);
setTimeout(() => {
props.dispatch({
type: "REMOVE_NOTIFICATION",
id: props.id
})
}, 400)
};

useEffect(() => {
if (width === 100) {
handleCloseNotification();
}
}, [width])

useEffect(() => {
handleStartTimer();
}, []);

return (
<div onMouseOver={handlePauseTimer} onMouseLeave={handleStartTimer}
className={`notification-item ${props.type === "SUCCESS" ? "success" : "error"}
${exit ? "exit" : ""}`}>
<p>{props.message}</p>
<div className={"bar"} style={{width: `${width}%`}}>

</div>
</div>
)
}

export default Notification;

0 comments on commit 3d270ca

Please sign in to comment.