Skip to content

Commit

Permalink
refactor(notification): update notification position
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed May 1, 2020
1 parent 6a1c31e commit 5ab1ae4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ const init = (serverUrl) => {
return (
<AppWrapper>
<GlobalStyle />
<Notifications />

<SocketProvider socket={socket}>
<Router>
<Notifications />

{store.isMinimized && <Redirect to="/minimized" />}
<Switch>
<Route exact path="/minimized">
Expand Down
14 changes: 11 additions & 3 deletions src/components/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import React, { FunctionComponent } from 'react';
import React, { FunctionComponent, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import styled from 'styled-components';
import { NotificationParams } from '../shared/interfaces';
import Notification from './Notification';
// store
import { observer } from 'mobx-react';
import { useStore } from '../store';
import { autorun, reaction } from 'mobx';

const Notifications: FunctionComponent = () => {
const store = useStore();
const location = useLocation();
const [isRoot, setIsRoot] = useState(true);

useEffect(() => {
setIsRoot(location.pathname === '/');
}, [location]);

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

return (
<NotificationsContainer>
<NotificationsContainer isRoot={isRoot}>
{store.notifications.map((data: NotificationParams, key) => (
<Notification
key={key}
Expand All @@ -34,7 +42,7 @@ const NotificationsContainer = styled.div`
display: flex;
flex-direction: column-reverse;
position: absolute;
bottom: 39px;
bottom: ${(props) => (props.isRoot ? 39 : 0)}px;
z-index: 11;
padding: 10px;
width: 100%;
Expand Down

0 comments on commit 5ab1ae4

Please sign in to comment.