Skip to content

Commit

Permalink
fix(socket): save settings correctly and add socket hoc to colorpicker
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Apr 25, 2020
1 parent d0f4597 commit 5d2be34
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/assets/css/ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ body {

::-webkit-scrollbar-track {
background-color: transparent;
padding-bottom: 20px;
margin-bottom: 15px;
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/Chatbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ColorPicker from './ColorPicker';
import { ConnectionEnum } from '../shared/interfaces';

interface ChatProps {
socket: SocketIOClient.Socket;
sendMessage: (event: any) => void;
setTextMessage: (text: string) => void;
textMessage: string;
Expand Down Expand Up @@ -97,7 +96,7 @@ const ChatBar: FunctionComponent<ChatProps> = (props) => {
props.selectionIsChecked ? '(optional)' : ''
}`}
/>
<ColorPicker socket={props.socket} />
<ColorPicker />
</ChatInput>
<SelectionCheckbox
checked={props.selectionIsChecked}
Expand Down
3 changes: 2 additions & 1 deletion src/components/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components';

import { state, view } from '../shared/state';
import { colors } from '../shared/constants';
import { withSocketContext } from '../shared/SocketProvider';

interface Props {
socket?: SocketIOClient.Socket;
Expand Down Expand Up @@ -120,4 +121,4 @@ const Picker = styled.div`
}
`;

export default ColorPicker;
export default withSocketContext(ColorPicker);
9 changes: 3 additions & 6 deletions src/shared/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,14 @@ const state = store({
}
},
persistSettings(settings, socket, init) {
// save user settings in main
sendMainMessage(
'save-user-settings',
Object.assign({}, state.settings, settings)
);

state.settings = {
...state.settings,
...settings,
};

// save user settings in main
sendMainMessage('save-user-settings', Object.assign({}, state.settings));

if (settings.url && settings.url !== state.url) {
// set server URL
sendMainMessage('set-server-url', settings.url);
Expand Down
74 changes: 41 additions & 33 deletions src/views/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,33 +175,36 @@ const ChatView: FunctionComponent<ChatProps> = (props) => {
more
</MoreButton>
)}

<Messages
onAnimationEnd={() => setContainerIsHidden(!containerIsHidden)}
animationEnabled={animationEnabled}
<MessagesContainer
isSettings={isSettings}
ref={state.messagesRef}
onWheel={() => {
const { current } = state.messagesRef;

state.disableAutoScroll =
current.scrollHeight -
(current.scrollTop + current.clientHeight) >
0;
}}
animationEnabled={animationEnabled}
>
{chatState.filteredMessages.map((m, i) => (
<Fragment key={i}>
<Message data={m} instanceId={state.instanceId} />
{(i + 1) % MAX_MESSAGES === 0 &&
i + 1 !== chatState.filteredMessages.length ? (
<MessageSeperator />
) : (
''
)}
</Fragment>
))}

<Messages
onAnimationEnd={() => setContainerIsHidden(!containerIsHidden)}
animationEnabled={animationEnabled}
isSettings={isSettings}
ref={state.messagesRef}
onWheel={() => {
const { current } = state.messagesRef;

state.disableAutoScroll =
current.scrollHeight -
(current.scrollTop + current.clientHeight) >
0;
}}
>
{chatState.filteredMessages.map((m, i) => (
<Fragment key={i}>
<Message data={m} instanceId={state.instanceId} />
{(i + 1) % MAX_MESSAGES === 0 &&
i + 1 !== chatState.filteredMessages.length ? (
<MessageSeperator />
) : (
''
)}
</Fragment>
))}
</Messages>
<SettingsArrow
isSettings={isSettings}
onClick={() => {
Expand Down Expand Up @@ -231,15 +234,14 @@ const ChatView: FunctionComponent<ChatProps> = (props) => {
</svg>
)}
</SettingsArrow>
</Messages>
</MessagesContainer>

{(isSettings || (!isSettings && !containerIsHidden)) && (
<SettingsView init={props.init} />
)}

<Chatbar
init={props.init}
socket={props.socket}
sendMessage={sendMessage}
setTextMessage={(text) => (chatState.textMessage = text)}
textMessage={chatState.textMessage}
Expand Down Expand Up @@ -283,8 +285,7 @@ const FloatingButtonRight = styled.div`
`;

const SettingsArrow = styled.div`
position: sticky;
left: 0;
position: absolute;
bottom: 0;
padding-top: 10px;
padding-bottom: 10px;
Expand Down Expand Up @@ -315,7 +316,7 @@ const MessageSeperator = styled.div`
border-width: 1px 0 0 0;
border-color: #ececec;
border-style: dotted;
margin: -5px 0 10px;
margin: 5px 0 10px;
`;

const Chat = styled.div`
Expand All @@ -324,12 +325,12 @@ const Chat = styled.div`
background-color: ${({ color }) => color};
`;

const Messages = styled.div`
const MessagesContainer = styled.div`
/* display: grid;
grid-template-rows: auto 26px; */
position: relative;
z-index: 2;
margin: 0;
overflow: ${({ isSettings }) => (isSettings ? 'hidden' : 'auto')};
padding: 55px 10px 0;
background-color: #fff;
border-radius: 0 0 15px 15px;
transition: transform 0.4s;
Expand All @@ -341,6 +342,13 @@ const Messages = styled.div`
animationEnabled ? 0.2 : 0}s;
`;

const Messages = styled.div`
padding: 55px 10px 0;
overflow: ${({ isSettings }) => (isSettings ? 'hidden' : 'auto')};
align-self: end;
height: 100%;
`;

const Online = styled.div`
position: relative;
padding: 8px 0 8px 24px;
Expand Down
2 changes: 1 addition & 1 deletion src/views/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const SettingsView: FunctionComponent<SettingsProps> = (props) => {
settings.url = state.settings.url;
settings.enableNotificationTooltip =
state.settings.enableNotificationTooltip;
}, [settings]);
}, [state.settings]);

return (
<>
Expand Down

0 comments on commit 5d2be34

Please sign in to comment.