source: components/Notification.jsx@ aac3b2b

main
Last change on this file since aac3b2b was 189cd8f, checked in by anastasovv <simon@…>, 2 years ago

Code cleanings

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import React from 'react'
2
3import { AiOutlineClose } from 'react-icons/ai';
4
5import { useState } from 'react';
6
7import { useDispatch, useSelector } from 'react-redux';
8import { setStyle } from '../redux/reducers/styleSlice';
9
10const Notification = () => {
11 const [timeoutIsSet, setTimeoutIsSet] = useState(false);
12
13 const styleState = useSelector(state => state.style);
14
15 const dispatch = useDispatch();
16
17 const display = styleState.style.notification.show === true ? 'flex' : 'none';
18 const bg = styleState.style.notification.status === 'success' ? 'rgba(0, 200, 255, 0.8)' : 'rgba(255, 0, 0, 0.8)';
19
20 function close() {
21 dispatch(setStyle({
22 ...styleState.style,
23 notification: {
24 ...styleState.style.notification,
25 show: false,
26 }
27 }))
28 }
29
30 if (styleState.style.notification.show === true && !timeoutIsSet) {
31 setTimeoutIsSet(true);
32 setTimeout(() => {
33 close();
34 setTimeoutIsSet(false);
35 }, 3000);
36 }
37
38 return (
39 <div className="notification" style={{display: display, backgroundColor: bg}}>
40 <AiOutlineClose onClick={() => close()}/>
41 <div>
42 {styleState.style.notification.text}
43 </div>
44 </div>
45 )
46}
47
48export default Notification
Note: See TracBrowser for help on using the repository browser.