Skip to content

Commit 5ab1ae4

Browse files
committed
refactor(notification): update notification position
1 parent 6a1c31e commit 5ab1ae4

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/Ui.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,11 @@ const init = (serverUrl) => {
158158
return (
159159
<AppWrapper>
160160
<GlobalStyle />
161-
<Notifications />
162161

163162
<SocketProvider socket={socket}>
164163
<Router>
164+
<Notifications />
165+
165166
{store.isMinimized && <Redirect to="/minimized" />}
166167
<Switch>
167168
<Route exact path="/minimized">

src/components/Notifications.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import React, { FunctionComponent } from 'react';
1+
import React, { FunctionComponent, useEffect, useState } from 'react';
2+
import { useLocation } from 'react-router-dom';
23
import styled from 'styled-components';
34
import { NotificationParams } from '../shared/interfaces';
45
import Notification from './Notification';
56
// store
67
import { observer } from 'mobx-react';
78
import { useStore } from '../store';
9+
import { autorun, reaction } from 'mobx';
810

911
const Notifications: FunctionComponent = () => {
1012
const store = useStore();
13+
const location = useLocation();
14+
const [isRoot, setIsRoot] = useState(true);
15+
16+
useEffect(() => {
17+
setIsRoot(location.pathname === '/');
18+
}, [location]);
1119

1220
const deleteNotification = (id: string) =>
1321
store.notifications.splice(
@@ -18,7 +26,7 @@ const Notifications: FunctionComponent = () => {
1826
if (store.notifications.length === 0) return null;
1927

2028
return (
21-
<NotificationsContainer>
29+
<NotificationsContainer isRoot={isRoot}>
2230
{store.notifications.map((data: NotificationParams, key) => (
2331
<Notification
2432
key={key}
@@ -34,7 +42,7 @@ const NotificationsContainer = styled.div`
3442
display: flex;
3543
flex-direction: column-reverse;
3644
position: absolute;
37-
bottom: 39px;
45+
bottom: ${(props) => (props.isRoot ? 39 : 0)}px;
3846
z-index: 11;
3947
padding: 10px;
4048
width: 100%;

0 commit comments

Comments
 (0)