Skip to content

Commit

Permalink
refactor: update animations
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Apr 24, 2020
1 parent 5442c42 commit 977b877
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
16 changes: 14 additions & 2 deletions src/Ui.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import * as ReactDOM from 'react-dom';
import styled, { createGlobalStyle } from 'styled-components';
import {
MemoryRouter as Router,
Redirect,
Expand Down Expand Up @@ -39,6 +40,16 @@ onmessage = (message) => {
}
};

const GlobalStyle = createGlobalStyle`
body {
overflow: hidden;
}
`;

const AppWrapper = styled.div`
overflow: hidden;
`;

const init = (serverUrl) => {
state.url = serverUrl;

Expand Down Expand Up @@ -99,7 +110,8 @@ const init = (serverUrl) => {

const App = view(() => {
return (
<>
<AppWrapper>
<GlobalStyle />
<Notifications />

<SocketProvider socket={socket}>
Expand All @@ -124,7 +136,7 @@ const init = (serverUrl) => {
</Switch>
</Router>
</SocketProvider>
</>
</AppWrapper>
);
});

Expand Down
14 changes: 11 additions & 3 deletions src/components/Chatbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FunctionComponent, useState, useEffect, useRef } from 'react';
import { useRouteMatch } from 'react-router-dom';
import styled from 'styled-components';
import { state } from '../shared/state';
import { sendMainMessage } from '../shared/utils';
Expand All @@ -13,6 +14,7 @@ interface ChatProps {
}

const ChatBar: FunctionComponent<ChatProps> = (props) => {
const isSettings = useRouteMatch('/settings');
const selection = state.selection.length;
const hasSelection = Boolean(selection);
const [show, setShow] = useState(hasSelection);
Expand All @@ -32,6 +34,7 @@ const ChatBar: FunctionComponent<ChatProps> = (props) => {

return (
<ChatBarForm
isSettings={isSettings}
onSubmit={(e) => {
props.sendMessage(e);
chatTextInput.current.value = '';
Expand Down Expand Up @@ -104,8 +107,13 @@ const ChatBar: FunctionComponent<ChatProps> = (props) => {
};

const ChatBarForm = styled.form`
position: relative;
position: absolute;
right: 14px;
left: 14px;
bottom: 7px;
margin: 0;
transition: transform 0.3s;
transform: translateY(${({ isSettings }) => (isSettings ? 50 : 0)}px);
`;

const SelectionCheckbox = styled.div`
Expand All @@ -124,7 +132,7 @@ const BellIcon = styled.div`
cursor: pointer;
position: absolute;
z-index: 3;
left: 22px;
left: 10px;
top: 15px;
svg {
width: 15px;
Expand Down Expand Up @@ -186,7 +194,7 @@ const ChatInput = styled.div`
width: 100%;
border: 0;
padding: 10px 14px 10px 30px;
margin: 7px 14px 0;
margin: 7px 0 0;
height: 30px;
outline: none;
transition: width 0.4s;
Expand Down
33 changes: 17 additions & 16 deletions src/views/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { FunctionComponent, useEffect, Fragment } from 'react';
import { store } from 'react-easy-state';
import { Redirect, useHistory } from 'react-router-dom';
import { Route, useRouteMatch } from 'react-router-dom';
import { Redirect, useHistory, Route, useRouteMatch } from 'react-router-dom';
import styled from 'styled-components';
// components
import SettingsView from '../views/Settings';
Expand Down Expand Up @@ -224,19 +223,18 @@ const ChatView: FunctionComponent<ChatProps> = (props) => {
</SettingsArrow>
</Messages>
<Route path="/settings">
<SettingsView></SettingsView>
<SettingsView init={props.retry} />
</Route>
{!isSettings && (
<Chatbar
sendMessage={sendMessage}
setTextMessage={(text) => (chatState.textMessage = text)}
textMessage={chatState.textMessage}
setSelectionIsChecked={(isChecked) =>
(chatState.selectionIsChecked = isChecked)
}
selectionIsChecked={chatState.selectionIsChecked}
/>
)}

<Chatbar
sendMessage={sendMessage}
setTextMessage={(text) => (chatState.textMessage = text)}
textMessage={chatState.textMessage}
setSelectionIsChecked={(isChecked) =>
(chatState.selectionIsChecked = isChecked)
}
selectionIsChecked={chatState.selectionIsChecked}
/>
</Chat>
</>
);
Expand All @@ -258,6 +256,7 @@ const SettingsArrow = styled.div`
position: sticky;
left: 0;
bottom: 0;
padding-top: 5px;
padding-bottom: 17px;
cursor: pointer;
transition: rotate 0.3s;
Expand Down Expand Up @@ -296,13 +295,15 @@ const Chat = styled.div`

const Messages = styled.div`
position: relative;
z-index: 2;
margin: 0;
overflow: ${({ isSettings }) => (isSettings ? 'hidden' : 'auto')};
padding: 15px 15px 0;
background-color: #fff;
border-radius: 0 0 15px 15px;
transition: height 0.4s;
height: ${({ isSettings }) => (isSettings ? 50 : 371)}px;
transition: transform 0.4s;
height: 371px;
transform: translateY(${({ isSettings }) => (isSettings ? -318 : 0)}px);
`;

const Online = styled.div`
Expand Down
4 changes: 4 additions & 0 deletions src/views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ const Checkboxes = styled.div`
`;

const Settings = styled.div`
position: relative;
z-index: 1;
transform: translateY(-318px);
padding: 20px;
color: #fff;
Expand All @@ -226,6 +229,7 @@ const Settings = styled.div`
background-color: transparent;
color: #fff;
padding: 5px 4px;
outline: none;
}
.fields {
margin-bottom: 20px;
Expand Down

0 comments on commit 977b877

Please sign in to comment.