Skip to content

Commit

Permalink
Rename props for open/close/show/hide states
Browse files Browse the repository at this point in the history
  • Loading branch information
dliuproduction committed Nov 21, 2018
1 parent a5c6d9c commit 418e14d
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 49 deletions.
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Widget, toggleWidget, openWidget, closeWidget, showWidget, hideWidget, isOpen, isVisible } from './index_for_react_app';
import { Widget, toggleChat, openChat, closeChat, showChat, hideChat, isOpen, isVisible } from './index_for_react_app';

const plugin = {
init: (args) => {
Expand Down Expand Up @@ -29,11 +29,11 @@ const plugin = {
export {
plugin as default,
Widget,
toggleWidget as toggle,
openWidget as open,
closeWidget as close,
showWidget as show,
hideWidget as hide,
toggleChat as toggle,
openChat as open,
closeChat as close,
showChat as show,
hideChat as hide,
isOpen,
isVisible
};
Expand Down
20 changes: 10 additions & 10 deletions index_for_react_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {
renderCustomComponent,
isOpen,
isVisible,
showWidget,
hideWidget,
toggleWidget,
openWidget,
closeWidget,
openChat,
closeChat,
toggleChat,
showChat,
hideChat,
toggleInputDisabled,
dropMessages
} from './src/store/actions/dispatcher';
Expand All @@ -29,11 +29,11 @@ export {
renderCustomComponent,
isOpen,
isVisible,
showWidget,
hideWidget,
toggleWidget,
openWidget,
closeWidget,
openChat,
closeChat,
toggleChat,
showChat,
hideChat,
toggleInputDisabled,
dropMessages
};
12 changes: 5 additions & 7 deletions src/components/Widget/components/Launcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ import openLauncher from 'assets/launcher_button.svg';
import close from 'assets/clear-button.svg';
import './style.scss';

const Launcher = ({ toggle, chatOpened, badge }) =>
<button type="button" className={chatOpened ? 'launcher hide-sm' : 'launcher'} onClick={toggle}>
const Launcher = ({ toggle, isChatOpen, badge }) =>
<button type="button" className={isChatOpen ? 'launcher hide-sm' : 'launcher'} onClick={toggle}>
<Badge badge ={badge} />
{
chatOpened ?
isChatOpen ?
<img src={close} className="close-launcher" alt="" /> :
<img src={openLauncher} className="open-launcher" alt="" />
}
</button>;

Launcher.propTypes = {
toggle: PropTypes.func,
chatOpened: PropTypes.bool,
isChatOpen: PropTypes.bool,
badge: PropTypes.number
};

export default connect(store => ({
chatOpened: store.behavior.get('showChat')
}))(Launcher);
export default Launcher;
4 changes: 2 additions & 2 deletions src/store/actions/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export const CONNECT = 'CONNECT';
export const DISCONNECT = 'DISCONNECT';
export const GET_OPEN_STATE = 'GET_OPEN_STATE';
export const GET_VISIBLE_STATE = 'GET_VISIBLE_STATE';
export const SHOW_WIDGET = 'SHOW_WIDGET';
export const HIDE_WIDGET = 'HIDE_WIDGET';
export const SHOW_CHAT = 'SHOW_CHAT';
export const HIDE_CHAT = 'HIDE_CHAT';
export const TOGGLE_CHAT = 'TOGGLE_CHAT';
export const OPEN_CHAT = 'OPEN_CHAT';
export const CLOSE_CHAT = 'CLOSE_CHAT';
Expand Down
18 changes: 9 additions & 9 deletions src/store/actions/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ export function renderCustomComponent(component, props, showAvatar = false) {
store.dispatch(actions.renderCustomComponent(component, props, showAvatar));
}

export function showWidget() {
store.dispatch(actions.showWidget());
export function openChat() {
store.dispatch(actions.openChat());
}

export function hideWidget() {
store.dispatch(actions.hideWidget());
export function closeChat() {
store.dispatch(actions.closeChat());
}

export function toggleWidget() {
export function toggleChat() {
store.dispatch(actions.toggleChat());
}

export function openWidget() {
store.dispatch(actions.openChat());
export function showChat() {
store.dispatch(actions.showChat());
}

export function closeWidget() {
store.dispatch(actions.closeChat());
export function hideChat() {
store.dispatch(actions.hideChat());
}

export function toggleInputDisabled() {
Expand Down
8 changes: 4 additions & 4 deletions src/store/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ export function getVisibleState() {
};
}

export function showWidget() {
export function showChat() {
return {
type: actions.SHOW_WIDGET
type: actions.SHOW_CHAT
};
}

export function hideWidget() {
export function hideChat() {
return {
type: actions.HIDE_WIDGET
type: actions.HIDE_CHAT
};
}

Expand Down
18 changes: 9 additions & 9 deletions src/store/reducers/behaviorReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export default function (inputFieldTextHint, connectingText, storage) {
const initialState = Map({
connected: false,
initialized: false,
showWidget: true,
showChat: false,
isChatVisible: true,
isChatOpen: false,
disabledInput: true,
inputFieldTextHint,
connectingText
Expand All @@ -18,20 +18,20 @@ export default function (inputFieldTextHint, connectingText, storage) {
const storeParams = storeParamsTo(storage);
switch (action.type) {
// Each change to the redux store's behavior Map gets recorded to storage
case actionTypes.SHOW_WIDGET: {
return storeParams(state.update('showWidget', showWidget => true));
case actionTypes.SHOW_CHAT: {
return storeParams(state.update('isChatVisible', isChatVisible => true));
}
case actionTypes.HIDE_WIDGET: {
return storeParams(state.update('showWidget', showWidget => false));
case actionTypes.HIDE_CHAT: {
return storeParams(state.update('isChatVisible', isChatVisible => false));
}
case actionTypes.TOGGLE_CHAT: {
return storeParams(state.update('showChat', showChat => !showChat));
return storeParams(state.update('isChatOpen', isChatOpen => !isChatOpen));
}
case actionTypes.OPEN_CHAT: {
return storeParams(state.update('showChat', showChat => true));
return storeParams(state.update('isChatOpen', isChatOpen => true));
}
case actionTypes.CLOSE_CHAT: {
return storeParams(state.update('showChat', showChat => false));
return storeParams(state.update('isChatOpen', isChatOpen => false));
}
case actionTypes.TOGGLE_INPUT_DISABLED: {
return storeParams(state.update('disabledInput', disabledInput => !disabledInput));
Expand Down
4 changes: 2 additions & 2 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function initStore(hintText, connectingText, socket, storage) {
socket.emit("user_uttered", { message: action.text, customData: socket.customData, session_id });
}
case actionTypes.GET_OPEN_STATE: {
return store.getState().behavior.get("showChat");
return store.getState().behavior.get("isChatOpen");
}
case actionTypes.GET_VISIBLE_STATE: {
return store.getState().behavior.get("showWidget");
return store.getState().behavior.get("isChatVisible");
}
}

Expand Down

0 comments on commit 418e14d

Please sign in to comment.