1
- import React , { FunctionComponent } from 'react' ;
1
+ import React , { FunctionComponent , useEffect , useState } from 'react' ;
2
+ import { useLocation } from 'react-router-dom' ;
2
3
import styled from 'styled-components' ;
3
4
import { NotificationParams } from '../shared/interfaces' ;
4
5
import Notification from './Notification' ;
5
6
// store
6
7
import { observer } from 'mobx-react' ;
7
8
import { useStore } from '../store' ;
9
+ import { autorun , reaction } from 'mobx' ;
8
10
9
11
const Notifications : FunctionComponent = ( ) => {
10
12
const store = useStore ( ) ;
13
+ const location = useLocation ( ) ;
14
+ const [ isRoot , setIsRoot ] = useState ( true ) ;
15
+
16
+ useEffect ( ( ) => {
17
+ setIsRoot ( location . pathname === '/' ) ;
18
+ } , [ location ] ) ;
11
19
12
20
const deleteNotification = ( id : string ) =>
13
21
store . notifications . splice (
@@ -18,7 +26,7 @@ const Notifications: FunctionComponent = () => {
18
26
if ( store . notifications . length === 0 ) return null ;
19
27
20
28
return (
21
- < NotificationsContainer >
29
+ < NotificationsContainer isRoot = { isRoot } >
22
30
{ store . notifications . map ( ( data : NotificationParams , key ) => (
23
31
< Notification
24
32
key = { key }
@@ -34,7 +42,7 @@ const NotificationsContainer = styled.div`
34
42
display: flex;
35
43
flex-direction: column-reverse;
36
44
position: absolute;
37
- bottom: 39px ;
45
+ bottom: ${ ( props ) => ( props . isRoot ? 39 : 0 ) } px ;
38
46
z-index: 11;
39
47
padding: 10px;
40
48
width: 100%;
0 commit comments