main
Last change
on this file since faff334 was 189cd8f, checked in by anastasovv <simon@…>, 2 years ago |
Code cleanings
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Rev | Line | |
---|
[87614a5] | 1 | import React from 'react'
|
---|
| 2 |
|
---|
| 3 | import { AiOutlineClose } from 'react-icons/ai';
|
---|
| 4 |
|
---|
[189cd8f] | 5 | import { useState } from 'react';
|
---|
| 6 |
|
---|
[87614a5] | 7 | import { useDispatch, useSelector } from 'react-redux';
|
---|
| 8 | import { setStyle } from '../redux/reducers/styleSlice';
|
---|
| 9 |
|
---|
| 10 | const Notification = () => {
|
---|
[189cd8f] | 11 | const [timeoutIsSet, setTimeoutIsSet] = useState(false);
|
---|
| 12 |
|
---|
[87614a5] | 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 |
|
---|
[189cd8f] | 30 | if (styleState.style.notification.show === true && !timeoutIsSet) {
|
---|
| 31 | setTimeoutIsSet(true);
|
---|
[b13f93b] | 32 | setTimeout(() => {
|
---|
| 33 | close();
|
---|
[189cd8f] | 34 | setTimeoutIsSet(false);
|
---|
[b13f93b] | 35 | }, 3000);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
[87614a5] | 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 |
|
---|
| 48 | export default Notification |
---|
Note:
See
TracBrowser
for help on using the repository browser.